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.ts190
1 files changed, 95 insertions, 95 deletions
diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts
index 352a266..0cffdd9 100644
--- a/viewer/src/store/galleryStore.ts
+++ b/viewer/src/store/galleryStore.ts
@@ -18,105 +18,105 @@
18*/ 18*/
19 19
20import { createModule, mutation, action } from "vuex-class-component"; 20import { createModule, mutation, action } from "vuex-class-component";
21import IndexFactory from '@/services/indexfactory'; 21import IndexFactory from "@/services/indexfactory";
22import Navigation from '@/services/navigation'; 22import Navigation from "@/services/navigation";
23 23
24const VuexModule = createModule({ 24const VuexModule = createModule({
25 namespaced: "galleryStore", 25 namespaced: "galleryStore",
26 strict: true 26 strict: true
27}) 27})
28 28
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 galleryIndex: Gallery.Index | null = null; 32 galleryIndex: Gallery.Index | null = null;
33 tagsIndex: Tag.Index = {}; 33 tagsIndex: Tag.Index = {};
34 tagsCategories: Tag.Category[] = []; 34 tagsCategories: Tag.Category[] = [];
35 currentPath: string = "/"; 35 currentPath: string = "/";
36 currentSearch: Tag.Search[] = []; 36 currentSearch: Tag.Search[] = [];
37 37
38 // --- 38 // ---
39 39
40 @mutation private setConfig(config: Gallery.Config) { 40 @mutation private setConfig(config: Gallery.Config) {
41 this.config = config; 41 this.config = config;
42 } 42 }
43 43
44 @mutation setGalleryIndex(galleryIndex: Gallery.Index) { 44 @mutation setGalleryIndex(galleryIndex: Gallery.Index) {
45 this.galleryIndex = Object.freeze(galleryIndex); 45 this.galleryIndex = Object.freeze(galleryIndex);
46 } 46 }
47 47
48 @mutation private setTagsIndex(tagsIndex: Tag.Index) { 48 @mutation private setTagsIndex(tagsIndex: Tag.Index) {
49 this.tagsIndex = Object.freeze(tagsIndex); 49 this.tagsIndex = Object.freeze(tagsIndex);
50 } 50 }
51 51
52 @mutation private setTagsCategories(tagsCategories: Tag.Category[]) { 52 @mutation private setTagsCategories(tagsCategories: Tag.Category[]) {
53 this.tagsCategories = tagsCategories; 53 this.tagsCategories = tagsCategories;
54 } 54 }
55 55
56 @mutation setCurrentPath(currentPath: string) { 56 @mutation setCurrentPath(currentPath: string) {
57 this.currentPath = currentPath; 57 this.currentPath = currentPath;
58 } 58 }
59 59
60 @mutation setCurrentSearch(currentSearch: Tag.Search[]) { 60 @mutation setCurrentSearch(currentSearch: Tag.Search[]) {
61 this.currentSearch = currentSearch; 61 this.currentSearch = currentSearch;
62 } 62 }
63 63
64 // --- 64 // ---
65 65
66 get currentItemPath(): Gallery.Item[] { 66 get currentItemPath(): Gallery.Item[] {
67 const root = this.galleryIndex?.tree; 67 const root = this.galleryIndex?.tree;
68 if (root) 68 if (root)
69 return Navigation.searchCurrentItemPath(root, this.currentPath); 69 return Navigation.searchCurrentItemPath(root, this.currentPath);
70 return []; 70 return [];
71 } 71 }
72 72
73 get currentItem(): Gallery.Item | null { 73 get currentItem(): Gallery.Item | null {
74 const path = this.currentItemPath; 74 const path = this.currentItemPath;
75 return path.length > 0 ? path[path.length - 1] : null; 75 return path.length > 0 ? path[path.length - 1] : null;
76 } 76 }
77 77
78 get galleryTitle(): string { 78 get galleryTitle(): string {
79 return this.galleryIndex?.properties.galleryTitle ?? "ldgallery"; 79 return this.galleryIndex?.properties.galleryTitle ?? "ldgallery";
80 } 80 }
81 81
82 // --- 82 // ---
83 83
84 // Fetches the gallery's JSON config 84 // Fetches the gallery's JSON config
85 @action async fetchConfig() { 85 @action async fetchConfig() {
86 return fetch(`${process.env.VUE_APP_DATA_URL}config.json`, { cache: "no-cache" }) 86 return fetch(`${process.env.VUE_APP_DATA_URL}config.json`, { cache: "no-cache" })
87 .then(response => response.json()) 87 .then(response => response.json())
88 .then(this.setConfig); 88 .then(this.setConfig);
89 } 89 }
90 90
91 // Fetches the gallery's JSON metadata 91 // Fetches the gallery's JSON metadata
92 @action async fetchGalleryItems() { 92 @action async fetchGalleryItems() {
93 const root = this.config?.galleryRoot ?? ''; 93 const root = this.config?.galleryRoot ?? "";
94 return fetch(`${process.env.VUE_APP_DATA_URL}${root}index.json`, { cache: "no-cache" }) 94 return fetch(`${process.env.VUE_APP_DATA_URL}${root}index.json`, { cache: "no-cache" })
95 .then(response => response.json()) 95 .then(response => response.json())
96 .then(this.setGalleryIndex) 96 .then(this.setGalleryIndex)
97 .then(this.indexTags) 97 .then(this.indexTags)
98 .then(this.indexTagCategories); 98 .then(this.indexTagCategories);
99 } 99 }
100 100
101 // Indexes the gallery 101 // Indexes the gallery
102 @action async indexTags() { 102 @action async indexTags() {
103 const root = this.galleryIndex?.tree ?? null; 103 const root = this.galleryIndex?.tree ?? null;
104 const index = IndexFactory.generateTags(root); 104 const index = IndexFactory.generateTags(root);
105 this.setTagsIndex(index); 105 this.setTagsIndex(index);
106 return index; 106 return index;
107 } 107 }
108 108
109 // Indexes the proposed categories 109 // Indexes the proposed categories
110 @action async indexTagCategories() { 110 @action async indexTagCategories() {
111 const categories = IndexFactory.generateCategories(this.tagsIndex, this.galleryIndex?.properties.tagCategories); 111 const categories = IndexFactory.generateCategories(this.tagsIndex, this.galleryIndex?.properties.tagCategories);
112 this.setTagsCategories(categories); 112 this.setTagsCategories(categories);
113 return categories; 113 return categories;
114 } 114 }
115 115
116 // Searches for tags 116 // Searches for tags
117 @action async search(filters: string[]) { 117 @action async search(filters: string[]) {
118 const results = filters.flatMap(filter => IndexFactory.searchTags(this.tagsIndex, filter, true)); 118 const results = filters.flatMap(filter => IndexFactory.searchTags(this.tagsIndex, filter, true));
119 this.setCurrentSearch(results); 119 this.setCurrentSearch(results);
120 return results; 120 return results;
121 } 121 }
122} 122}