Skip to content

Commit 0db6756

Browse files
feat(snippets): add restore from trash (#221)
1 parent 6acbf8d commit 0db6756

File tree

6 files changed

+50
-5
lines changed

6 files changed

+50
-5
lines changed

src/main/services/i18n/locales/en/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@
5858
"hide": "Hide",
5959
"show": "Show",
6060
"collapse-all": "Collapse All",
61-
"expand-all": "Expand All"
61+
"expand-all": "Expand All",
62+
"restore": "Restore"
6263
}

src/main/services/i18n/locales/ru/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@
5757
"hide": "Hide",
5858
"show": "Show",
5959
"collapse-all": "Закрыть все",
60-
"expand-all": "Открыть все"
60+
"expand-all": "Открыть все",
61+
"restore": "Восстановить"
6162
}

src/main/services/ipc/context-menu.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ export const subscribeToContextMenu = () => {
156156
})
157157
}
158158
}
159+
},
160+
{
161+
label: i18n.t('restore'),
162+
click: () => {
163+
resolve({
164+
action: 'restore-from-trash',
165+
type,
166+
data: undefined
167+
})
168+
}
159169
}
160170
]
161171

src/renderer/components/sidebar/TheSidebar.vue

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ import { useTagStore } from '@/store/tags'
100100
import { emitter, onAddNewFolder } from '@/composable'
101101
import interact from 'interactjs'
102102
import { useAppStore } from '@/store/app'
103+
import type { Snippet } from '@shared/types/main/db'
103104
104105
const folderStore = useFolderStore()
105106
const snippetStore = useSnippetStore()
@@ -156,12 +157,26 @@ const onDrop = async (e: DragEvent, id: string) => {
156157
157158
if (payload) {
158159
const snippetIds = JSON.parse(payload)
160+
159161
for (const i of snippetIds) {
160-
await snippetStore.patchSnippetsById(i, {
162+
const isDeleted = snippetStore.snippets.find(s => s.id === i)?.isDeleted
163+
164+
const body: Partial<Snippet> = {
161165
folderId: id
162-
})
166+
}
167+
168+
if (isDeleted) body.isDeleted = false
169+
170+
await snippetStore.patchSnippetsById(i, body)
171+
}
172+
173+
if (folderStore.selectedIds) {
174+
snippetStore.getSnippetsByFolderIds(folderStore.selectedIds)
175+
}
176+
177+
if (folderStore.selectedAlias) {
178+
await snippetStore.setSnippetsByAlias(folderStore.selectedAlias)
163179
}
164-
snippetStore.getSnippetsByFolderIds(folderStore.selectedIds!)
165180
}
166181
}
167182

src/renderer/components/snippets/SnippetListItem.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,23 @@ const onClickContextMenu = async () => {
207207
}
208208
}
209209
210+
if (action === 'restore-from-trash') {
211+
if (snippetStore.selectedIds.length) {
212+
for (const id of snippetStore.selectedIds) {
213+
await snippetStore.patchSnippetsById(id, {
214+
isDeleted: false
215+
})
216+
}
217+
} else {
218+
await snippetStore.patchSnippetsById(props.id, {
219+
isDeleted: false
220+
})
221+
}
222+
223+
await snippetStore.getSnippets()
224+
snippetStore.setSnippetsByAlias('trash')
225+
}
226+
210227
isHighlighted.value = false
211228
isFocused.value = false
212229
snippetStore.isContextState = false

src/shared/types/main/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type ContextMenuAction =
2121
| 'update:language'
2222
| 'collapse-all'
2323
| 'expand-all'
24+
| 'restore-from-trash'
2425
| 'none'
2526

2627
export type ContextMenuType =

0 commit comments

Comments
 (0)