diff --git a/src/main/services/i18n/locales/en/common.json b/src/main/services/i18n/locales/en/common.json index a3481ad7..99880900 100644 --- a/src/main/services/i18n/locales/en/common.json +++ b/src/main/services/i18n/locales/en/common.json @@ -58,5 +58,6 @@ "hide": "Hide", "show": "Show", "collapse-all": "Collapse All", - "expand-all": "Expand All" + "expand-all": "Expand All", + "restore": "Restore" } diff --git a/src/main/services/i18n/locales/ru/common.json b/src/main/services/i18n/locales/ru/common.json index cc7eb5ed..bc45d3a8 100644 --- a/src/main/services/i18n/locales/ru/common.json +++ b/src/main/services/i18n/locales/ru/common.json @@ -57,5 +57,6 @@ "hide": "Hide", "show": "Show", "collapse-all": "Закрыть все", - "expand-all": "Открыть все" + "expand-all": "Открыть все", + "restore": "Восстановить" } diff --git a/src/main/services/ipc/context-menu.ts b/src/main/services/ipc/context-menu.ts index 1a4be84f..d095f8cc 100644 --- a/src/main/services/ipc/context-menu.ts +++ b/src/main/services/ipc/context-menu.ts @@ -156,6 +156,16 @@ export const subscribeToContextMenu = () => { }) } } + }, + { + label: i18n.t('restore'), + click: () => { + resolve({ + action: 'restore-from-trash', + type, + data: undefined + }) + } } ] diff --git a/src/renderer/components/sidebar/TheSidebar.vue b/src/renderer/components/sidebar/TheSidebar.vue index f467fed2..11c220ff 100644 --- a/src/renderer/components/sidebar/TheSidebar.vue +++ b/src/renderer/components/sidebar/TheSidebar.vue @@ -100,6 +100,7 @@ import { useTagStore } from '@/store/tags' import { emitter, onAddNewFolder } from '@/composable' import interact from 'interactjs' import { useAppStore } from '@/store/app' +import type { Snippet } from '@shared/types/main/db' const folderStore = useFolderStore() const snippetStore = useSnippetStore() @@ -156,12 +157,26 @@ const onDrop = async (e: DragEvent, id: string) => { if (payload) { const snippetIds = JSON.parse(payload) + for (const i of snippetIds) { - await snippetStore.patchSnippetsById(i, { + const isDeleted = snippetStore.snippets.find(s => s.id === i)?.isDeleted + + const body: Partial = { folderId: id - }) + } + + if (isDeleted) body.isDeleted = false + + await snippetStore.patchSnippetsById(i, body) + } + + if (folderStore.selectedIds) { + snippetStore.getSnippetsByFolderIds(folderStore.selectedIds) + } + + if (folderStore.selectedAlias) { + await snippetStore.setSnippetsByAlias(folderStore.selectedAlias) } - snippetStore.getSnippetsByFolderIds(folderStore.selectedIds!) } } diff --git a/src/renderer/components/snippets/SnippetListItem.vue b/src/renderer/components/snippets/SnippetListItem.vue index 7d2c0469..f5c5d699 100644 --- a/src/renderer/components/snippets/SnippetListItem.vue +++ b/src/renderer/components/snippets/SnippetListItem.vue @@ -207,6 +207,23 @@ const onClickContextMenu = async () => { } } + if (action === 'restore-from-trash') { + if (snippetStore.selectedIds.length) { + for (const id of snippetStore.selectedIds) { + await snippetStore.patchSnippetsById(id, { + isDeleted: false + }) + } + } else { + await snippetStore.patchSnippetsById(props.id, { + isDeleted: false + }) + } + + await snippetStore.getSnippets() + snippetStore.setSnippetsByAlias('trash') + } + isHighlighted.value = false isFocused.value = false snippetStore.isContextState = false diff --git a/src/shared/types/main/index.d.ts b/src/shared/types/main/index.d.ts index feb64822..1c522ddf 100644 --- a/src/shared/types/main/index.d.ts +++ b/src/shared/types/main/index.d.ts @@ -21,6 +21,7 @@ type ContextMenuAction = | 'update:language' | 'collapse-all' | 'expand-all' + | 'restore-from-trash' | 'none' export type ContextMenuType =