index.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use client'
  2. import List from './list'
  3. import React, { useEffect, useState } from 'react'
  4. import useSWR from 'swr'
  5. import { fetchLog } from '@/service/common'
  6. const LogIndex = () => {
  7. const [page, setPage] = React.useState<number>(0)
  8. const [limit, setLimit] = useState<number>(10)
  9. const { data, mutate }: any = useSWR(
  10. {
  11. url: '/intentions/train_tasks',
  12. params: {
  13. page: page + 1,
  14. limit,
  15. },
  16. },
  17. fetchLog,
  18. )
  19. const list: any = data?.data || []
  20. const total = data?.total || 0
  21. useEffect(() => {
  22. mutate()
  23. }, [page, limit])
  24. return (
  25. <>
  26. <div className='flex h-full w-full flex-col bg-background-default-subtle p-6'>
  27. <div className="flex-1">
  28. <List
  29. list={list || []}
  30. onUpdate={mutate}
  31. pagination={{
  32. total,
  33. limit,
  34. onLimitChange: setLimit,
  35. current: page,
  36. onChange: setPage,
  37. }}
  38. />
  39. </div>
  40. </div>
  41. </>
  42. )
  43. }
  44. export default LogIndex