From 812e4ac0afc56ee3121a5673af35bf8be2f4432c Mon Sep 17 00:00:00 2001 From: Rafi Zadanly Date: Fri, 24 Nov 2023 14:43:48 +0700 Subject: Update --- src/modules/result/components/Table.tsx | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'src/modules/result/components') diff --git a/src/modules/result/components/Table.tsx b/src/modules/result/components/Table.tsx index a184ad7..a6a9f30 100644 --- a/src/modules/result/components/Table.tsx +++ b/src/modules/result/components/Table.tsx @@ -2,7 +2,7 @@ import { useResultStore } from "@/common/stores/useResultStore"; import { StockOpnameRes } from "@/common/types/stockOpname"; import { Button, Pagination, Skeleton, Spacer, Spinner } from "@nextui-org/react" -import { useQuery } from "@tanstack/react-query"; +import { keepPreviousData, useQuery } from "@tanstack/react-query"; import styles from "./table.module.css" import clsxm from "@/common/libs/clsxm"; import DetailRow from "./DetailRow"; @@ -39,6 +39,7 @@ const Table = () => { return await fetch(`/api/stock-opname?${searchParams}`) .then(res => res.json()) }, + placeholderData: keepPreviousData }) const { filter } = useResultStore() @@ -62,6 +63,21 @@ const Table = () => { setExportLoad(false) } + let debounceTimeout: NodeJS.Timeout | null = null; + + const paginationOnChange = (page: number) => { + updateFilter('page', page) + + if (debounceTimeout) clearTimeout(debounceTimeout) + + debounceTimeout = setTimeout(() => { + window.scrollTo({ top: 0, 'behavior': 'smooth' }); + debounceTimeout = null + }, 1000); + } + + const isLoading = stockOpnames.isLoading || stockOpnames.isRefetching + return ( <>
@@ -83,7 +99,7 @@ const Table = () => { GUDANG SELISIH - {stockOpnames.data?.result.map((stockOpname: StockOpnameRes['result']) => ( + {!isLoading && stockOpnames.data?.result.map((stockOpname: StockOpnameRes['result']) => ( <> { ))} - {stockOpnames.data?.result.length === 0 && ( + {!isLoading && stockOpnames.data?.result.length === 0 && ( Belum ada data untuk ditampilkan )} - {stockOpnames.isLoading && ( + {isLoading && ( -
- {Array.from({ length: 6 }, (_, i) => ( - +
+ {Array.from({ length: 10 }, (_, i) => ( + ))}
@@ -152,7 +168,7 @@ const Table = () => { isCompact page={stockOpnames.data?.page || 1} total={stockOpnames.data?.totalPage || 1} - onChange={(page) => updateFilter('page', page)} + onChange={paginationOnChange} />
-- cgit v1.2.3