diff options
Diffstat (limited to 'viewer/src/store/uiStore.ts')
-rw-r--r-- | viewer/src/store/uiStore.ts | 34 |
1 files changed, 32 insertions, 2 deletions
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 | ||
20 | import { createModule, mutation, action } from "vuex-class-component"; | 20 | import { Config } from "@/@types/gallery"; |
21 | import { SplashScreenConfig } from "@/@types/splashscreen"; | ||
21 | import ItemComparators, { ItemSort } from "@/services/itemComparators"; | 22 | import ItemComparators, { ItemSort } from "@/services/itemComparators"; |
23 | import { action, createModule, mutation } from "vuex-class-component"; | ||
22 | 24 | ||
23 | const VuexModule = createModule({ | 25 | const VuexModule = createModule({ |
24 | namespaced: "uiStore", | 26 | namespaced: "uiStore", |
25 | strict: true, | 27 | strict: true, |
26 | }); | 28 | }); |
27 | 29 | ||
30 | const STORAGE_SPLASHSCREEN_ACKNOWLEDGMENT = "splashScreenAcknowledgment"; | ||
31 | |||
28 | export default class UIStore extends VuexModule { | 32 | export 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 | } |