Convert selection to map
parent
c70d46b45c
commit
bee28095fa
|
@ -53,7 +53,7 @@ export default class Photo extends Mixins(GlobalMixin) {
|
||||||
@Prop() rowHeight: number;
|
@Prop() rowHeight: number;
|
||||||
@Prop() day: IDay;
|
@Prop() day: IDay;
|
||||||
|
|
||||||
@Emit('reprocess') emitReprocess(remIds: Set<number>, updatedDays: Set<IDay>) {}
|
@Emit('reprocess') emitReprocess(remPhotos: IPhoto[]) {}
|
||||||
@Emit('select') emitSelect(data: IPhoto) {}
|
@Emit('select') emitSelect(data: IPhoto) {}
|
||||||
@Emit('clickImg') emitClickImg(component: any) {}
|
@Emit('clickImg') emitClickImg(component: any) {}
|
||||||
|
|
||||||
|
@ -180,7 +180,9 @@ export default class Photo extends Mixins(GlobalMixin) {
|
||||||
this.day.origFileIds = newIds;
|
this.day.origFileIds = newIds;
|
||||||
|
|
||||||
// Remove deleted files from details
|
// Remove deleted files from details
|
||||||
this.emitReprocess(remIds, new Set([this.day]));
|
// Get IPhotos of the deleted file Ids
|
||||||
|
const remPhotos = this.day.detail.filter(p => remIds.has(p.fileid));
|
||||||
|
this.emitReprocess(remPhotos);
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleSelect() {
|
toggleSelect() {
|
||||||
|
|
|
@ -194,7 +194,7 @@ export default class Timeline extends Mixins(GlobalMixin) {
|
||||||
/** Set of dayIds for which images loaded */
|
/** Set of dayIds for which images loaded */
|
||||||
private loadedDays = new Set<number>();
|
private loadedDays = new Set<number>();
|
||||||
/** Set of selected file ids */
|
/** Set of selected file ids */
|
||||||
private selection = new Set<IPhoto>();
|
private selection = new Map<number, IPhoto>();
|
||||||
|
|
||||||
/** State for request cancellations */
|
/** State for request cancellations */
|
||||||
private state = Math.random();
|
private state = Math.random();
|
||||||
|
@ -864,13 +864,13 @@ export default class Timeline extends Mixins(GlobalMixin) {
|
||||||
|
|
||||||
/** Add a photo to selection list */
|
/** Add a photo to selection list */
|
||||||
selectPhoto(photo: IPhoto, val?: boolean, noUpdate?: boolean) {
|
selectPhoto(photo: IPhoto, val?: boolean, noUpdate?: boolean) {
|
||||||
const nval = val ?? !this.selection.has(photo);
|
const nval = val ?? !this.selection.has(photo.fileid);
|
||||||
if (nval) {
|
if (nval) {
|
||||||
photo.flag |= this.c.FLAG_SELECTED;
|
photo.flag |= this.c.FLAG_SELECTED;
|
||||||
this.selection.add(photo);
|
this.selection.set(photo.fileid, photo);
|
||||||
} else {
|
} else {
|
||||||
photo.flag &= ~this.c.FLAG_SELECTED;
|
photo.flag &= ~this.c.FLAG_SELECTED;
|
||||||
this.selection.delete(photo);
|
this.selection.delete(photo.fileid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!noUpdate) {
|
if (!noUpdate) {
|
||||||
|
@ -880,12 +880,13 @@ export default class Timeline extends Mixins(GlobalMixin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Clear all selected photos */
|
/** Clear all selected photos */
|
||||||
clearSelection(only?: Set<IPhoto>) {
|
clearSelection(only?: IPhoto[]) {
|
||||||
const heads = new Set<IHeadRow>();
|
const heads = new Set<IHeadRow>();
|
||||||
new Set(only || this.selection).forEach((photo: IPhoto) => {
|
const toClear = only || this.selection.values();
|
||||||
|
Array.from(toClear).forEach((photo: IPhoto) => {
|
||||||
photo.flag &= ~this.c.FLAG_SELECTED;
|
photo.flag &= ~this.c.FLAG_SELECTED;
|
||||||
heads.add(this.heads[photo.d.dayid]);
|
heads.add(this.heads[photo.d.dayid]);
|
||||||
this.selection.delete(photo);
|
this.selection.delete(photo.fileid);
|
||||||
});
|
});
|
||||||
heads.forEach(this.updateHeadSelected);
|
heads.forEach(this.updateHeadSelected);
|
||||||
this.$forceUpdate();
|
this.$forceUpdate();
|
||||||
|
@ -929,7 +930,8 @@ export default class Timeline extends Mixins(GlobalMixin) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await dav.downloadFilesByIds([...this.selection].map(p => p.fileid));
|
await dav.downloadFilesByIds(Array.from(this.selection.keys()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -943,13 +945,13 @@ export default class Timeline extends Mixins(GlobalMixin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const list = [...this.selection];
|
|
||||||
this.loading++;
|
this.loading++;
|
||||||
for await (const delIds of dav.deleteFilesByIds(list.map(p => p.fileid))) {
|
for await (const delIds of dav.deleteFilesByIds(Array.from(this.selection.keys()))) {
|
||||||
const delIdsSet = new Set(delIds.filter(i => i));
|
const delPhotos = delIds.map(id => this.selection.get(id));
|
||||||
const updatedDays = new Set(list.filter(f => delIdsSet.has(f.fileid)).map(f => f.d));
|
await this.deleteFromViewWithAnimation(delPhotos);
|
||||||
await this.deleteFromViewWithAnimation(delIdsSet, updatedDays);
|
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
} finally {
|
} finally {
|
||||||
this.loading--;
|
this.loading--;
|
||||||
}
|
}
|
||||||
|
@ -964,27 +966,20 @@ export default class Timeline extends Mixins(GlobalMixin) {
|
||||||
* a call to processDay so just pass it the list of ids to
|
* a call to processDay so just pass it the list of ids to
|
||||||
* delete and the days that were updated.
|
* delete and the days that were updated.
|
||||||
*
|
*
|
||||||
* @param {Set} delIds Set of file ids to delete
|
* @param delPhotos photos to delete
|
||||||
* @param {Set} updatedDays of days that MAY be affected
|
|
||||||
*/
|
*/
|
||||||
async deleteFromViewWithAnimation(delIds: Set<number>, updatedDays: Set<IDay>) {
|
async deleteFromViewWithAnimation(delPhotos: IPhoto[]) {
|
||||||
if (delIds.size === 0 || updatedDays.size === 0) {
|
if (delPhotos.length === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set of photos that are being deleted
|
// Get all days that need to be updatd
|
||||||
const delPhotos = new Set<IPhoto>();
|
const updatedDays = new Set<IDay>(delPhotos.map(p => p.d));
|
||||||
|
const delPhotosSet = new Set(delPhotos);
|
||||||
|
|
||||||
// Animate the deletion
|
// Animate the deletion
|
||||||
for (const day of updatedDays) {
|
for (const photo of delPhotos) {
|
||||||
for (const row of day.rows) {
|
photo.flag |= this.c.FLAG_LEAVING;
|
||||||
for (const photo of row.photos) {
|
|
||||||
if (delIds.has(photo.fileid)) {
|
|
||||||
photo.flag |= this.c.FLAG_LEAVING;
|
|
||||||
delPhotos.add(photo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// wait for 200ms
|
// wait for 200ms
|
||||||
|
@ -1014,7 +1009,7 @@ export default class Timeline extends Mixins(GlobalMixin) {
|
||||||
|
|
||||||
// Reflow all touched days
|
// Reflow all touched days
|
||||||
for (const day of updatedDays) {
|
for (const day of updatedDays) {
|
||||||
day.detail = day.detail.filter(p => !delIds.has(p.fileid));
|
day.detail = day.detail.filter(p => !delPhotosSet.has(p));
|
||||||
day.count = day.detail.length;
|
day.count = day.detail.length;
|
||||||
this.processDay(day);
|
this.processDay(day);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue