diff options
author | Zero~Informatique | 2020-01-09 02:10:35 +0100 |
---|---|---|
committer | Zero~Informatique | 2020-01-09 02:10:35 +0100 |
commit | 89bcb2dbe5b5e6eb8e8ba13ceecee2770dfe4cd4 (patch) | |
tree | 8eb2c100707123f77ff6980c94e161d6214c648f /viewer/src/store | |
parent | c1e334b883e28381851fca077ff36aee0387b1db (diff) | |
download | ldgallery-89bcb2dbe5b5e6eb8e8ba13ceecee2770dfe4cd4.tar.gz |
viewer: Changed "image" type to "picture". Adapted the code to the current compiler output format. The currentItem and currentPath are calculated in the store for easier multi-component access. Breadcrumb for current's position and navigation.
Diffstat (limited to 'viewer/src/store')
-rw-r--r-- | viewer/src/store/galleryStore.ts | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts index 179fbe2..2d17fd6 100644 --- a/viewer/src/store/galleryStore.ts +++ b/viewer/src/store/galleryStore.ts | |||
@@ -9,6 +9,7 @@ export default class GalleryStore extends VuexModule { | |||
9 | 9 | ||
10 | galleryItemsRoot: Gallery.Item | null = null; | 10 | galleryItemsRoot: Gallery.Item | null = null; |
11 | tags: Tag.Index = {}; | 11 | tags: Tag.Index = {}; |
12 | currentPath: string = "/"; | ||
12 | 13 | ||
13 | // --- | 14 | // --- |
14 | 15 | ||
@@ -20,6 +21,22 @@ export default class GalleryStore extends VuexModule { | |||
20 | this.tags = tags; | 21 | this.tags = tags; |
21 | } | 22 | } |
22 | 23 | ||
24 | @mutation setCurrentPath(currentPath: string) { | ||
25 | this.currentPath = currentPath; | ||
26 | } | ||
27 | |||
28 | get currentItemPath(): Gallery.Item[] { | ||
29 | const galleryItemsRoot = this.galleryItemsRoot; | ||
30 | if (galleryItemsRoot) | ||
31 | return GalleryStore.searchCurrentItemPath(galleryItemsRoot, this.currentPath); | ||
32 | return []; | ||
33 | } | ||
34 | |||
35 | get currentItem(): Gallery.Item | null { | ||
36 | const currentItemPath = this.currentItemPath; | ||
37 | return currentItemPath.length > 0 ? currentItemPath[currentItemPath.length - 1] : null; | ||
38 | } | ||
39 | |||
23 | // --- | 40 | // --- |
24 | 41 | ||
25 | // Fetches the gallery's JSON metadata | 42 | // Fetches the gallery's JSON metadata |
@@ -61,14 +78,14 @@ export default class GalleryStore extends VuexModule { | |||
61 | } | 78 | } |
62 | 79 | ||
63 | // Searches for an item by path from a root item (navigation) | 80 | // Searches for an item by path from a root item (navigation) |
64 | static searchCurrentItem(item: Gallery.Item, path: string): Gallery.Item | null { | 81 | private static searchCurrentItemPath(item: Gallery.Item, path: string): Gallery.Item[] { |
65 | if (path === item.path) return item; | 82 | if (path === item.path) return [item]; |
66 | if (item.properties.type === "directory" && path.startsWith(item.path)) { | 83 | if (item.properties.type === "directory" && path.startsWith(item.path)) { |
67 | const itemFound = item.properties.items | 84 | const itemChain = item.properties.items |
68 | .map(item => this.searchCurrentItem(item, path)) | 85 | .map(item => this.searchCurrentItemPath(item, path)) |
69 | .find(item => Boolean(item)); | 86 | .find(itemChain => itemChain.length > 0); |
70 | return itemFound ?? null; | 87 | if (itemChain) return [item, ...itemChain]; |
71 | } | 88 | } |
72 | return null; | 89 | return []; |
73 | } | 90 | } |
74 | } \ No newline at end of file | 91 | } \ No newline at end of file |