From b252a96d47529749bb1d5e7a8d06fb7ce284b4ee Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Sun, 23 Feb 2020 18:19:33 +0100 Subject: viewer: searching when viewing a picture will return to the parent directory Code review fix --- viewer/src/services/navigation.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'viewer/src/services') diff --git a/viewer/src/services/navigation.ts b/viewer/src/services/navigation.ts index 77fa47a..fa17990 100644 --- a/viewer/src/services/navigation.ts +++ b/viewer/src/services/navigation.ts @@ -31,7 +31,6 @@ export default class Navigation { return []; } - // Normalize a string to lowercase, no-accents public static normalize(value: string) { return value @@ -40,11 +39,20 @@ export default class Navigation { .toLowerCase(); } - + // Checks if the type of an item matches public static checkType(item: Gallery.Item | null, type: Gallery.ItemType): boolean { return item?.properties.type === type ?? false; } + public static getLastDirectory(itemPath: Gallery.Item[]): Gallery.Directory { + for (let idx = itemPath.length - 1; idx >= 0; idx--) { + const item = itemPath[idx]; + if (Navigation.checkType(item, "directory")) return item as Gallery.Directory; + } + throw new Error("No directory found"); + } + + // Sort a list of items, moving the directories to the beginning of the list public static directoriesFirst(items: Gallery.Item[]) { return [ ...items @@ -56,6 +64,7 @@ export default class Navigation { ]; } + // Get the icon for an item public static getIcon(item: Gallery.Item): string { if (item.path.length <= 1) return "home"; switch (item.properties.type) { -- cgit v1.2.3