From b909ec093591b50950c0de54b2005d471ca28116 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sat, 12 Sep 2020 22:33:37 +0200 Subject: viewer: make default sort order configurable. code review improvements github: resolves #239 --- viewer/src/store/uiStore.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'viewer/src/store') diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts index 04f14a0..84e7fed 100644 --- a/viewer/src/store/uiStore.ts +++ b/viewer/src/store/uiStore.ts @@ -29,7 +29,7 @@ export default class UIStore extends VuexModule { fullscreen: boolean = false; fullWidth: boolean = window.innerWidth < Number(process.env.VUE_APP_FULLWIDTH_LIMIT); searchMode: boolean = false; - sortFn: ItemComparator = ItemComparators.sortByNameAsc; + sortFn: ItemComparator = ItemComparators.DEFAULT; // --- @@ -50,15 +50,10 @@ export default class UIStore extends VuexModule { } @action async initFromConfig(config: Gallery.Config) { - switch (config.initialSort ?? "") { - case "date_desc": - this.setSortFn(ItemComparators.sortByDateDesc); - break; - case "name_asc": - case "": - break; - default: - throw new Error("Unknown sort type: " + config.initialSort); + if (config.initialItemSort) { + const itemSort = ItemComparators.ITEM_SORTS.find(s => s.name == config.initialItemSort); + if (itemSort) this.setSortFn(itemSort.fn); + else throw new Error("Unknown sort type: " + config.initialItemSort); } } } -- cgit v1.2.3