From 1a4744de3cfe74524cd0415416fa9da0a322e86c Mon Sep 17 00:00:00 2001 From: Zephyrrus Date: Wed, 22 Jul 2020 02:12:24 +0300 Subject: feat: show selected albums first when modal is first opened fix: change the color of the dropdown for tags to match the base theme chore: pass props into some of the components instead of fetching from store inside of components --- src/site/components/image-modal/AlbumInfo.vue | 33 +++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) (limited to 'src/site/components/image-modal/AlbumInfo.vue') diff --git a/src/site/components/image-modal/AlbumInfo.vue b/src/site/components/image-modal/AlbumInfo.vue index 9d57e55..8974a11 100644 --- a/src/site/components/image-modal/AlbumInfo.vue +++ b/src/site/components/image-modal/AlbumInfo.vue @@ -13,12 +13,12 @@ - {{ album. name }} + {{ album.name }} @@ -37,18 +37,37 @@ export default { type: Array, default: () => [], }, + albums: { + type: Array, + default: () => [], + }, }, data() { return { - selectedOptions: this.imageAlbums.map((e) => e.id), + selectedOptions: [], + orderedAlbums: [], }; }, - computed: { - ...mapState({ - albums: (state) => state.albums.tinyDetails, - }), + created() { + this.orderedAlbums = this.getOrderedAlbums(); + // we're sorting here instead of computed because we want sort on creation + // then the array's values should be frozen + this.selectedOptions = this.imageAlbums.map((e) => e.id); }, methods: { + getOrderedAlbums() { + return [...this.albums].sort( + (a, b) => { + const selectedA = this.imageAlbums.findIndex(({ name }) => name === a.name) !== -1; + const selectedB = this.imageAlbums.findIndex(({ name }) => name === b.name) !== -1; + + if (selectedA !== selectedB) { + return selectedA ? -1 : 1; + } + return a.name.localeCompare(b.name); + }, + ); + }, isAlbumSelected(id) { if (!this.showingModalForFile) return false; const found = this.showingModalForFile.albums.find((el) => el.id === id); -- cgit v1.2.3