mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 13:15:24 +02:00
Implement Undo system for AI and bulk actions
This commit is contained in:
+27
@@ -10,6 +10,7 @@ import { getAllSyncedRows, saveRowToSupabase } from './lib/supabase';
|
||||
import { getStoredSession, signOut, type AuthSession } from './lib/auth';
|
||||
import { LoginPage } from './components/LoginPage';
|
||||
import { DimensionsView } from './components/DimensionsView';
|
||||
import { UndoToast } from './components/UndoToast';
|
||||
|
||||
export default function App() {
|
||||
const [session, setSession] = useState<AuthSession | null>(() => getStoredSession());
|
||||
@@ -31,6 +32,7 @@ export default function App() {
|
||||
hasUnsavedChanges: false
|
||||
});
|
||||
const [activeModule, setActiveModule] = useState<'descriptions' | 'matrix' | 'dimensions'>('descriptions');
|
||||
const [undoState, setUndoState] = useState<{ data: ExcelRow[], message: string } | null>(null);
|
||||
const [editingRowIndex, setEditingRowIndex] = useState<number | null>(null);
|
||||
const [isLoadingDefault, setIsLoadingDefault] = useState(true);
|
||||
const [defaultLoadError, setDefaultLoadError] = useState<string | null>(null);
|
||||
@@ -245,6 +247,23 @@ export default function App() {
|
||||
}
|
||||
};
|
||||
|
||||
const captureState = (message: string) => {
|
||||
setUndoState({
|
||||
data: JSON.parse(JSON.stringify(appState.data)), // Deep copy
|
||||
message
|
||||
});
|
||||
};
|
||||
|
||||
const handleUndo = () => {
|
||||
if (!undoState) return;
|
||||
setAppState(prev => ({
|
||||
...prev,
|
||||
data: undoState.data,
|
||||
hasUnsavedChanges: true
|
||||
}));
|
||||
setUndoState(null);
|
||||
};
|
||||
|
||||
const stats = useMemo(() => {
|
||||
if (appState.data.length === 0) return null;
|
||||
let missingDeLong = 0;
|
||||
@@ -329,6 +348,7 @@ export default function App() {
|
||||
headers={appState.headers}
|
||||
onEdit={(index) => setEditingRowIndex(index)}
|
||||
onSaveRow={handleSaveRow}
|
||||
onCaptureState={captureState}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
@@ -336,12 +356,19 @@ export default function App() {
|
||||
</main>
|
||||
</div>
|
||||
|
||||
<UndoToast
|
||||
undoState={undoState}
|
||||
onUndo={handleUndo}
|
||||
onClose={() => setUndoState(null)}
|
||||
/>
|
||||
|
||||
{editingRowIndex !== null && (
|
||||
<EditPanel
|
||||
row={appState.data[editingRowIndex]}
|
||||
rowIndex={editingRowIndex}
|
||||
onSave={handleSaveRow}
|
||||
onClose={() => setEditingRowIndex(null)}
|
||||
onCaptureState={captureState}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user