diff options
Diffstat (limited to 'viewer/src/store/uiStore.ts')
-rw-r--r-- | viewer/src/store/uiStore.ts | 82 |
1 files changed, 44 insertions, 38 deletions
diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts index f065cdd..df8dacc 100644 --- a/viewer/src/store/uiStore.ts +++ b/viewer/src/store/uiStore.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | /* ldgallery - A static generator which turns a collection of tagged | 1 | /* ldgallery - A static generator which turns a collection of tagged |
2 | -- pictures into a searchable web gallery. | 2 | -- pictures into a searchable web gallery. |
3 | -- | 3 | -- |
4 | -- Copyright (C) 2019-2020 Guillaume FOUET | 4 | -- Copyright (C) 2019-2022 Guillaume FOUET |
5 | -- | 5 | -- |
6 | -- This program is free software: you can redistribute it and/or modify | 6 | -- This program is free software: you can redistribute it and/or modify |
7 | -- it under the terms of the GNU Affero General Public License as | 7 | -- it under the terms of the GNU Affero General Public License as |
@@ -17,43 +17,49 @@ | |||
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 ItemComparators, { ItemSort } from "@/services/itemComparators"; | 21 | import { SplashScreenConfig } from '@/@types/splashscreen'; |
22 | import { ItemSort, useItemComparator } from '@/services/itemComparator'; | ||
23 | import { useLocalStorage } from '@vueuse/core'; | ||
24 | import { defineStore } from 'pinia'; | ||
22 | 25 | ||
23 | const VuexModule = createModule({ | 26 | const itemComparator = useItemComparator(); |
24 | namespaced: "uiStore", | 27 | const splashScreenAcknowledgment = useLocalStorage('splashScreenAcknowledgment', ''); |
25 | strict: true, | ||
26 | }); | ||
27 | |||
28 | export default class UIStore extends VuexModule { | ||
29 | fullscreen: boolean = false; | ||
30 | fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT); | ||
31 | searchMode: boolean = false; | ||
32 | sort: ItemSort = ItemComparators.DEFAULT; | ||
33 | |||
34 | // --- | ||
35 | |||
36 | @mutation toggleFullscreen(value?: boolean) { | ||
37 | this.fullscreen = value ?? !this.fullscreen; | ||
38 | } | ||
39 | 28 | ||
40 | @mutation toggleFullWidth(value?: boolean) { | 29 | export const useUiStore = defineStore('ui', { |
41 | this.fullWidth = value ?? !this.fullWidth; | 30 | state: () => ({ |
42 | } | 31 | fullscreen: false, |
32 | fullWidth: window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT), | ||
33 | searchMode: false, | ||
34 | sort: itemComparator.DEFAULT as ItemSort, | ||
43 | 35 | ||
44 | @mutation toggleSearchMode(value?: boolean) { | 36 | splashScreenConfig: null as SplashScreenConfig | null, |
45 | this.searchMode = value ?? !this.searchMode; | 37 | splashScreenEnabled: false, |
46 | } | 38 | }), |
47 | 39 | getters: { | |
48 | @mutation setSort(sort: ItemSort) { | 40 | }, |
49 | this.sort = sort; | 41 | actions: { |
50 | } | 42 | toggleFullscreen(value?: boolean) { |
51 | 43 | this.fullscreen = value ?? !this.fullscreen; | |
52 | @action async initFromConfig(config: Gallery.Config) { | 44 | }, |
53 | if (config.initialItemSort) { | 45 | toggleFullWidth(value?: boolean) { |
54 | const itemSort = ItemComparators.ITEM_SORTS[config.initialItemSort]; | 46 | this.fullWidth = value ?? !this.fullWidth; |
55 | if (itemSort) this.setSort(itemSort); | 47 | }, |
56 | else throw new Error("Unknown sort type: " + config.initialItemSort); | 48 | validateSpashScreen() { |
57 | } | 49 | this.splashScreenEnabled = false; |
58 | } | 50 | splashScreenAcknowledgment.value = this.splashScreenConfig?.acknowledgmentKey ?? ''; |
59 | } | 51 | }, |
52 | async initFromConfig(config: Config) { | ||
53 | if (config.initialItemSort) { | ||
54 | const itemSort = itemComparator.ITEM_SORTS.find(sort => sort.name === config.initialItemSort); | ||
55 | if (itemSort) this.sort = itemSort; | ||
56 | else throw new Error('Unknown sort type: ' + config.initialItemSort); | ||
57 | } | ||
58 | if (config.splashScreen) { | ||
59 | this.splashScreenConfig = config.splashScreen; | ||
60 | const uid = config.splashScreen.acknowledgmentKey; | ||
61 | this.splashScreenEnabled = !uid || splashScreenAcknowledgment.value !== uid; | ||
62 | } | ||
63 | }, | ||
64 | }, | ||
65 | }); | ||