Skip to content

Commit

Permalink
🐛 Fix: removeById handler error
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #382
  • Loading branch information
Molunerfinn committed Jan 9, 2020
1 parent 762dc9b commit c4f0a30
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/renderer/pages/Gallery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,8 @@ export default class extends Vue {
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
const file = this.$db.get('uploaded').getById(id)
// @ts-ignore
this.$db.read().get('uploaded').removeById(id).write()
const file = this.$db.getById('uploaded', id)
this.$db.removeById('uploaded', id)
ipcRenderer.send('removeFiles', [file])
const obj = {
title: '操作结果',
Expand All @@ -250,7 +249,8 @@ export default class extends Vue {
return true
}
this.getGallery()
}).catch(() => {
}).catch((e) => {
console.log(e)
return true
})
}
Expand Down Expand Up @@ -302,11 +302,9 @@ export default class extends Vue {
let files: ImgInfo[] = []
Object.keys(this.choosedList).forEach(key => {
if (this.choosedList[key]) {
// @ts-ignore
const file = this.$db.read().get('uploaded').getById(key).value()
const file = this.$db.getById('uploaded', key)
files.push(file)
// @ts-ignore
this.$db.read().get('uploaded').removeById(key).write()
this.$db.removeById('uploaded', key)
}
})
this.choosedList = {}
Expand All @@ -332,8 +330,7 @@ export default class extends Vue {
// choosedList -> { [id]: true or false }; true means choosed. false means not choosed.
Object.keys(this.choosedList).forEach(key => {
if (this.choosedList[key]) {
// @ts-ignore
const item = this.$db.read().get('uploaded').getById(key).value()
const item = this.$db.getById('uploaded', key)
copyString += pasteStyle(style, item) + '\n'
this.choosedList[key] = false
}
Expand Down
8 changes: 8 additions & 0 deletions src/universal/datastore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ class DB {
unset (key: string, value: any): boolean {
return this.read().get(key).unset(value).value()
}
getById (key: string, id: string) {
// @ts-ignore
return this.read().get(key).getById(id).value()
}
removeById (key: string, id: string) {
// @ts-ignore
return this.read().get(key).removeById(id).write()
}
}

export default new DB()

0 comments on commit c4f0a30

Please sign in to comment.