aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/store/galleryStore.ts
diff options
context:
space:
mode:
Diffstat (limited to 'viewer/src/store/galleryStore.ts')
-rw-r--r--viewer/src/store/galleryStore.ts23
1 files changed, 15 insertions, 8 deletions
diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts
index cd09996..84673b5 100644
--- a/viewer/src/store/galleryStore.ts
+++ b/viewer/src/store/galleryStore.ts
@@ -29,9 +29,10 @@ const VuexModule = createModule({
29export default class GalleryStore extends VuexModule { 29export default class GalleryStore extends VuexModule {
30 30
31 config: Gallery.Config | null = null; 31 config: Gallery.Config | null = null;
32 galleryItemsRoot: Gallery.Item | null = null; 32 galleryIndex: Gallery.Index | null = null;
33 tagsIndex: Tag.Index = {}; 33 tagsIndex: Tag.Index = {};
34 currentPath: string = "/"; 34 currentPath: string = "/";
35 currentSearch: Tag.Search[] = [];
35 36
36 // --- 37 // ---
37 38
@@ -39,20 +40,26 @@ export default class GalleryStore extends VuexModule {
39 this.config = config; 40 this.config = config;
40 } 41 }
41 42
42 @mutation setGalleryItemsRoot(galleryItemsRoot: Gallery.Item) { 43 @mutation setGalleryIndex(galleryIndex: Gallery.Index) {
43 this.galleryItemsRoot = galleryItemsRoot; 44 this.galleryIndex = Object.freeze(galleryIndex);
44 } 45 }
45 46
46 @mutation private setTagsIndex(tagsIndex: Tag.Index) { 47 @mutation private setTagsIndex(tagsIndex: Tag.Index) {
47 this.tagsIndex = tagsIndex; 48 this.tagsIndex = Object.freeze(tagsIndex);
48 } 49 }
49 50
50 @mutation setCurrentPath(currentPath: string) { 51 @mutation setCurrentPath(currentPath: string) {
51 this.currentPath = currentPath; 52 this.currentPath = currentPath;
52 } 53 }
53 54
55 @mutation setCurrentSearch(currentSearch: Tag.Search[]) {
56 this.currentSearch = currentSearch;
57 }
58
59 // ---
60
54 get currentItemPath(): Gallery.Item[] { 61 get currentItemPath(): Gallery.Item[] {
55 const root = this.galleryItemsRoot; 62 const root = this.galleryIndex?.tree;
56 if (root) 63 if (root)
57 return Navigation.searchCurrentItemPath(root, this.currentPath); 64 return Navigation.searchCurrentItemPath(root, this.currentPath);
58 return []; 65 return [];
@@ -77,14 +84,14 @@ export default class GalleryStore extends VuexModule {
77 const root = this.config?.galleryRoot ?? ''; 84 const root = this.config?.galleryRoot ?? '';
78 return fetch(`${process.env.VUE_APP_DATA_URL}${root}index.json`, { cache: "no-cache" }) 85 return fetch(`${process.env.VUE_APP_DATA_URL}${root}index.json`, { cache: "no-cache" })
79 .then(response => response.json()) 86 .then(response => response.json())
80 .then(index => index.tree) 87 .then(this.setGalleryIndex)
81 .then(this.setGalleryItemsRoot)
82 .then(this.indexTags); 88 .then(this.indexTags);
83 } 89 }
84 90
85 // Indexes the gallery 91 // Indexes the gallery
86 @action async indexTags() { 92 @action async indexTags() {
87 this.setTagsIndex(IndexFactory.generateTags(this.galleryItemsRoot)); 93 const root = this.galleryIndex?.tree ?? null;
94 this.setTagsIndex(IndexFactory.generateTags(root));
88 } 95 }
89 96
90} 97}