aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/services
diff options
context:
space:
mode:
authorzeroinformatique2020-09-17 15:51:42 +0200
committerGitHub2020-09-17 15:51:42 +0200
commitab97f64575f1b51bacced6ce1bc6bf22e0354615 (patch)
tree49cf6ce1429e7c4df67973f8472cf7819c0f9a19 /viewer/src/services
parentb530f65cf7bc32eb4bb16cf445950a0b1ab685b4 (diff)
downloadldgallery-ab97f64575f1b51bacced6ce1bc6bf22e0354615.tar.gz
viewer: sort by date ascending (#249)
* viewer: sort by date ascending * viewer: sort by date ascending
Diffstat (limited to 'viewer/src/services')
-rw-r--r--viewer/src/services/itemComparators.ts15
1 files changed, 12 insertions, 3 deletions
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}