diff options
Diffstat (limited to 'viewer/src/store')
-rw-r--r-- | viewer/src/store/galleryStore.ts | 36 | ||||
-rw-r--r-- | viewer/src/store/index.ts | 16 | ||||
-rw-r--r-- | viewer/src/store/uiStore.ts | 19 |
3 files changed, 50 insertions, 21 deletions
diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts index 0cffdd9..5d599aa 100644 --- a/viewer/src/store/galleryStore.ts +++ b/viewer/src/store/galleryStore.ts | |||
@@ -23,16 +23,15 @@ import Navigation from "@/services/navigation"; | |||
23 | 23 | ||
24 | const VuexModule = createModule({ | 24 | const VuexModule = createModule({ |
25 | namespaced: "galleryStore", | 25 | namespaced: "galleryStore", |
26 | strict: true | 26 | strict: true, |
27 | }) | 27 | }); |
28 | 28 | ||
29 | export default class GalleryStore extends VuexModule { | 29 | export default class GalleryStore extends VuexModule { |
30 | |||
31 | config: Gallery.Config | null = null; | 30 | config: Gallery.Config | null = null; |
32 | galleryIndex: Gallery.Index | null = null; | 31 | galleryIndex: Gallery.Index | null = null; |
33 | tagsIndex: Tag.Index = {}; | 32 | tagsIndex: Tag.Index = {}; |
34 | tagsCategories: Tag.Category[] = []; | 33 | tagsCategories: Tag.Category[] = []; |
35 | currentPath: string = "/"; | 34 | currentPath: string | null = null; |
36 | currentSearch: Tag.Search[] = []; | 35 | currentSearch: Tag.Search[] = []; |
37 | 36 | ||
38 | // --- | 37 | // --- |
@@ -65,8 +64,7 @@ export default class GalleryStore extends VuexModule { | |||
65 | 64 | ||
66 | get currentItemPath(): Gallery.Item[] { | 65 | get currentItemPath(): Gallery.Item[] { |
67 | const root = this.galleryIndex?.tree; | 66 | const root = this.galleryIndex?.tree; |
68 | if (root) | 67 | if (root && this.currentPath) return Navigation.searchCurrentItemPath(root, this.currentPath); |
69 | return Navigation.searchCurrentItemPath(root, this.currentPath); | ||
70 | return []; | 68 | return []; |
71 | } | 69 | } |
72 | 70 | ||
@@ -79,23 +77,30 @@ export default class GalleryStore extends VuexModule { | |||
79 | return this.galleryIndex?.properties.galleryTitle ?? "ldgallery"; | 77 | return this.galleryIndex?.properties.galleryTitle ?? "ldgallery"; |
80 | } | 78 | } |
81 | 79 | ||
80 | get resourceRoot(): string { | ||
81 | return process.env.VUE_APP_DATA_URL + this.config!.galleryRoot; | ||
82 | } | ||
83 | |||
82 | // --- | 84 | // --- |
83 | 85 | ||
84 | // Fetches the gallery's JSON config | 86 | // Fetches the gallery's JSON config |
85 | @action async fetchConfig() { | 87 | @action async fetchConfig() { |
86 | return fetch(`${process.env.VUE_APP_DATA_URL}config.json`, { cache: "no-cache" }) | 88 | await fetch(`${process.env.VUE_APP_DATA_URL}${GalleryStore.getUrlConfig()}`, { cache: "no-cache" }) |
87 | .then(response => response.json()) | 89 | .then(GalleryStore.responseToJson) |
88 | .then(this.setConfig); | 90 | .then(this.setConfig); |
91 | return this.config!; | ||
89 | } | 92 | } |
90 | 93 | ||
91 | // Fetches the gallery's JSON metadata | 94 | // Fetches the gallery's JSON metadata |
92 | @action async fetchGalleryItems() { | 95 | @action async fetchGalleryItems() { |
93 | const root = this.config?.galleryRoot ?? ""; | 96 | const root = this.config?.galleryRoot ?? ""; |
94 | return fetch(`${process.env.VUE_APP_DATA_URL}${root}index.json`, { cache: "no-cache" }) | 97 | const index = this.config?.galleryIndex ?? "index.json"; |
95 | .then(response => response.json()) | 98 | await fetch(`${process.env.VUE_APP_DATA_URL}${root}${index}`, { cache: "no-cache" }) |
99 | .then(GalleryStore.responseToJson) | ||
96 | .then(this.setGalleryIndex) | 100 | .then(this.setGalleryIndex) |
97 | .then(this.indexTags) | 101 | .then(this.indexTags) |
98 | .then(this.indexTagCategories); | 102 | .then(this.indexTagCategories); |
103 | return this.galleryIndex!; | ||
99 | } | 104 | } |
100 | 105 | ||
101 | // Indexes the gallery | 106 | // Indexes the gallery |
@@ -119,4 +124,15 @@ export default class GalleryStore extends VuexModule { | |||
119 | this.setCurrentSearch(results); | 124 | this.setCurrentSearch(results); |
120 | return results; | 125 | return results; |
121 | } | 126 | } |
127 | |||
128 | private static getUrlConfig() { | ||
129 | let search = window.location.search; | ||
130 | if (search.length > 1) return search.substr(1) + ".json"; | ||
131 | return "config.json"; | ||
132 | } | ||
133 | |||
134 | private static responseToJson(response: Response) { | ||
135 | if (!response.ok) throw new Error(`${response.status}: ${response.statusText}`); | ||
136 | return response.json(); | ||
137 | } | ||
122 | } | 138 | } |
diff --git a/viewer/src/store/index.ts b/viewer/src/store/index.ts index d5339e8..f86d66b 100644 --- a/viewer/src/store/index.ts +++ b/viewer/src/store/index.ts | |||
@@ -17,30 +17,30 @@ | |||
17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. | 17 | -- along with this program. If not, see <https://www.gnu.org/licenses/>. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | import Vue from "vue" | 20 | import Vue from "vue"; |
21 | import Vuex from "vuex" | 21 | import Vuex from "vuex"; |
22 | import { extractVuexModule } from "vuex-class-component"; | 22 | import { extractVuexModule } from "vuex-class-component"; |
23 | import { createProxy } from "vuex-class-component"; | 23 | import { createProxy } from "vuex-class-component"; |
24 | import UIStore from "@/store/uiStore"; | 24 | import UIStore from "@/store/uiStore"; |
25 | import GalleryStore from "@/store/galleryStore"; | 25 | import GalleryStore from "@/store/galleryStore"; |
26 | 26 | ||
27 | Vue.use(Vuex) | 27 | Vue.use(Vuex); |
28 | 28 | ||
29 | const store = new Vuex.Store({ | 29 | const store = new Vuex.Store({ |
30 | modules: { | 30 | modules: { |
31 | ...extractVuexModule(UIStore), | 31 | ...extractVuexModule(UIStore), |
32 | ...extractVuexModule(GalleryStore) | 32 | ...extractVuexModule(GalleryStore), |
33 | }, | 33 | }, |
34 | strict: process.env.NODE_ENV !== "production", | 34 | strict: process.env.NODE_ENV !== "production", |
35 | }); | 35 | }); |
36 | 36 | ||
37 | Vue.use((vue) => vue.prototype.$uiStore = createProxy(store, UIStore)); | 37 | Vue.use(vue => (vue.prototype.$uiStore = createProxy(store, UIStore))); |
38 | Vue.use((vue) => vue.prototype.$galleryStore = createProxy(store, GalleryStore)); | 38 | Vue.use(vue => (vue.prototype.$galleryStore = createProxy(store, GalleryStore))); |
39 | 39 | ||
40 | declare module "vue/types/vue" { | 40 | declare module "vue/types/vue" { |
41 | interface Vue { | 41 | interface Vue { |
42 | $uiStore: UIStore, | 42 | $uiStore: UIStore; |
43 | $galleryStore: GalleryStore | 43 | $galleryStore: GalleryStore; |
44 | } | 44 | } |
45 | } | 45 | } |
46 | 46 | ||
diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts index 892d35e..f065cdd 100644 --- a/viewer/src/store/uiStore.ts +++ b/viewer/src/store/uiStore.ts | |||
@@ -18,17 +18,18 @@ | |||
18 | */ | 18 | */ |
19 | 19 | ||
20 | import { createModule, mutation, action } from "vuex-class-component"; | 20 | import { createModule, mutation, action } from "vuex-class-component"; |
21 | import ItemComparators, { ItemSort } from "@/services/itemComparators"; | ||
21 | 22 | ||
22 | const VuexModule = createModule({ | 23 | const VuexModule = createModule({ |
23 | namespaced: "uiStore", | 24 | namespaced: "uiStore", |
24 | strict: true | 25 | strict: true, |
25 | }) | 26 | }); |
26 | 27 | ||
27 | export default class UIStore extends VuexModule { | 28 | export default class UIStore extends VuexModule { |
28 | |||
29 | fullscreen: boolean = false; | 29 | fullscreen: boolean = false; |
30 | fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT); | 30 | fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT); |
31 | searchMode: boolean = false; | 31 | searchMode: boolean = false; |
32 | sort: ItemSort = ItemComparators.DEFAULT; | ||
32 | 33 | ||
33 | // --- | 34 | // --- |
34 | 35 | ||
@@ -43,4 +44,16 @@ export default class UIStore extends VuexModule { | |||
43 | @mutation toggleSearchMode(value?: boolean) { | 44 | @mutation toggleSearchMode(value?: boolean) { |
44 | this.searchMode = value ?? !this.searchMode; | 45 | this.searchMode = value ?? !this.searchMode; |
45 | } | 46 | } |
47 | |||
48 | @mutation setSort(sort: ItemSort) { | ||
49 | this.sort = sort; | ||
50 | } | ||
51 | |||
52 | @action async initFromConfig(config: Gallery.Config) { | ||
53 | if (config.initialItemSort) { | ||
54 | const itemSort = ItemComparators.ITEM_SORTS[config.initialItemSort]; | ||
55 | if (itemSort) this.setSort(itemSort); | ||
56 | else throw new Error("Unknown sort type: " + config.initialItemSort); | ||
57 | } | ||
58 | } | ||
46 | } | 59 | } |