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 return tags
}) })
ipcMain.on('remove-hashtag', (event: IpcMainEvent, tag: LocalTag) => { ipcMain.handle('remove-hashtag', async (_: IpcMainInvokeEvent, tag: LocalTag) => {
const hashtags = new Hashtags(hashtagsDB) const hashtags = new Hashtags(hashtagsDB)
hashtags await hashtags.removeTag(tag)
.removeTag(tag)
.then(() => {
event.sender.send('response-remove-hashtag')
})
.catch(err => {
event.sender.send('error-remove-hashtag', err)
})
}) })
// Fonts // Fonts

View File

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