aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/store
diff options
context:
space:
mode:
Diffstat (limited to 'viewer/src/store')
-rw-r--r--viewer/src/store/galleryStore.ts30
-rw-r--r--viewer/src/store/index.ts7
-rw-r--r--viewer/src/store/uiStore.ts34
3 files changed, 51 insertions, 20 deletions
diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts
index 5d599aa..e2adf18 100644
--- a/viewer/src/store/galleryStore.ts
+++ b/viewer/src/store/galleryStore.ts
@@ -17,9 +17,11 @@
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
20import { createModule, mutation, action } from "vuex-class-component"; 20import { Config, Index, Item } from "@/@types/gallery";
21import { TagCategory, TagIndex, TagSearch } from "@/@types/tag";
21import IndexFactory from "@/services/indexfactory"; 22import IndexFactory from "@/services/indexfactory";
22import Navigation from "@/services/navigation"; 23import Navigation from "@/services/navigation";
24import { action, createModule, mutation } from "vuex-class-component";
23 25
24const VuexModule = createModule({ 26const VuexModule = createModule({
25 namespaced: "galleryStore", 27 namespaced: "galleryStore",
@@ -27,28 +29,28 @@ const VuexModule = createModule({
27}); 29});
28 30
29export default class GalleryStore extends VuexModule { 31export default class GalleryStore extends VuexModule {
30 config: Gallery.Config | null = null; 32 config: Config | null = null;
31 galleryIndex: Gallery.Index | null = null; 33 galleryIndex: Index | null = null;
32 tagsIndex: Tag.Index = {}; 34 tagsIndex: TagIndex = {};
33 tagsCategories: Tag.Category[] = []; 35 tagsCategories: TagCategory[] = [];
34 currentPath: string | null = null; 36 currentPath: string | null = null;
35 currentSearch: Tag.Search[] = []; 37 currentSearch: TagSearch[] = [];
36 38
37 // --- 39 // ---
38 40
39 @mutation private setConfig(config: Gallery.Config) { 41 @mutation private setConfig(config: Config) {
40 this.config = config; 42 this.config = config;
41 } 43 }
42 44
43 @mutation setGalleryIndex(galleryIndex: Gallery.Index) { 45 @mutation setGalleryIndex(galleryIndex: Index) {
44 this.galleryIndex = Object.freeze(galleryIndex); 46 this.galleryIndex = Object.freeze(galleryIndex);
45 } 47 }
46 48
47 @mutation private setTagsIndex(tagsIndex: Tag.Index) { 49 @mutation private setTagsIndex(tagsIndex: TagIndex) {
48 this.tagsIndex = Object.freeze(tagsIndex); 50 this.tagsIndex = Object.freeze(tagsIndex);
49 } 51 }
50 52
51 @mutation private setTagsCategories(tagsCategories: Tag.Category[]) { 53 @mutation private setTagsCategories(tagsCategories: TagCategory[]) {
52 this.tagsCategories = tagsCategories; 54 this.tagsCategories = tagsCategories;
53 } 55 }
54 56
@@ -56,19 +58,19 @@ export default class GalleryStore extends VuexModule {
56 this.currentPath = currentPath; 58 this.currentPath = currentPath;
57 } 59 }
58 60
59 @mutation setCurrentSearch(currentSearch: Tag.Search[]) { 61 @mutation setCurrentSearch(currentSearch: TagSearch[]) {
60 this.currentSearch = currentSearch; 62 this.currentSearch = currentSearch;
61 } 63 }
62 64
63 // --- 65 // ---
64 66
65 get currentItemPath(): Gallery.Item[] { 67 get currentItemPath(): Item[] {
66 const root = this.galleryIndex?.tree; 68 const root = this.galleryIndex?.tree;
67 if (root && this.currentPath) return Navigation.searchCurrentItemPath(root, this.currentPath); 69 if (root && this.currentPath) return Navigation.searchCurrentItemPath(root, this.currentPath);
68 return []; 70 return [];
69 } 71 }
70 72
71 get currentItem(): Gallery.Item | null { 73 get currentItem(): Item | null {
72 const path = this.currentItemPath; 74 const path = this.currentItemPath;
73 return path.length > 0 ? path[path.length - 1] : null; 75 return path.length > 0 ? path[path.length - 1] : null;
74 } 76 }
@@ -126,7 +128,7 @@ export default class GalleryStore extends VuexModule {
126 } 128 }
127 129
128 private static getUrlConfig() { 130 private static getUrlConfig() {
129 let search = window.location.search; 131 const search = window.location.search;
130 if (search.length > 1) return search.substr(1) + ".json"; 132 if (search.length > 1) return search.substr(1) + ".json";
131 return "config.json"; 133 return "config.json";
132 } 134 }
diff --git a/viewer/src/store/index.ts b/viewer/src/store/index.ts
index f86d66b..1f49589 100644
--- a/viewer/src/store/index.ts
+++ b/viewer/src/store/index.ts
@@ -17,12 +17,11 @@
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
20import GalleryStore from "@/store/galleryStore";
21import UIStore from "@/store/uiStore";
20import Vue from "vue"; 22import Vue from "vue";
21import Vuex from "vuex"; 23import Vuex from "vuex";
22import { extractVuexModule } from "vuex-class-component"; 24import { createProxy, extractVuexModule } from "vuex-class-component";
23import { createProxy } from "vuex-class-component";
24import UIStore from "@/store/uiStore";
25import GalleryStore from "@/store/galleryStore";
26 25
27Vue.use(Vuex); 26Vue.use(Vuex);
28 27
diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts
index f065cdd..520fcf4 100644
--- a/viewer/src/store/uiStore.ts
+++ b/viewer/src/store/uiStore.ts
@@ -17,20 +17,27 @@
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
20import { createModule, mutation, action } from "vuex-class-component"; 20import { Config } from "@/@types/gallery";
21import { SplashScreenConfig } from "@/@types/splashscreen";
21import ItemComparators, { ItemSort } from "@/services/itemComparators"; 22import ItemComparators, { ItemSort } from "@/services/itemComparators";
23import { action, createModule, mutation } from "vuex-class-component";
22 24
23const VuexModule = createModule({ 25const VuexModule = createModule({
24 namespaced: "uiStore", 26 namespaced: "uiStore",
25 strict: true, 27 strict: true,
26}); 28});
27 29
30const STORAGE_SPLASHSCREEN_ACKNOWLEDGMENT = "splashScreenAcknowledgment";
31
28export default class UIStore extends VuexModule { 32export default class UIStore extends VuexModule {
29 fullscreen: boolean = false; 33 fullscreen: boolean = false;
30 fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT); 34 fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT);
31 searchMode: boolean = false; 35 searchMode: boolean = false;
32 sort: ItemSort = ItemComparators.DEFAULT; 36 sort: ItemSort = ItemComparators.DEFAULT;
33 37
38 splashScreenConfig: SplashScreenConfig | null = null;
39 splashScreenEnabled: boolean = false;
40
34 // --- 41 // ---
35 42
36 @mutation toggleFullscreen(value?: boolean) { 43 @mutation toggleFullscreen(value?: boolean) {
@@ -49,11 +56,34 @@ export default class UIStore extends VuexModule {
49 this.sort = sort; 56 this.sort = sort;
50 } 57 }
51 58
52 @action async initFromConfig(config: Gallery.Config) { 59 @mutation setSplashScreenConfig(splashScreenConfig: SplashScreenConfig) {
60 this.splashScreenConfig = splashScreenConfig;
61 }
62
63 @mutation setSplashScreenEnabled(enabled: boolean) {
64 this.splashScreenEnabled = enabled;
65 }
66
67 // ---
68
69 @action async initFromConfig(config: Config) {
53 if (config.initialItemSort) { 70 if (config.initialItemSort) {
54 const itemSort = ItemComparators.ITEM_SORTS[config.initialItemSort]; 71 const itemSort = ItemComparators.ITEM_SORTS[config.initialItemSort];
55 if (itemSort) this.setSort(itemSort); 72 if (itemSort) this.setSort(itemSort);
56 else throw new Error("Unknown sort type: " + config.initialItemSort); 73 else throw new Error("Unknown sort type: " + config.initialItemSort);
57 } 74 }
75 if (config.splashScreen) {
76 this.setSplashScreenConfig(config.splashScreen);
77 const uid = config.splashScreen.acknowledgmentKey;
78 this.setSplashScreenEnabled(!uid || localStorage.getItem(STORAGE_SPLASHSCREEN_ACKNOWLEDGMENT) !== uid);
79 }
80 }
81
82 // ---
83
84 @action async validateSpashScreen() {
85 this.setSplashScreenEnabled(false);
86 const uid = this.splashScreenConfig?.acknowledgmentKey;
87 if (uid) localStorage.setItem(STORAGE_SPLASHSCREEN_ACKNOWLEDGMENT, String(uid));
58 } 88 }
59} 89}