From 8d889762872501eebd5edb5d7cacddfd4cd55ad4 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Fri, 28 Feb 2020 04:09:40 +0100 Subject: viewer: more minor architectural improvement --- viewer/src/services/indexfactory.ts | 14 ++++++++------ viewer/src/store/galleryStore.ts | 2 +- viewer/src/store/uiStore.ts | 14 +++++++++----- viewer/src/views/GalleryDirectory.vue | 2 +- viewer/src/views/GallerySearch.vue | 6 +++--- 5 files changed, 22 insertions(+), 16 deletions(-) (limited to 'viewer') diff --git a/viewer/src/services/indexfactory.ts b/viewer/src/services/indexfactory.ts index 45abcd5..a31f3ef 100644 --- a/viewer/src/services/indexfactory.ts +++ b/viewer/src/services/indexfactory.ts @@ -93,12 +93,10 @@ export default class IndexFactory { category = Navigation.normalize(category); disambiguation = Navigation.normalize(disambiguation); return Object.values(tagsIndex) - .filter(node => strict || node.tagfiltered.includes(category)) - .filter(node => !strict || node.tagfiltered === category) + .filter(node => IndexFactory.matches(node, category, strict)) .flatMap(node => Object.values(node.children) - .filter(child => strict || child.tagfiltered.includes(disambiguation)) - .filter(child => !strict || child.tagfiltered === disambiguation) + .filter(child => IndexFactory.matches(child, disambiguation, strict)) .map(child => ({ ...child, parent: node, operation, display: `${operation}${node.tag}:${child.tag}` })) ); } @@ -106,8 +104,12 @@ export default class IndexFactory { private static searchTagsFromFilter(tagsIndex: Tag.Index, operation: Operation, filter: string, strict: boolean): Tag.Search[] { filter = Navigation.normalize(filter); return Object.values(tagsIndex) - .filter(node => strict || node.tagfiltered.includes(filter)) - .filter(node => !strict || node.tagfiltered === filter) + .filter(node => IndexFactory.matches(node, filter, strict)) .map(node => ({ ...node, operation, display: `${operation}${node.tag}` })); } + + private static matches(node: Tag.Node, filter: string, strict: boolean): boolean { + if (strict) return node.tagfiltered === filter; + return node.tagfiltered.includes(filter) + } } diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts index 9950f5b..bc43ed2 100644 --- a/viewer/src/store/galleryStore.ts +++ b/viewer/src/store/galleryStore.ts @@ -36,7 +36,7 @@ export default class GalleryStore extends VuexModule { // --- - @mutation setConfig(config: Gallery.Config) { + @mutation private setConfig(config: Gallery.Config) { this.config = config; } diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts index 1e63b3e..21f9ce9 100644 --- a/viewer/src/store/uiStore.ts +++ b/viewer/src/store/uiStore.ts @@ -21,7 +21,7 @@ import { createModule, mutation, action } from "vuex-class-component"; const VuexModule = createModule({ namespaced: "uiStore", - strict: false + strict: true }) export default class UIStore extends VuexModule { @@ -32,11 +32,15 @@ export default class UIStore extends VuexModule { // --- - @mutation toggleFullscreen() { - this.fullscreen = !this.fullscreen; + @mutation toggleFullscreen(value?: boolean) { + this.fullscreen = value ?? !this.fullscreen; } - @mutation toggleFullWidth() { - this.fullWidth = !this.fullWidth; + @mutation toggleFullWidth(value?: boolean) { + this.fullWidth = value ?? !this.fullWidth; + } + + @mutation toggleSearchMode(value?: boolean) { + this.searchMode = value ?? !this.searchMode; } } diff --git a/viewer/src/views/GalleryDirectory.vue b/viewer/src/views/GalleryDirectory.vue index 6e68578..30f651c 100644 --- a/viewer/src/views/GalleryDirectory.vue +++ b/viewer/src/views/GalleryDirectory.vue @@ -30,7 +30,7 @@ export default class GalleryDirectory extends Vue { @Prop({ required: true }) readonly directory!: Gallery.Directory; mounted() { - this.$uiStore.fullscreen = false; + this.$uiStore.toggleFullscreen(false); } orderedItems() { diff --git a/viewer/src/views/GallerySearch.vue b/viewer/src/views/GallerySearch.vue index d638df2..e3369b3 100644 --- a/viewer/src/views/GallerySearch.vue +++ b/viewer/src/views/GallerySearch.vue @@ -33,12 +33,12 @@ export default class GalleryPicture extends Vue { otherCount: Number = 0; mounted() { - this.$uiStore.fullscreen = false; - this.$uiStore.searchMode = true; + this.$uiStore.toggleFullscreen(false); + this.$uiStore.toggleSearchMode(true); } destroyed() { - this.$uiStore.searchMode = false; + this.$uiStore.toggleSearchMode(false); } items() { -- cgit v1.2.3