🚧 WIP: add gallery db

This commit is contained in:
PiEgg
2021-07-27 00:15:11 +08:00
parent 76964ff1a5
commit c70c3aff78
8 changed files with 118 additions and 50 deletions

View File

@@ -159,14 +159,15 @@ export default class extends Vue {
this.clearChoosedList()
}
}
created () {
async created () {
ipcRenderer.on('updateGallery', (event: IpcRendererEvent) => {
this.$nextTick(() => {
this.filterList = this.getGallery()
this.$nextTick(async () => {
this.images = await this.$$db.get()
})
})
ipcRenderer.send('getPicBeds')
ipcRenderer.on('getPicBeds', this.getPicBeds)
this.images = await this.$$db.get()
}
mounted () {
document.addEventListener('keydown', this.handleDetectShiftKey)
@@ -180,9 +181,6 @@ export default class extends Vue {
get filterList () {
return this.getGallery()
}
set filterList (val) {
this.images = val
}
get isAllSelected () {
const values = Object.values(this.choosedList)
if (values.length === 0) {
@@ -196,38 +194,21 @@ export default class extends Vue {
getPicBeds (event: IpcRendererEvent, picBeds: IPicBedType[]) {
this.picBed = picBeds
}
// FIXME: gallery db && async computed - -||.....
getGallery () {
if (this.choosedPicBed.length > 0) {
let arr: ImgInfo[] = []
this.choosedPicBed.forEach(item => {
let obj: IObj = {
type: item
}
if (this.searchText) {
obj.fileName = this.searchText
}
arr = arr.concat(this.$db.read().get('uploaded').filter(obj => {
return obj.fileName.indexOf(this.searchText) !== -1 && obj.type === item
}).reverse().value())
})
this.images = arr
getGallery (): ImgInfo[] {
if (this.searchText || this.choosedPicBed.length > 0) {
return this.images
.filter(item => {
let isInChoosedPicBed = true
if (this.choosedPicBed.length > 0) {
isInChoosedPicBed = this.choosedPicBed.some(type => type === item.type)
}
return item.fileName?.includes(this.searchText) && isInChoosedPicBed
})
} else {
if (this.searchText) {
// FIXME: gallery db
let data = this.$db.read().get('uploaded')
// @ts-ignore
.filter(item => {
return item.fileName.indexOf(this.searchText) !== -1
}).reverse().value()
this.images = data
} else {
// FIXME: gallery db
this.images = this.$db.read().get('uploaded').slice().reverse().value()
}
return this.images
}
return this.images
}
@Watch('filterList')
handleFilterListChange () {
this.clearChoosedList()

View File

@@ -27,8 +27,8 @@ export class GalleryDB implements IGalleryDB {
const res = await this.msgHandler<boolean>(PICGO_UPDATE_BY_ID_DB, id, value)
return res
}
async getById (id: string): Promise<IObject | undefined> {
const res = await this.msgHandler<IObject | undefined>(PICGO_GET_BY_ID_DB, id)
async getById<T> (id: string): Promise<IResult<T> | undefined> {
const res = await this.msgHandler<IResult<T> | undefined>(PICGO_GET_BY_ID_DB, id)
return res
}
async removeById (id: string): Promise<void> {
@@ -45,7 +45,7 @@ export class GalleryDB implements IGalleryDB {
}
}
ipcRenderer.on(method, callback)
ipcRenderer.send(method, ...args)
ipcRenderer.send(method, ...args, callbackId)
})
}
}