Skip to content

Commit 8e77886

Browse files
committed
confirm delete file or dir
1 parent 74142d7 commit 8e77886

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/components/Sidebars/FileSideBar/FileItemRows.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ const FileItemRows: React.FC<ListChildComponentProps> = ({ index, style, data })
7171
setIsNewDirectoryModalOpen(true)
7272
}, [file.path, isDirectory])
7373

74+
const handleDelete = useCallback(() => {
75+
const itemType = isDirectory ? 'directory' : 'file'
76+
const confirmMessage = `Are you sure you want to delete this ${itemType}?${
77+
isDirectory ? ' This will delete all contents of the directory.' : ''
78+
}`
79+
80+
if (window.confirm(confirmMessage)) {
81+
deleteFile(file.path)
82+
}
83+
}, [deleteFile, file.path, isDirectory])
84+
7485
const itemClasses = `flex items-center cursor-pointer px-2 py-1 border-b border-gray-200 hover:bg-neutral-700 h-full mt-0 mb-0 text-cyan-100 font-sans text-xs leading-relaxed rounded-md ${
7586
isSelected ? 'bg-neutral-700 text-white font-semibold' : 'text-gray-200'
7687
} ${isDragOver ? 'bg-neutral-500' : ''}`
@@ -82,7 +93,7 @@ const FileItemRows: React.FC<ListChildComponentProps> = ({ index, style, data })
8293
</ContextMenuItem>
8394
<ContextMenuItem onClick={openNewDirectoryModal}>New Folder</ContextMenuItem>
8495
<ContextMenuItem onClick={() => setNoteToBeRenamed(file.path)}>Rename</ContextMenuItem>
85-
<ContextMenuItem onClick={() => deleteFile(file.path)}>Delete</ContextMenuItem>
96+
<ContextMenuItem onClick={handleDelete}>Delete</ContextMenuItem>
8697
</>
8798
)
8899

src/main.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import React from 'react'
22

33
import ReactDOM from 'react-dom/client'
4-
import { toast } from 'react-toastify'
54
import * as Sentry from '@sentry/electron/renderer'
5+
import { toast } from 'react-toastify'
66

77
import App from './App'
88
import './styles/global.css'
99
import errorToStringRendererProcess from './lib/error'
1010

11-
Sentry.init({
12-
integrations: [],
13-
})
11+
if (process.env.NODE_ENV === 'production') {
12+
Sentry.init({
13+
integrations: [],
14+
})
15+
}
1416

1517
window.addEventListener('error', (event) => {
1618
event.preventDefault()

0 commit comments

Comments
 (0)