From 2854feadc52ec91ab01a3926bb8742da408c72c9 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Thu, 3 Nov 2022 14:47:10 -0700 Subject: [PATCH] Fix bad selection after day process --- src/components/SelectionManager.vue | 41 ++++++++++++++++++++++++++--- src/components/Timeline.vue | 3 +++ 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/src/components/SelectionManager.vue b/src/components/SelectionManager.vue index 46de66c9..33ad99d3 100644 --- a/src/components/SelectionManager.vue +++ b/src/components/SelectionManager.vue @@ -13,8 +13,8 @@
{{ - n("memories", "{n} selected", "{n} selected", selection.size, { - n: selection.size, + n("memories", "{n} selected", "{n} selected", size, { + n: size, }) }}
@@ -55,7 +55,7 @@ import { showError } from "@nextcloud/dialogs"; import { generateUrl } from "@nextcloud/router"; import { NcActions, NcActionButton } from "@nextcloud/vue"; import { translate as t, translatePlural as n } from "@nextcloud/l10n"; -import { IHeadRow, IPhoto, ISelectionAction } from "../types"; +import { IDay, IHeadRow, IPhoto, ISelectionAction } from "../types"; import { getCurrentUser } from "@nextcloud/auth"; import * as dav from "../services/DavRequests"; @@ -92,6 +92,7 @@ export default class SelectionManager extends Mixins(GlobalMixin, UserConfig) { @Prop() public heads: { [dayid: number]: IHeadRow }; private show = false; + private size = 0; private readonly selection!: Selection; private readonly defaultActions: ISelectionAction[]; @@ -193,6 +194,7 @@ export default class SelectionManager extends Mixins(GlobalMixin, UserConfig) { private selectionChanged() { this.show = this.selection.size > 0; + this.size = this.selection.size; } /** Is this fileid (or anything if not specified) selected */ @@ -203,6 +205,39 @@ export default class SelectionManager extends Mixins(GlobalMixin, UserConfig) { return this.selection.has(fileid); } + /** Restore selections from new day object */ + public restoreDay(day: IDay) { + if (!this.has()) { + return; + } + + // FileID => Photo for new day + const dayMap = new Map(); + day.detail.forEach((photo) => { + dayMap.set(photo.fileid, photo); + }); + + this.selection.forEach((photo, fileid) => { + // Process this day only + if (photo.dayid !== day.dayid) { + return; + } + + // Remove all selections that are not in the new day + if (!dayMap.has(fileid)) { + this.selection.delete(fileid); + return; + } + + // Update the photo object + const newPhoto = dayMap.get(fileid); + this.selection.set(fileid, newPhoto); + newPhoto.flag |= this.c.FLAG_SELECTED; + }); + + this.selectionChanged(); + } + /** Click on an action */ private async click(action: ISelectionAction) { try { diff --git a/src/components/Timeline.vue b/src/components/Timeline.vue index 6361d175..a3765004 100644 --- a/src/components/Timeline.vue +++ b/src/components/Timeline.vue @@ -1029,6 +1029,9 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) { row.photos.push(photo); } + // Restore selection day + this.selectionManager.restoreDay(day); + // Rows that were removed const removedRows: IRow[] = []; let headRemoved = false;