aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/services/navigation.ts
diff options
context:
space:
mode:
authorZero~Informatique2020-02-23 18:19:33 +0100
committerZero~Informatique2020-02-24 00:04:40 +0100
commitb252a96d47529749bb1d5e7a8d06fb7ce284b4ee (patch)
tree5ec03f0ed04a9af6c9d7738dd38e0b4f43f87599 /viewer/src/services/navigation.ts
parent1915fd6e8b7b0c83a9a1b9254fd945f1cc0c7c19 (diff)
downloadldgallery-b252a96d47529749bb1d5e7a8d06fb7ce284b4ee.tar.gz
viewer: searching when viewing a picture will return to the parent directory
Code review fix
Diffstat (limited to 'viewer/src/services/navigation.ts')
-rw-r--r--viewer/src/services/navigation.ts13
1 files changed, 11 insertions, 2 deletions
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 {
31 return []; 31 return [];
32 } 32 }
33 33
34
35 // Normalize a string to lowercase, no-accents 34 // Normalize a string to lowercase, no-accents
36 public static normalize(value: string) { 35 public static normalize(value: string) {
37 return value 36 return value
@@ -40,11 +39,20 @@ export default class Navigation {
40 .toLowerCase(); 39 .toLowerCase();
41 } 40 }
42 41
43 42 // Checks if the type of an item matches
44 public static checkType(item: Gallery.Item | null, type: Gallery.ItemType): boolean { 43 public static checkType(item: Gallery.Item | null, type: Gallery.ItemType): boolean {
45 return item?.properties.type === type ?? false; 44 return item?.properties.type === type ?? false;
46 } 45 }
47 46
47 public static getLastDirectory(itemPath: Gallery.Item[]): Gallery.Directory {
48 for (let idx = itemPath.length - 1; idx >= 0; idx--) {
49 const item = itemPath[idx];
50 if (Navigation.checkType(item, "directory")) return item as Gallery.Directory;
51 }
52 throw new Error("No directory found");
53 }
54
55 // Sort a list of items, moving the directories to the beginning of the list
48 public static directoriesFirst(items: Gallery.Item[]) { 56 public static directoriesFirst(items: Gallery.Item[]) {
49 return [ 57 return [
50 ...items 58 ...items
@@ -56,6 +64,7 @@ export default class Navigation {
56 ]; 64 ];
57 } 65 }
58 66
67 // Get the icon for an item
59 public static getIcon(item: Gallery.Item): string { 68 public static getIcon(item: Gallery.Item): string {
60 if (item.path.length <= 1) return "home"; 69 if (item.path.length <= 1) return "home";
61 switch (item.properties.type) { 70 switch (item.properties.type) {