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)
|
await hashtags.insertTag(tag)
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('list-hashtags', (event: IpcMainEvent) => {
|
ipcMain.handle('list-hashtags', async (_: IpcMainInvokeEvent) => {
|
||||||
const hashtags = new Hashtags(hashtagsDB)
|
const hashtags = new Hashtags(hashtagsDB)
|
||||||
hashtags
|
const tags = await hashtags.listTags()
|
||||||
.listTags()
|
return tags
|
||||||
.then(tags => {
|
|
||||||
event.sender.send('response-list-hashtags', tags)
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
event.sender.send('error-list-hashtags', err)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ipcMain.on('remove-hashtag', (event: IpcMainEvent, tag: LocalTag) => {
|
ipcMain.on('remove-hashtag', (event: IpcMainEvent, tag: LocalTag) => {
|
||||||
|
|
|
@ -24,19 +24,10 @@ const mutations: MutationTree<ListState> = {
|
||||||
}
|
}
|
||||||
|
|
||||||
const actions: ActionTree<ListState, RootState> = {
|
const actions: ActionTree<ListState, RootState> = {
|
||||||
listTags: ({ commit }) => {
|
listTags: async ({ commit }) => {
|
||||||
return new Promise((resolve, reject) => {
|
const tags: Array<LocalTag> = await win.ipcRenderer.invoke('list-hashtags')
|
||||||
win.ipcRenderer.once('response-list-hashtags', (_, tags: Array<LocalTag>) => {
|
|
||||||
win.ipcRenderer.removeAllListeners('error-list-hashtags')
|
|
||||||
commit(MUTATION_TYPES.UPDATE_TAGS, tags)
|
commit(MUTATION_TYPES.UPDATE_TAGS, tags)
|
||||||
resolve(tags)
|
return tags
|
||||||
})
|
|
||||||
win.ipcRenderer.once('error-list-hashtags', (_, err: Error) => {
|
|
||||||
win.ipcRenderer.removeAllListeners('response-list-hashtags')
|
|
||||||
reject(err)
|
|
||||||
})
|
|
||||||
win.ipcRenderer.send('list-hashtags')
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
removeTag: ({ dispatch }, tag: LocalTag) => {
|
removeTag: ({ dispatch }, tag: LocalTag) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
|
@ -149,19 +149,10 @@ const actions: ActionTree<SideMenuState, RootState> = {
|
||||||
commit(MUTATION_TYPES.CHANGE_COLLAPSE, value)
|
commit(MUTATION_TYPES.CHANGE_COLLAPSE, value)
|
||||||
return value
|
return value
|
||||||
},
|
},
|
||||||
listTags: ({ commit }) => {
|
listTags: async ({ commit }) => {
|
||||||
return new Promise((resolve, reject) => {
|
const tags: Array<LocalTag> = await win.ipcRenderer.invoke('list-hashtags')
|
||||||
win.ipcRenderer.once('response-list-hashtags', (_, tags: Array<LocalTag>) => {
|
|
||||||
win.ipcRenderer.removeAllListeners('error-list-hashtags')
|
|
||||||
commit(MUTATION_TYPES.UPDATE_TAGS, tags)
|
commit(MUTATION_TYPES.UPDATE_TAGS, tags)
|
||||||
resolve(tags)
|
return tags
|
||||||
})
|
|
||||||
win.ipcRenderer.once('error-list-hashtags', (_, err: Error) => {
|
|
||||||
win.ipcRenderer.removeAllListeners('response-list-hashtags')
|
|
||||||
reject(err)
|
|
||||||
})
|
|
||||||
win.ipcRenderer.send('list-hashtags')
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue