refactor: Use invoke for ipc to save hashtag

This commit is contained in:
AkiraFukushima 2020-11-29 22:49:10 +09:00
parent 5d4428038b
commit b3c03b1406
2 changed files with 5 additions and 14 deletions

View File

@ -989,16 +989,9 @@ ipcMain.handle('change-language', async (_: IpcMainInvokeEvent, value: string) =
}) })
// hashtag // hashtag
ipcMain.on('save-hashtag', (event: IpcMainEvent, tag: string) => { ipcMain.handle('save-hashtag', async (_: IpcMainInvokeEvent, tag: string) => {
const hashtags = new Hashtags(hashtagsDB) const hashtags = new Hashtags(hashtagsDB)
hashtags await hashtags.insertTag(tag)
.insertTag(tag)
.then(() => {
event.sender.send('response-save-hashtag')
})
.catch(err => {
log.error(err)
})
}) })
ipcMain.on('list-hashtags', (event: IpcMainEvent) => { ipcMain.on('list-hashtags', (event: IpcMainEvent) => {

View File

@ -18,11 +18,9 @@ export type HashtagModuleState = HashtagModule & HashtagState
const state = (): HashtagState => ({}) const state = (): HashtagState => ({})
const actions: ActionTree<HashtagState, RootState> = { const actions: ActionTree<HashtagState, RootState> = {
saveTag: ({ dispatch }, tag: string) => { saveTag: async ({ dispatch }, tag: string) => {
win.ipcRenderer.once('response-save-hashtag', () => { await win.ipcRenderer.invoke('save-hashtag', tag)
dispatch('TimelineSpace/SideMenu/listTags', {}, { root: true }) dispatch('TimelineSpace/SideMenu/listTags', {}, { root: true })
})
win.ipcRenderer.send('save-hashtag', tag)
} }
} }