Skip to content

Commit d9faa3d

Browse files
feat(spaces): confirm before deleting math sheets and drawings (#848)
1 parent 867e2ab commit d9faa3d

2 files changed

Lines changed: 44 additions & 4 deletions

File tree

src/renderer/components/drawings/List.vue

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
useContentSort,
66
useCopyToClipboard,
77
useDeleteShortcut,
8+
useDialog,
89
useDrawings,
910
useInlineRename,
1011
} from '@/composables'
@@ -26,6 +27,7 @@ const {
2627
} = useDrawings()
2728
const copyToClipboard = useCopyToClipboard()
2829
const { contentSortState } = useContentSort()
30+
const { confirm } = useDialog()
2931
3032
function copyLinkForNote(name: string) {
3133
copyToClipboard(`![${name}](masscode://drawing/${encodeURIComponent(name)})`)
@@ -153,12 +155,29 @@ function selectDrawingFromList(id: string, event: MouseEvent) {
153155
focusDrawingListItem(event)
154156
}
155157
158+
async function confirmDeleteDrawing(id: string) {
159+
const drawing = drawings.value.find(item => item.id === id)
160+
161+
const isConfirmed = await confirm({
162+
title: i18n.t('messages:confirm.deletePermanently', {
163+
name: drawing?.name ?? '',
164+
}),
165+
content: i18n.t('messages:warning.noUndo'),
166+
})
167+
168+
if (!isConfirmed) {
169+
return
170+
}
171+
172+
await deleteDrawing(id)
173+
}
174+
156175
function deleteActiveDrawing() {
157176
if (!activeDrawingId.value) {
158177
return
159178
}
160179
161-
void deleteDrawing(activeDrawingId.value)
180+
void confirmDeleteDrawing(activeDrawingId.value)
162181
}
163182
164183
useDeleteShortcut({
@@ -281,7 +300,9 @@ defineExpose({
281300
{{ i18n.t("spaces.drawings.exportImage") }}
282301
</ContextMenu.ContextMenuItem>
283302
<ContextMenu.ContextMenuSeparator />
284-
<ContextMenu.ContextMenuItem @click="deleteDrawing(drawing.id)">
303+
<ContextMenu.ContextMenuItem
304+
@click="confirmDeleteDrawing(drawing.id)"
305+
>
285306
{{ i18n.t("action.delete.common") }}
286307
</ContextMenu.ContextMenuItem>
287308
</ContextMenu.ContextMenuContent>

src/renderer/components/math-notebook/SheetList.vue

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
useApp,
55
useContentSort,
66
useDeleteShortcut,
7+
useDialog,
78
useInlineRename,
89
useMathNotebook,
910
} from '@/composables'
@@ -22,6 +23,7 @@ const {
2223
renameSheet,
2324
} = useMathNotebook()
2425
const { contentSortState } = useContentSort()
26+
const { confirm } = useDialog()
2527
2628
const {
2729
editingId,
@@ -146,12 +148,29 @@ function selectSheetFromList(id: string, event: MouseEvent) {
146148
focusSheetListItem(event)
147149
}
148150
151+
async function confirmDeleteSheet(id: string) {
152+
const sheet = sheets.value.find(item => item.id === id)
153+
154+
const isConfirmed = await confirm({
155+
title: i18n.t('messages:confirm.deletePermanently', {
156+
name: sheet?.name ?? '',
157+
}),
158+
content: i18n.t('messages:warning.noUndo'),
159+
})
160+
161+
if (!isConfirmed) {
162+
return
163+
}
164+
165+
deleteSheet(id)
166+
}
167+
149168
function deleteActiveSheet() {
150169
if (!activeSheetId.value) {
151170
return
152171
}
153172
154-
deleteSheet(activeSheetId.value)
173+
void confirmDeleteSheet(activeSheetId.value)
155174
}
156175
157176
useDeleteShortcut({
@@ -262,7 +281,7 @@ defineExpose({
262281
{{ i18n.t("action.rename") }}
263282
</ContextMenu.ContextMenuItem>
264283
<ContextMenu.ContextMenuSeparator />
265-
<ContextMenu.ContextMenuItem @click="deleteSheet(sheet.id)">
284+
<ContextMenu.ContextMenuItem @click="confirmDeleteSheet(sheet.id)">
266285
{{ i18n.t("action.delete.common") }}
267286
</ContextMenu.ContextMenuItem>
268287
</ContextMenu.ContextMenuContent>

0 commit comments

Comments
 (0)