Skip to content

Commit

Permalink
feat(snippets): add empty trash
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov committed Apr 7, 2022
1 parent f27295a commit 8bcf972
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/main/services/ipc/context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,36 @@ export const subscribeToContextMenu = () => {
}
]

const trashMenu: MenuItemConstructorOptions[] = [
{
label: 'Empty Trash',
click: () => {
const buttonId = dialog.showMessageBoxSync({
message:
'Are you sure you want to permanently delete all snippets in Trash?',
detail: 'You cannot undo this action.',
buttons: ['Delete', 'Cancel'],
defaultId: 0,
cancelId: 1
})

if (buttonId === 0) {
resolve({
action: 'delete',
type,
data: undefined
})
} else {
resolve({
action: 'none',
type,
data: undefined
})
}
}
}
]

if (type === 'folder') {
folderMenu.forEach(i => {
menu.append(new MenuItem(i))
Expand All @@ -287,6 +317,12 @@ export const subscribeToContextMenu = () => {
})
}

if (type === 'trash') {
trashMenu.forEach(i => {
menu.append(new MenuItem(i))
})
}

menu.on('menu-will-close', () => {
BrowserWindow.getFocusedWindow()?.webContents.send(
'context-menu:close'
Expand Down
21 changes: 21 additions & 0 deletions src/renderer/components/sidebar/SidebarListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,27 @@ const onClickContextMenu = async () => {
}
}
if (props.alias) {
const { action, type, data } = await ipc.invoke<
ContextMenuResponse,
ContextMenuPayload
>('context-menu:library', {
name: props.name,
type: 'trash',
data: {}
})
if (action === 'delete') {
console.log('trash delete')
snippetStore.emptyTrash()
await snippetStore.getSnippets()
if (folderStore.selectedAlias === 'trash') {
snippetStore.setSnippetsByAlias('trash')
}
}
}
if (props.isTag) {
const { action, type, data } = await ipc.invoke<
ContextMenuResponse,
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/store/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,10 @@ export const useSnippetStore = defineStore('snippets', {
setSnippetById (id: string) {
const snippet = this.all.find(i => i.id === id)
if (snippet) this.selected = snippet
},
async emptyTrash () {
const ids = this.all.filter(i => i.isDeleted).map(i => i.id)
await this.deleteSnippetsByIds(ids)
}
}
})

0 comments on commit 8bcf972

Please sign in to comment.