diff options
Diffstat (limited to 'viewer/src/store')
-rw-r--r-- | viewer/src/store/uiStore.ts | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts index 2d583fc..04f14a0 100644 --- a/viewer/src/store/uiStore.ts +++ b/viewer/src/store/uiStore.ts | |||
@@ -18,20 +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 ItemSortFn from "@/services/itemSortFn"; | 21 | import ItemComparators, { ItemComparator } from "@/services/itemComparators"; |
22 | 22 | ||
23 | const VuexModule = createModule({ | 23 | const VuexModule = createModule({ |
24 | namespaced: "uiStore", | 24 | namespaced: "uiStore", |
25 | strict: true, | 25 | strict: true, |
26 | }); | 26 | }); |
27 | 27 | ||
28 | type TItemSortFn = (left: Gallery.Item, right: Gallery.Item) => number; | ||
29 | |||
30 | export default class UIStore extends VuexModule { | 28 | export default class UIStore extends VuexModule { |
31 | fullscreen: boolean = false; | 29 | fullscreen: boolean = false; |
32 | fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT); | 30 | fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT); |
33 | searchMode: boolean = false; | 31 | searchMode: boolean = false; |
34 | sortFn: TItemSortFn = ItemSortFn.sortByNameAsc; | 32 | sortFn: ItemComparator = ItemComparators.sortByNameAsc; |
35 | 33 | ||
36 | // --- | 34 | // --- |
37 | 35 | ||
@@ -47,7 +45,20 @@ export default class UIStore extends VuexModule { | |||
47 | this.searchMode = value ?? !this.searchMode; | 45 | this.searchMode = value ?? !this.searchMode; |
48 | } | 46 | } |
49 | 47 | ||
50 | @mutation setSortFn(sortFn: TItemSortFn) { | 48 | @mutation setSortFn(sortFn: ItemComparator) { |
51 | this.sortFn = sortFn; | 49 | this.sortFn = sortFn; |
52 | } | 50 | } |
51 | |||
52 | @action async initFromConfig(config: Gallery.Config) { | ||
53 | switch (config.initialSort ?? "") { | ||
54 | case "date_desc": | ||
55 | this.setSortFn(ItemComparators.sortByDateDesc); | ||
56 | break; | ||
57 | case "name_asc": | ||
58 | case "": | ||
59 | break; | ||
60 | default: | ||
61 | throw new Error("Unknown sort type: " + config.initialSort); | ||
62 | } | ||
63 | } | ||
53 | } | 64 | } |