feat: release v1.0.0
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useMemo, useState } from 'react'
|
||||
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { getCoreRowModel, useReactTable } from '@tanstack/react-table'
|
||||
|
||||
import { getCategories } from '@/api'
|
||||
import { hasPermission } from '@/lib'
|
||||
import { type Category } from '@/schemas'
|
||||
|
||||
import { ActionDialogs } from './components/action-dialogs.tsx'
|
||||
@@ -17,9 +18,8 @@ export default function CrudPage() {
|
||||
pageIndex: 0,
|
||||
pageSize: 10,
|
||||
})
|
||||
const [rowCount, setRowCount] = useState<number>()
|
||||
|
||||
const { data, isFetching } = useQuery({
|
||||
const { data, isFetching, refetch } = useQuery({
|
||||
queryKey: [QUERY_KEY, pagination.pageIndex, pagination.pageSize],
|
||||
queryFn: () =>
|
||||
getCategories({
|
||||
@@ -27,28 +27,24 @@ export default function CrudPage() {
|
||||
page_size: pagination.pageSize,
|
||||
}),
|
||||
placeholderData: (prev) => prev,
|
||||
enabled: hasPermission('category:list'),
|
||||
})
|
||||
|
||||
const tableData = useMemo<Category[]>(() => data?.list ?? [], [data])
|
||||
|
||||
const columns = useMemo(() => createColumns(), [])
|
||||
|
||||
useEffect(() => {
|
||||
if (!isFetching && data?.total !== undefined) {
|
||||
setRowCount(data.total)
|
||||
}
|
||||
}, [isFetching, data?.total])
|
||||
|
||||
const table = useReactTable<Category>({
|
||||
data: tableData,
|
||||
columns,
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
manualPagination: true,
|
||||
rowCount: rowCount,
|
||||
rowCount: data?.total,
|
||||
state: { pagination },
|
||||
onPaginationChange: setPagination,
|
||||
meta: {
|
||||
showLoading: isFetching,
|
||||
isFetching,
|
||||
refetch,
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user