Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/main/services/i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@
"hide": "Hide",
"show": "Show",
"collapse-all": "Collapse All",
"expand-all": "Expand All"
"expand-all": "Expand All",
"restore": "Restore"
}
3 changes: 2 additions & 1 deletion src/main/services/i18n/locales/ru/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@
"hide": "Hide",
"show": "Show",
"collapse-all": "Закрыть все",
"expand-all": "Открыть все"
"expand-all": "Открыть все",
"restore": "Восстановить"
}
10 changes: 10 additions & 0 deletions src/main/services/ipc/context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ export const subscribeToContextMenu = () => {
})
}
}
},
{
label: i18n.t('restore'),
click: () => {
resolve({
action: 'restore-from-trash',
type,
data: undefined
})
}
}
]

Expand Down
21 changes: 18 additions & 3 deletions src/renderer/components/sidebar/TheSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<Snippet> = {
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!)
}
}

Expand Down
17 changes: 17 additions & 0 deletions src/renderer/components/snippets/SnippetListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/shared/types/main/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ContextMenuAction =
| 'update:language'
| 'collapse-all'
| 'expand-all'
| 'restore-from-trash'
| 'none'

export type ContextMenuType =
Expand Down