diff options
Diffstat (limited to 'viewer/src')
-rw-r--r-- | viewer/src/services/navigation.ts | 13 | ||||
-rw-r--r-- | viewer/src/views/PanelLeft.vue | 4 |
2 files changed, 14 insertions, 3 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) { |
diff --git a/viewer/src/views/PanelLeft.vue b/viewer/src/views/PanelLeft.vue index fd117a6..eb921b7 100644 --- a/viewer/src/views/PanelLeft.vue +++ b/viewer/src/views/PanelLeft.vue | |||
@@ -34,6 +34,7 @@ | |||
34 | <script lang="ts"> | 34 | <script lang="ts"> |
35 | import { Component, Vue, Prop } from "vue-property-decorator"; | 35 | import { Component, Vue, Prop } from "vue-property-decorator"; |
36 | import { Dictionary } from "vue-router/types/router"; | 36 | import { Dictionary } from "vue-router/types/router"; |
37 | import Navigation from "../services/navigation"; | ||
37 | 38 | ||
38 | @Component | 39 | @Component |
39 | export default class PanelLeft extends Vue { | 40 | export default class PanelLeft extends Vue { |
@@ -43,7 +44,8 @@ export default class PanelLeft extends Vue { | |||
43 | } | 44 | } |
44 | 45 | ||
45 | search() { | 46 | search() { |
46 | this.$router.push({ query: this.serializeSearch() }).catch(err => { | 47 | const lastDirectory = Navigation.getLastDirectory(this.$galleryStore.currentItemPath); |
48 | this.$router.push({ path: lastDirectory.path, query: this.serializeSearch() }).catch(err => { | ||
47 | if (err.name !== "NavigationDuplicated") throw err; | 49 | if (err.name !== "NavigationDuplicated") throw err; |
48 | }); | 50 | }); |
49 | } | 51 | } |