mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-23 15:08:12 +02:00
feat: implement infinite grid loading with server-side pagination and client-side integration
This commit is contained in:
1 parent
49928e9c08
commit
b39e010903
3 files changed
+8
-2
No files matched your search
@@ -22,10 +22,12 @@ export async function GET(request: NextRequest) {
|
|||||||
const search = searchParams.get("search") ?? undefined;
|
const search = searchParams.get("search") ?? undefined;
|
||||||
const gamme = searchParams.get("gamme") ?? undefined;
|
const gamme = searchParams.get("gamme") ?? undefined;
|
||||||
const code3 = searchParams.get("code3") ?? undefined;
|
const code3 = searchParams.get("code3") ?? undefined;
|
||||||
|
const magasin = searchParams.get("magasin") ?? undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await getProductRows({
|
const result = await getProductRows({
|
||||||
codeFournisseur,
|
codeFournisseur,
|
||||||
|
magasin,
|
||||||
page: isNaN(page) ? 0 : page,
|
page: isNaN(page) ? 0 : page,
|
||||||
pageSize: isNaN(pageSize) ? 200 : pageSize,
|
pageSize: isNaN(pageSize) ? 200 : pageSize,
|
||||||
offset: offset !== undefined && !isNaN(offset) ? offset : undefined,
|
offset: offset !== undefined && !isNaN(offset) ? offset : undefined,
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ export function GridClient({ initialRows, initialTotal, codeFournisseur, nomFour
|
|||||||
|
|
||||||
const { total, isLoadingMore, hasMore, loadNextPage, stopLoading, progress } = useInfiniteGrid({
|
const { total, isLoadingMore, hasMore, loadNextPage, stopLoading, progress } = useInfiniteGrid({
|
||||||
codeFournisseur,
|
codeFournisseur,
|
||||||
|
magasin: magasin || "TOTAL",
|
||||||
initialTotal,
|
initialTotal,
|
||||||
pageSize: 10000,
|
pageSize: 10000,
|
||||||
onPageLoaded: handlePageLoaded
|
onPageLoaded: handlePageLoaded
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export interface InfiniteGridOptions {
|
|||||||
codeFournisseur: string | null;
|
codeFournisseur: string | null;
|
||||||
initialTotal: number;
|
initialTotal: number;
|
||||||
pageSize?: number;
|
pageSize?: number;
|
||||||
|
magasin?: string;
|
||||||
search?: string;
|
search?: string;
|
||||||
gamme?: string | null;
|
gamme?: string | null;
|
||||||
code3?: string | null;
|
code3?: string | null;
|
||||||
@@ -28,6 +29,7 @@ export function useInfiniteGrid({
|
|||||||
codeFournisseur,
|
codeFournisseur,
|
||||||
initialTotal,
|
initialTotal,
|
||||||
pageSize = 10000,
|
pageSize = 10000,
|
||||||
|
magasin,
|
||||||
search,
|
search,
|
||||||
gamme,
|
gamme,
|
||||||
code3,
|
code3,
|
||||||
@@ -58,9 +60,10 @@ export function useInfiniteGrid({
|
|||||||
if (search) params.set("search", search);
|
if (search) params.set("search", search);
|
||||||
if (gamme) params.set("gamme", gamme);
|
if (gamme) params.set("gamme", gamme);
|
||||||
if (code3) params.set("code3", code3);
|
if (code3) params.set("code3", code3);
|
||||||
|
if (magasin) params.set("magasin", magasin);
|
||||||
return `/api/grid/rows?${params.toString()}`;
|
return `/api/grid/rows?${params.toString()}`;
|
||||||
},
|
},
|
||||||
[codeFournisseur, pageSize, search, gamme, code3]
|
[codeFournisseur, pageSize, search, gamme, code3, magasin]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -70,7 +73,7 @@ export function useInfiniteGrid({
|
|||||||
setIsStopped(false);
|
setIsStopped(false);
|
||||||
loadedPagesRef.current = new Set([0]);
|
loadedPagesRef.current = new Set([0]);
|
||||||
fetchIdRef.current += 1;
|
fetchIdRef.current += 1;
|
||||||
}, [codeFournisseur, initialTotal, search, gamme, code3]);
|
}, [codeFournisseur, initialTotal, search, gamme, code3, magasin]);
|
||||||
|
|
||||||
const loadNextPage = useCallback(async () => {
|
const loadNextPage = useCallback(async () => {
|
||||||
if (!codeFournisseur || isLoadingMore || isStopped) return;
|
if (!codeFournisseur || isLoadingMore || isStopped) return;
|
||||||
|
|||||||
Reference in new issue
Block a user