diff options
author | Zero~Informatique | 2020-09-12 06:34:58 +0200 |
---|---|---|
committer | G.Fouet | 2020-09-12 23:19:44 +0200 |
commit | 96ed5e6583a7f03d4ea7fa0512e66fffb656cc6e (patch) | |
tree | 7df81984c78d616bff317be25f99c7c2d02286c8 /viewer/src/store | |
parent | 7a8eba922ad34182628f80cf2496d8654abe91e6 (diff) | |
download | ldgallery-96ed5e6583a7f03d4ea7fa0512e66fffb656cc6e.tar.gz |
viewer: make default sort order configurable
github: resolves #239
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 | } |