albums: auto select new album in picker (fix #770)

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/783/head
Varun Patil 2023-08-19 11:19:00 -07:00
parent 178e46fba6
commit d04697ae63
1 changed files with 26 additions and 5 deletions

View File

@ -119,15 +119,26 @@ export default defineComponent({
}, },
methods: { methods: {
albumCreatedHandler() { async albumCreatedHandler({ album }: { album: { basename: string } }) {
this.showAlbumCreationForm = false; this.showAlbumCreationForm = false;
this.loadAlbums(); await this.loadAlbums(true);
// select the newly created album
const newAlbum = this.albums.find((a) => a.name === album.basename);
if (newAlbum) {
this.selection.add(newAlbum);
this.forceUpdate();
}
}, },
async loadAlbums() { async loadAlbums(preserveSelection: boolean = false) {
try { try {
this.loadingAlbums = true; this.loadingAlbums = true;
// FIXME: preserve deselection too; but then this is only
// applicable for single photo selection ... at least for now
const prevSel = new Set(Array.from(this.selection).map((a) => a.album_id));
// get all albums // get all albums
this.albums = await dav.getAlbums(); this.albums = await dav.getAlbums();
@ -143,10 +154,16 @@ export default defineComponent({
this.initSelection = new Set(this.albums.filter((a) => selIds.has(a.album_id))); this.initSelection = new Set(this.albums.filter((a) => selIds.has(a.album_id)));
this.selection = new Set(this.initSelection); this.selection = new Set(this.initSelection);
} }
// restore selection
if (preserveSelection) {
this.albums.filter((a) => prevSel.has(a.album_id)).forEach(this.selection.add, this.selection);
}
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} finally { } finally {
this.loadingAlbums = false; this.loadingAlbums = false;
this.forceUpdate();
} }
}, },
@ -165,13 +182,17 @@ export default defineComponent({
this.deselection.delete(album); this.deselection.delete(album);
} }
this.$forceUpdate(); // sets do not trigger reactivity this.forceUpdate();
(<any>this.$refs.albumsList)?.$forceUpdate();
}, },
submit() { submit() {
this.$emit('select', Array.from(this.selection), Array.from(this.deselection)); this.$emit('select', Array.from(this.selection), Array.from(this.deselection));
}, },
forceUpdate() {
this.$forceUpdate(); // sets do not trigger reactivity
(<any>this.$refs.albumsList)?.$forceUpdate();
},
}, },
}); });
</script> </script>