From 3462ac9991d05c6ed0bf3101928fbd281c6f514c Mon Sep 17 00:00:00 2001 From: Christian Vidal Wolf Date: Tue, 21 Apr 2026 08:55:50 +0200 Subject: [PATCH] feat: update Dropbox source URL and implement smart dirty-checking for row highlight --- src/App.tsx | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 354f5be..5f73436 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -318,23 +318,48 @@ export default function App() { const handleSaveRow = (rowIndex: number, updatedRow: ExcelRow) => { const articleNo = String(updatedRow[COLUMNS.ARTICLE_NO]); - const originalData = appState.data[rowIndex]; // Capture before update + const currentPending = pendingRows[articleNo]; + const originalData = currentPending?.originalData ?? appState.data[rowIndex]; + + // Check if the new state is actually different from the original (not the current) + const isActuallyModified = JSON.stringify(updatedRow) !== JSON.stringify(originalData); + setAppState(prev => { const newData = [...prev.data]; newData[rowIndex] = updatedRow; return { ...prev, data: newData, hasUnsavedChanges: true }; }); - setPendingRows(prev => ({ - ...prev, - [articleNo]: { - rowIndex, - // Keep the very first originalData if already pending (re-edit case) - originalData: prev[articleNo]?.originalData ?? originalData, - newData: updatedRow, - articleName: String(updatedRow[COLUMNS.ARTICLE_NAME] || articleNo), - } - })); - setRowStatuses(prev => ({ ...prev, [articleNo]: 'pending' })); + + if (isActuallyModified) { + setPendingRows(prev => { + const next = { + ...prev, + [articleNo]: { + rowIndex, + originalData, + newData: updatedRow, + articleName: String(updatedRow[COLUMNS.ARTICLE_NAME] || articleNo), + } + }; + setAppState(app => ({ ...app, hasUnsavedChanges: true })); + return next; + }); + setRowStatuses(prev => ({ ...prev, [articleNo]: 'pending' })); + } else { + // It was changed back to its original state - remove from pending + setPendingRows(prev => { + const n = { ...prev }; + delete n[articleNo]; + const stillHasChanges = Object.keys(n).length > 0; + setAppState(app => ({ ...app, hasUnsavedChanges: stillHasChanges })); + return n; + }); + setRowStatuses(prev => { + const n = { ...prev }; + delete n[articleNo]; + return n; + }); + } setEditingRowIndex(null); };