From 89bcb2dbe5b5e6eb8e8ba13ceecee2770dfe4cd4 Mon Sep 17 00:00:00 2001 From: Zero~Informatique Date: Thu, 9 Jan 2020 02:10:35 +0100 Subject: 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. --- viewer/src/store/galleryStore.ts | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'viewer/src/store') 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 { galleryItemsRoot: Gallery.Item | null = null; tags: Tag.Index = {}; + currentPath: string = "/"; // --- @@ -20,6 +21,22 @@ export default class GalleryStore extends VuexModule { this.tags = tags; } + @mutation setCurrentPath(currentPath: string) { + this.currentPath = currentPath; + } + + get currentItemPath(): Gallery.Item[] { + const galleryItemsRoot = this.galleryItemsRoot; + if (galleryItemsRoot) + return GalleryStore.searchCurrentItemPath(galleryItemsRoot, this.currentPath); + return []; + } + + get currentItem(): Gallery.Item | null { + const currentItemPath = this.currentItemPath; + return currentItemPath.length > 0 ? currentItemPath[currentItemPath.length - 1] : null; + } + // --- // Fetches the gallery's JSON metadata @@ -61,14 +78,14 @@ export default class GalleryStore extends VuexModule { } // Searches for an item by path from a root item (navigation) - static searchCurrentItem(item: Gallery.Item, path: string): Gallery.Item | null { - if (path === item.path) return item; + private static searchCurrentItemPath(item: Gallery.Item, path: string): Gallery.Item[] { + if (path === item.path) return [item]; if (item.properties.type === "directory" && path.startsWith(item.path)) { - const itemFound = item.properties.items - .map(item => this.searchCurrentItem(item, path)) - .find(item => Boolean(item)); - return itemFound ?? null; + const itemChain = item.properties.items + .map(item => this.searchCurrentItemPath(item, path)) + .find(itemChain => itemChain.length > 0); + if (itemChain) return [item, ...itemChain]; } - return null; + return []; } } \ No newline at end of file -- cgit v1.2.3