aboutsummaryrefslogtreecommitdiff
path: root/viewer/src
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
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')
-rw-r--r--viewer/src/services/navigation.ts13
-rw-r--r--viewer/src/views/PanelLeft.vue4
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">
35import { Component, Vue, Prop } from "vue-property-decorator"; 35import { Component, Vue, Prop } from "vue-property-decorator";
36import { Dictionary } from "vue-router/types/router"; 36import { Dictionary } from "vue-router/types/router";
37import Navigation from "../services/navigation";
37 38
38@Component 39@Component
39export default class PanelLeft extends Vue { 40export 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 }