From 254329e1c202f66d7336c786f13d54445d3f4937 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Wed, 2 Aug 2023 12:28:44 -0700 Subject: [PATCH] album: refactor add modal Signed-off-by: Varun Patil --- src/components/SelectionManager.vue | 2 +- src/components/modal/AddToAlbumModal.vue | 80 ++++++++++----------- src/components/modal/AlbumCollaborators.vue | 2 +- src/components/modal/AlbumPicker.vue | 19 ++++- 4 files changed, 58 insertions(+), 45 deletions(-) diff --git a/src/components/SelectionManager.vue b/src/components/SelectionManager.vue index 6f7819cd..e3c6c994 100644 --- a/src/components/SelectionManager.vue +++ b/src/components/SelectionManager.vue @@ -34,7 +34,7 @@ - + diff --git a/src/components/modal/AddToAlbumModal.vue b/src/components/modal/AddToAlbumModal.vue index fae75e63..8ff590e6 100644 --- a/src/components/modal/AddToAlbumModal.vue +++ b/src/components/modal/AddToAlbumModal.vue @@ -5,9 +5,9 @@
- + -
+
@@ -37,60 +37,54 @@ export default defineComponent({ data: () => ({ show: false, photos: [] as IPhoto[], - progress: 0, - processing: false, - processed: new Set(), - photosDone: 0, - totalOperations: 0, + opsDone: 0, + opsTotal: 0, }), + computed: { + progress(): number { + return Math.min(this.opsTotal ? Math.round((this.opsDone * 100) / this.opsTotal) : 100, 100); + }, + }, + methods: { open(photos: IPhoto[]) { - this.progress = 0; - this.processing = false; - this.show = true; this.photos = photos; - }, - - added(photos: IPhoto[]) { - this.$emit('added', photos); + this.show = true; + this.opsTotal = 0; }, close() { - this.photos = []; - this.processing = false; this.show = false; + this.photos = []; + this.opsTotal = 0; this.$emit('close'); }, - async processAlbum(album: IAlbum, action: 'add' | 'remove') { - const name = album.name || album.album_id.toString(); - const gen = action === 'add' - ? dav.addToAlbum(album.user, name, this.photos) - : dav.removeFromAlbum(album.user, name, this.photos); - - for await (const fids of gen) { - this.photosDone += fids.length; - this.photos.forEach((p) => { - if (fids.includes(p.fileid)) { - this.processed.add(p); - } - }); + async update(selection: IAlbum[], deselection: IAlbum[]) { + if (this.opsTotal) return; + + // Total number of DAV calls (ugh DAV) + this.opsTotal = this.photos.length * (selection.length + deselection.length); + + // Add the photos to the selected albums + for (const album of selection) { + for await (const fids of dav.addToAlbum(album.user, album.name, this.photos)) { + this.opsDone += fids.filter((f) => f).length; + } } - this.progress = Math.round((this.photosDone * 100) / this.totalOperations); - }, - async updateAlbums(albumsToAddTo: IAlbum[], albumsToRemoveFrom: IAlbum[] = []) { - if (this.processing) return; - this.processing = true; - this.processed = new Set(); - this.totalOperations = this.photos.length * (albumsToAddTo.length + albumsToRemoveFrom.length); + // Remove the photos from the deselected albums + for (const album of deselection) { + for await (const fids of dav.removeFromAlbum(album.user, album.name, this.photos)) { + this.opsDone += fids.filter((f) => f).length; + } + } - await Promise.all(albumsToAddTo.map((album) => this.processAlbum(album, 'add'))); - await Promise.all(albumsToRemoveFrom.map((album) => this.processAlbum(album, 'remove'))); - const n = this.processed.size; - this.added(Array.from(this.processed)); - showInfo(this.n('memories', '{n} processed', '{n} processed', n, { n })); + const n = this.photos.length; + showInfo(this.n('memories', '{n} photo updated', '{n} photos updated', n, { n })); + + this.$emit('change'); this.close(); }, }, @@ -101,4 +95,8 @@ export default defineComponent({ .outer { margin-top: 15px; } + +.progress-bar { + margin-top: 10px; +} diff --git a/src/components/modal/AlbumCollaborators.vue b/src/components/modal/AlbumCollaborators.vue index e9c26ad0..1023d98c 100644 --- a/src/components/modal/AlbumCollaborators.vue +++ b/src/components/modal/AlbumCollaborators.vue @@ -159,7 +159,7 @@ type Collaborator = { }; export default defineComponent({ - name: 'AddToAlbumModal', + name: 'AlbumCollaborators', components: { Magnify, Close, diff --git a/src/components/modal/AlbumPicker.vue b/src/components/modal/AlbumPicker.vue index 5f1bbbb3..170a3413 100644 --- a/src/components/modal/AlbumPicker.vue +++ b/src/components/modal/AlbumPicker.vue @@ -43,7 +43,8 @@
- + {{ t('memories', 'Save changes') }} @@ -107,6 +114,12 @@ export default defineComponent({ type: Array as PropType, required: true, }, + + /** Disable controls */ + disabled: { + type: Boolean, + default: false, + }, }, components: { AlbumForm, @@ -180,6 +193,8 @@ export default defineComponent({ }, toggleAlbumSelection(album: IAlbum) { + if (this.disabled) return; + if (this.selection.has(album)) { this.selection.delete(album);