feat: implement grid state management, data fetching, and infinite scroll infrastructure

This commit is contained in:
Michael committed 2026-04-02 17:22:41 +02:00
1 parent 2893114fca
commit 88a3121c92
4 files changed
+61 -37

No files matched your search

+13
View File
@@ -27,6 +27,7 @@ interface GridState {
// Actions
setRows: (rows: ProductRow[]) => void;
appendRows: (newRows: ProductRow[]) => void;
setDraftGamme: (codein: string, gamme: GammeCode) => void;
resetDrafts: () => void;
/** Clear specific draft changes by codein */
@@ -102,6 +103,18 @@ export const useGridStore = create<GridState>()(
set({ rows, rowsIndex, summary: computeSummary(rows, get().draftChanges, get().activeMagasin) });
},
appendRows: (newRows) => {
const { rows, rowsIndex, draftChanges, activeMagasin } = get();
// O(n) uniquement sur les nouveaux éléments, au lieu de re-calculer les 130k existants
const mergedRows = [...rows, ...newRows];
newRows.forEach(r => rowsIndex.set(r.codein, r));
set({
rows: mergedRows,
rowsIndex,
summary: computeSummary(mergedRows, draftChanges, activeMagasin)
});
},
setDraftGamme: (codein, gamme) => {
const { rows, rowsIndex, draftChanges: oldDrafts } = get();
// Lookup O(1) via l'index au lieu de O(n) via .find()