refactor: Use invoke for ipc to remove hashtag

This commit is contained in:
AkiraFukushima 2020-11-29 23:19:16 +09:00
parent 778ed6f642
commit 0cb08601f8
2 changed files with 7 additions and 23 deletions

View File

@ -1000,16 +1000,9 @@ ipcMain.handle('list-hashtags', async (_: IpcMainInvokeEvent) => {
return tags
})
ipcMain.on('remove-hashtag', (event: IpcMainEvent, tag: LocalTag) => {
ipcMain.handle('remove-hashtag', async (_: IpcMainInvokeEvent, tag: LocalTag) => {
const hashtags = new Hashtags(hashtagsDB)
hashtags
.removeTag(tag)
.then(() => {
event.sender.send('response-remove-hashtag')
})
.catch(err => {
event.sender.send('error-remove-hashtag', err)
})
await hashtags.removeTag(tag)
})
// Fonts

View File

@ -29,20 +29,11 @@ const actions: ActionTree<ListState, RootState> = {
commit(MUTATION_TYPES.UPDATE_TAGS, tags)
return tags
},
removeTag: ({ dispatch }, tag: LocalTag) => {
return new Promise((resolve, reject) => {
win.ipcRenderer.once('response-remove-hashtag', () => {
win.ipcRenderer.removeAllListeners('error-remove-hashtag')
dispatch('listTags')
dispatch('TimelineSpace/SideMenu/listTags', {}, { root: true })
resolve('deleted')
})
win.ipcRenderer.once('error-remove-hashtag', (_, err: Error) => {
win.ipcRenderer.removeAllListeners('response-remove-hashtag')
reject(err)
})
win.ipcRenderer.send('remove-hashtag', tag)
})
removeTag: async ({ dispatch }, tag: LocalTag) => {
await win.ipcRenderer.invoke('remove-hashtag', tag)
dispatch('listTags')
dispatch('TimelineSpace/SideMenu/listTags', {}, { root: true })
return 'deleted'
}
}