aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/services/itemComparators.ts
diff options
context:
space:
mode:
Diffstat (limited to 'viewer/src/services/itemComparators.ts')
-rw-r--r--viewer/src/services/itemComparators.ts13
1 files changed, 7 insertions, 6 deletions
diff --git a/viewer/src/services/itemComparators.ts b/viewer/src/services/itemComparators.ts
index bd9accb..aceff79 100644
--- a/viewer/src/services/itemComparators.ts
+++ b/viewer/src/services/itemComparators.ts
@@ -16,14 +16,15 @@
16-- You should have received a copy of the GNU Affero General Public License 16-- You should have received a copy of the GNU Affero General Public License
17-- along with this program. If not, see <https://www.gnu.org/licenses/>. 17-- along with this program. If not, see <https://www.gnu.org/licenses/>.
18*/ 18*/
19import { TranslateResult } from "vue-i18n"; 19import { Item, ItemSortStr } from "@/@types/gallery";
20import i18n from "@/plugins/i18n"; 20import i18n from "@/plugins/i18n";
21import { TranslateResult } from "vue-i18n";
21 22
22export type ItemComparator = (left: Gallery.Item, right: Gallery.Item) => number; 23export type ItemComparator = (left: Item, right: Item) => number;
23export type ItemSort = { text: TranslateResult; fn: ItemComparator }; 24export type ItemSort = { text: TranslateResult; fn: ItemComparator };
24 25
25export default class ItemComparators { 26export default class ItemComparators {
26 static readonly ITEM_SORTS: Record<Gallery.ItemSortStr, ItemSort> = { 27 static readonly ITEM_SORTS: Record<ItemSortStr, ItemSort> = {
27 title_asc: { 28 title_asc: {
28 text: i18n.t("command.sort.byTitleAsc"), 29 text: i18n.t("command.sort.byTitleAsc"),
29 fn: ItemComparators.chain(ItemComparators.sortByTitleAsc, ItemComparators.sortByPathAsc), 30 fn: ItemComparators.chain(ItemComparators.sortByTitleAsc, ItemComparators.sortByPathAsc),
@@ -40,7 +41,7 @@ export default class ItemComparators {
40 41
41 static readonly DEFAULT = ItemComparators.ITEM_SORTS.date_asc; 42 static readonly DEFAULT = ItemComparators.ITEM_SORTS.date_asc;
42 43
43 static sortByPathAsc(left: Gallery.Item, right: Gallery.Item): number { 44 static sortByPathAsc(left: Item, right: Item): number {
44 return left.path.localeCompare(right.path, undefined, { 45 return left.path.localeCompare(right.path, undefined, {
45 sensitivity: "base", 46 sensitivity: "base",
46 ignorePunctuation: true, 47 ignorePunctuation: true,
@@ -48,7 +49,7 @@ export default class ItemComparators {
48 }); 49 });
49 } 50 }
50 51
51 static sortByTitleAsc(left: Gallery.Item, right: Gallery.Item): number { 52 static sortByTitleAsc(left: Item, right: Item): number {
52 return left.title.localeCompare(right.title, undefined, { 53 return left.title.localeCompare(right.title, undefined, {
53 sensitivity: "base", 54 sensitivity: "base",
54 ignorePunctuation: true, 55 ignorePunctuation: true,
@@ -56,7 +57,7 @@ export default class ItemComparators {
56 }); 57 });
57 } 58 }
58 59
59 static sortByDateAsc(left: Gallery.Item, right: Gallery.Item): number { 60 static sortByDateAsc(left: Item, right: Item): number {
60 return left.datetime.localeCompare(right.datetime); // TODO: handle timezones 61 return left.datetime.localeCompare(right.datetime); // TODO: handle timezones
61 } 62 }
62 63