mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-16 11:49:18 +02:00
feat: implement grid state management, data fetching, and infinite scroll infrastructure
This commit is contained in:
1 parent
2893114fca
commit
88a3121c92
4 files changed
+61
-37
No files matched your search
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user