aboutsummaryrefslogtreecommitdiff
path: root/viewer
diff options
context:
space:
mode:
Diffstat (limited to 'viewer')
-rw-r--r--viewer/src/@types/gallery.d.ts2
-rw-r--r--viewer/src/locales/en.json1
-rw-r--r--viewer/src/services/itemComparators.ts15
3 files changed, 14 insertions, 4 deletions
diff --git a/viewer/src/@types/gallery.d.ts b/viewer/src/@types/gallery.d.ts
index a7f3d29..41ad5bb 100644
--- a/viewer/src/@types/gallery.d.ts
+++ b/viewer/src/@types/gallery.d.ts
@@ -18,7 +18,7 @@
18*/ 18*/
19 19
20declare namespace Gallery { 20declare namespace Gallery {
21 type ItemSortStr = "name_asc" | "date_desc"; 21 type ItemSortStr = "name_asc" | "date_asc" | "date_desc";
22 22
23 interface Config { 23 interface Config {
24 galleryRoot: string; 24 galleryRoot: string;
diff --git a/viewer/src/locales/en.json b/viewer/src/locales/en.json
index ce5b8b2..41088da 100644
--- a/viewer/src/locales/en.json
+++ b/viewer/src/locales/en.json
@@ -4,6 +4,7 @@
4 "command.search": "Open/close search panel", 4 "command.search": "Open/close search panel",
5 "command.search.clear": "Clear", 5 "command.search.clear": "Clear",
6 "command.search.search": "Search", 6 "command.search.search": "Search",
7 "command.sort.byDateAsc": "By date (oldest first)",
7 "command.sort.byDateDesc": "By date (most recent first)", 8 "command.sort.byDateDesc": "By date (most recent first)",
8 "command.sort.byNameAsc": "By name (A to Z)", 9 "command.sort.byNameAsc": "By name (A to Z)",
9 "directory.no-results": "Empty directory", 10 "directory.no-results": "Empty directory",
diff --git a/viewer/src/services/itemComparators.ts b/viewer/src/services/itemComparators.ts
index 6a7c81c..64ce288 100644
--- a/viewer/src/services/itemComparators.ts
+++ b/viewer/src/services/itemComparators.ts
@@ -27,7 +27,12 @@ export default class ItemComparators {
27 27
28 static readonly ITEM_SORTS: ItemSort[] = [ 28 static readonly ITEM_SORTS: ItemSort[] = [
29 { name: "name_asc", text: i18n.t("command.sort.byNameAsc"), fn: ItemComparators.sortByNameAsc }, 29 { name: "name_asc", text: i18n.t("command.sort.byNameAsc"), fn: ItemComparators.sortByNameAsc },
30 { name: "date_desc", text: i18n.t("command.sort.byDateDesc"), fn: ItemComparators.sortByDateDesc }, 30 { name: "date_asc", text: i18n.t("command.sort.byDateAsc"), fn: ItemComparators.sortByDateAsc },
31 {
32 name: "date_desc",
33 text: i18n.t("command.sort.byDateDesc"),
34 fn: ItemComparators.reverse(ItemComparators.sortByDateAsc),
35 },
31 ]; 36 ];
32 37
33 static sortByNameAsc(left: Gallery.Item, right: Gallery.Item): number { 38 static sortByNameAsc(left: Gallery.Item, right: Gallery.Item): number {
@@ -38,7 +43,11 @@ export default class ItemComparators {
38 }); 43 });
39 } 44 }
40 45
41 static sortByDateDesc(left: Gallery.Item, right: Gallery.Item): number { 46 static sortByDateAsc(left: Gallery.Item, right: Gallery.Item): number {
42 return -left.datetime.localeCompare(right.datetime); // TODO: handle timezones 47 return left.datetime.localeCompare(right.datetime); // TODO: handle timezones
48 }
49
50 static reverse(fn: ItemComparator): ItemComparator {
51 return (l, r) => -fn(l, r);
43 } 52 }
44} 53}