refactor: Use invoke for ipc to list hashtags
This commit is contained in:
parent
b3c03b1406
commit
778ed6f642
|
@ -994,16 +994,10 @@ ipcMain.handle('save-hashtag', async (_: IpcMainInvokeEvent, tag: string) => {
|
|||
await hashtags.insertTag(tag)
|
||||
})
|
||||
|
||||
ipcMain.on('list-hashtags', (event: IpcMainEvent) => {
|
||||
ipcMain.handle('list-hashtags', async (_: IpcMainInvokeEvent) => {
|
||||
const hashtags = new Hashtags(hashtagsDB)
|
||||
hashtags
|
||||
.listTags()
|
||||
.then(tags => {
|
||||
event.sender.send('response-list-hashtags', tags)
|
||||
})
|
||||
.catch(err => {
|
||||
event.sender.send('error-list-hashtags', err)
|
||||
})
|
||||
const tags = await hashtags.listTags()
|
||||
return tags
|
||||
})
|
||||
|
||||
ipcMain.on('remove-hashtag', (event: IpcMainEvent, tag: LocalTag) => {
|
||||
|
|
|
@ -24,19 +24,10 @@ const mutations: MutationTree<ListState> = {
|
|||
}
|
||||
|
||||
const actions: ActionTree<ListState, RootState> = {
|
||||
listTags: ({ commit }) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
win.ipcRenderer.once('response-list-hashtags', (_, tags: Array<LocalTag>) => {
|
||||
win.ipcRenderer.removeAllListeners('error-list-hashtags')
|
||||
commit(MUTATION_TYPES.UPDATE_TAGS, tags)
|
||||
resolve(tags)
|
||||
})
|
||||
win.ipcRenderer.once('error-list-hashtags', (_, err: Error) => {
|
||||
win.ipcRenderer.removeAllListeners('response-list-hashtags')
|
||||
reject(err)
|
||||
})
|
||||
win.ipcRenderer.send('list-hashtags')
|
||||
})
|
||||
listTags: async ({ commit }) => {
|
||||
const tags: Array<LocalTag> = await win.ipcRenderer.invoke('list-hashtags')
|
||||
commit(MUTATION_TYPES.UPDATE_TAGS, tags)
|
||||
return tags
|
||||
},
|
||||
removeTag: ({ dispatch }, tag: LocalTag) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
|
@ -149,19 +149,10 @@ const actions: ActionTree<SideMenuState, RootState> = {
|
|||
commit(MUTATION_TYPES.CHANGE_COLLAPSE, value)
|
||||
return value
|
||||
},
|
||||
listTags: ({ commit }) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
win.ipcRenderer.once('response-list-hashtags', (_, tags: Array<LocalTag>) => {
|
||||
win.ipcRenderer.removeAllListeners('error-list-hashtags')
|
||||
commit(MUTATION_TYPES.UPDATE_TAGS, tags)
|
||||
resolve(tags)
|
||||
})
|
||||
win.ipcRenderer.once('error-list-hashtags', (_, err: Error) => {
|
||||
win.ipcRenderer.removeAllListeners('response-list-hashtags')
|
||||
reject(err)
|
||||
})
|
||||
win.ipcRenderer.send('list-hashtags')
|
||||
})
|
||||
listTags: async ({ commit }) => {
|
||||
const tags: Array<LocalTag> = await win.ipcRenderer.invoke('list-hashtags')
|
||||
commit(MUTATION_TYPES.UPDATE_TAGS, tags)
|
||||
return tags
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue