From 96ed5e6583a7f03d4ea7fa0512e66fffb656cc6e Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sat, 12 Sep 2020 06:34:58 +0200 Subject: viewer: make default sort order configurable github: resolves #239 --- viewer/src/services/itemComparators.ts | 30 ++++++++++++++++++++++++++++++ viewer/src/services/itemSortFn.ts | 28 ---------------------------- 2 files changed, 30 insertions(+), 28 deletions(-) create mode 100644 viewer/src/services/itemComparators.ts delete mode 100644 viewer/src/services/itemSortFn.ts (limited to 'viewer/src/services') diff --git a/viewer/src/services/itemComparators.ts b/viewer/src/services/itemComparators.ts new file mode 100644 index 0000000..c8fedbe --- /dev/null +++ b/viewer/src/services/itemComparators.ts @@ -0,0 +1,30 @@ +/* ldgallery - A static generator which turns a collection of tagged +-- pictures into a searchable web gallery. +-- +-- Copyright (C) 2019-2020 Guillaume FOUET +-- +-- This program is free software: you can redistribute it and/or modify +-- it under the terms of the GNU Affero General Public License as +-- published by the Free Software Foundation, either version 3 of the +-- License, or (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU Affero General Public License for more details. +-- +-- You should have received a copy of the GNU Affero General Public License +-- along with this program. If not, see . +*/ + +export type ItemComparator = (left: Gallery.Item, right: Gallery.Item) => number; + +export default class ItemComparators { + static sortByNameAsc(left: Gallery.Item, right: Gallery.Item): number { + return left.title.localeCompare(right.title); + } + + static sortByDateDesc(left: Gallery.Item, right: Gallery.Item): number { + return -left.datetime.localeCompare(right.datetime); // TODO: handle timezones + } +} diff --git a/viewer/src/services/itemSortFn.ts b/viewer/src/services/itemSortFn.ts deleted file mode 100644 index a7e0883..0000000 --- a/viewer/src/services/itemSortFn.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* ldgallery - A static generator which turns a collection of tagged --- pictures into a searchable web gallery. --- --- Copyright (C) 2019-2020 Guillaume FOUET --- --- This program is free software: you can redistribute it and/or modify --- it under the terms of the GNU Affero General Public License as --- published by the Free Software Foundation, either version 3 of the --- License, or (at your option) any later version. --- --- This program is distributed in the hope that it will be useful, --- but WITHOUT ANY WARRANTY; without even the implied warranty of --- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --- GNU Affero General Public License for more details. --- --- You should have received a copy of the GNU Affero General Public License --- along with this program. If not, see . -*/ - -export default class ItemSortFn { - static sortByNameAsc(left: Gallery.Item, right: Gallery.Item): number { - return left.title.localeCompare(right.title); - } - - static sortByDateDesc(left: Gallery.Item, right: Gallery.Item): number { - return -left.datetime.localeCompare(right.datetime); // TODO: handle timezones - } -} -- cgit v1.2.3