feat: add delete confirmation modal with 5-second undo option#55
feat: add delete confirmation modal with 5-second undo option#55nidhii-dev wants to merge 5 commits into
Conversation
| const timer = setTimeout(() => { | ||
| onDeleteNode(nodeId); | ||
| setUndoToast(null); | ||
| }, 5000); |
There was a problem hiding this comment.
Pending delete timer is not cleared on FileNode unmount
The setTimeout stored in undoToast.timer is never cancelled if the FileNode unmounts during the 5-second window (e.g. parent re-renders, room closes). When it fires, onDeleteNode(nodeId) executes unintentionally and setUndoToast(null) is called on an unmounted component.
Prompt to fix with AI
Copy this prompt into your AI coding assistant to fix this issue.
In `src/components/FileExplorer.js`, the `FileNode` component creates a `setTimeout` inside `handleDeleteConfirm` (lines 74-77) and stores it in `undoToast.timer`, but never clears it when the component unmounts. Add a `useEffect` cleanup:
1. Add `useEffect` to the import on line 1: `import React, { useState, useRef, useEffect } from 'react';`
2. After the `handleUndo` function (after line 85), add:
```js
useEffect(() => {
return () => {
if (undoToast?.timer) clearTimeout(undoToast.timer);
};
}, [undoToast]);
This ensures the pending deletion timer is cancelled if the component unmounts during the 5-second undo window, preventing unintended file deletion.
</details>
| <Pencil size={13} /> | ||
| </button> | ||
| <button title="Delete" onClick={() => onDeleteNode(node.id)}> | ||
| <button title="Delete" onClick={() => handleDeleteClick(node.id, node.name, node.type, node.children?.length ?? 0)}> |
There was a problem hiding this comment.
childCount is shallow-only but modal says "all X files inside"
FileExplorer.js passes node.children?.length (direct children only) as childCount, but DeleteConfirmModal.js:26 displays it as "along with all X files inside" — language that implies a deep/recursive count. A folder with 2 subfolders each containing 10 files would show "2 files inside" instead of 22.
Prompt to fix with AI
Copy this prompt into your AI coding assistant to fix this issue.
Either (a) compute a recursive child count before passing it to handleDeleteClick — add a helper like `function countDescendants(node, fs) { return (node.children || []).reduce((n, id) => n + 1 + countDescendants(fs[id] || {}, fs), 0); }` and pass the result instead of `node.children?.length`, OR (b) change the modal copy to say "along with all items directly inside" to match the shallow count that is actually passed.
Confidence Score: 2/5 - Changes NeededNot safe to merge — this PR introduces a delete confirmation modal with a 5-second undo timer, but contains two reliability bugs that could cause data loss or undefined behavior before the feature is fit for production. Specifically, Key Findings:
Files requiring special attention
|
|
@nidhii-dev Key Findings: In DeleteConfirmModal.js, the combination of confirmRef auto-focus and a global keydown listener on the Delete button causes onConfirm to be invoked twice when the user presses Enter — the first call via the keydown handler and the second via the button's native click event. This creates a second setTimeout timer that the undo toast has no reference to, making it impossible to cancel the deletion. |
fix: prevent Enter key from triggering deletion twice Co-authored-by: entelligence-ai-pr-reviews[bot] <174136889+entelligence-ai-pr-reviews[bot]@users.noreply.github.com>
EntelligenceAI PR SummaryThis PR improves the deletion confirmation message wording and adds timer cleanup logic to prevent memory leaks in the FileNode component.
Confidence Score: 5/5 - Safe to MergeSafe to merge — this PR makes clean, targeted improvements to Key Findings:
Files requiring special attention
|
Co-authored-by: entelligence-ai-pr-reviews[bot] <174136889+entelligence-ai-pr-reviews[bot]@users.noreply.github.com>
@nidhii-dev kindly fix these issues |
Changes
Testing
Closes issue #54