aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/views/Gallery.vue
diff options
context:
space:
mode:
Diffstat (limited to 'viewer/src/views/Gallery.vue')
-rw-r--r--viewer/src/views/Gallery.vue31
1 files changed, 16 insertions, 15 deletions
diff --git a/viewer/src/views/Gallery.vue b/viewer/src/views/Gallery.vue
index 2020280..38199b9 100644
--- a/viewer/src/views/Gallery.vue
+++ b/viewer/src/views/Gallery.vue
@@ -1,17 +1,20 @@
1<template> 1<template>
2 <div> 2 <div>
3 <gallery-directory v-if="isDirectory" :directory="currentItem" /> 3 <gallery-search v-if="$uiStore.isModeSearch" :items="currentSearch" />
4 <gallery-image v-if="isImage" :image="currentItem" /> 4 <gallery-directory v-else-if="isDirectory" :directory="currentItem" />
5 <gallery-image v-else-if="isImage" :image="currentItem" />
5 </div> 6 </div>
6</template> 7</template>
7 8
8<script lang="ts"> 9<script lang="ts">
9import { Component, Vue, Prop } from "vue-property-decorator"; 10import { Component, Vue, Prop } from "vue-property-decorator";
11import GallerySearch from "./GallerySearch.vue";
10import GalleryDirectory from "./GalleryDirectory.vue"; 12import GalleryDirectory from "./GalleryDirectory.vue";
11import GalleryImage from "./GalleryImage.vue"; 13import GalleryImage from "./GalleryImage.vue";
14import GalleryStore from "../store/galleryStore";
12 15
13@Component({ 16@Component({
14 components: { GalleryDirectory, GalleryImage }, 17 components: { GallerySearch, GalleryDirectory, GalleryImage },
15}) 18})
16export default class Gallery extends Vue { 19export default class Gallery extends Vue {
17 @Prop(String) readonly pathMatch!: string; 20 @Prop(String) readonly pathMatch!: string;
@@ -24,25 +27,23 @@ export default class Gallery extends Vue {
24 return this.checkType("image"); 27 return this.checkType("image");
25 } 28 }
26 29
30 // Results of the search (by tags)
31 get currentSearch(): Gallery.Item[] {
32 const currentTags = this.$uiStore.currentTags;
33 let items = new Set<Gallery.Item>();
34 currentTags.flatMap(tag => tag.items).forEach(item => items.add(item));
35 return [...items];
36 }
37
38 // Item pointed by the URL (navigation)
27 get currentItem(): Gallery.Item | null { 39 get currentItem(): Gallery.Item | null {
28 const galleryItemsRoot = this.$galleryStore.galleryItemsRoot; 40 const galleryItemsRoot = this.$galleryStore.galleryItemsRoot;
29 if (galleryItemsRoot) return this.searchCurrentItem(galleryItemsRoot, this.pathMatch); 41 if (galleryItemsRoot) return GalleryStore.searchCurrentItem(galleryItemsRoot, this.pathMatch);
30 return null; 42 return null;
31 } 43 }
32 44
33 // --- 45 // ---
34 46
35 private searchCurrentItem(item: Gallery.Item, currentPath: string): Gallery.Item | null {
36 if (currentPath === item.path) return item;
37 if (item.properties.type === "directory" && currentPath.startsWith(item.path)) {
38 const itemFound = item.properties.items
39 .map(item => this.searchCurrentItem(item, currentPath))
40 .find(item => Boolean(item));
41 return itemFound || null;
42 }
43 return null;
44 }
45
46 private checkType(type: string): boolean { 47 private checkType(type: string): boolean {
47 return (this.currentItem && this.currentItem.properties.type === type) || false; 48 return (this.currentItem && this.currentItem.properties.type === type) || false;
48 } 49 }