aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/store
diff options
context:
space:
mode:
Diffstat (limited to 'viewer/src/store')
-rw-r--r--viewer/src/store/galleryStore.ts21
-rw-r--r--viewer/src/store/uiStore.ts19
2 files changed, 38 insertions, 2 deletions
diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts
index c875837..ca36a32 100644
--- a/viewer/src/store/galleryStore.ts
+++ b/viewer/src/store/galleryStore.ts
@@ -22,6 +22,7 @@ export default class GalleryStore extends VuexModule {
22 22
23 // --- 23 // ---
24 24
25 // Fetches the gallery's JSON metadata
25 @action async fetchGalleryItems(url: string) { 26 @action async fetchGalleryItems(url: string) {
26 fetch(url) 27 fetch(url)
27 .then(response => response.json()) 28 .then(response => response.json())
@@ -29,14 +30,18 @@ export default class GalleryStore extends VuexModule {
29 .then(this.indexTags); 30 .then(this.indexTags);
30 } 31 }
31 32
33 // Indexes the gallery
32 @action async indexTags() { 34 @action async indexTags() {
33 let index = {}; 35 let index = {};
34 if (this.galleryItemsRoot) 36 if (this.galleryItemsRoot)
35 GalleryStore.pushTagsForItem(index, this.galleryItemsRoot); 37 GalleryStore.pushTagsForItem(index, this.galleryItemsRoot);
36 console.log(index); 38 console.log("Index: ", index);
37 this.setTags(index); 39 this.setTags(index);
38 } 40 }
39 41
42 // ---
43
44 // Pushes all tags for a root item (and its children) to the index
40 private static pushTagsForItem(index: Tag.Index, item: Gallery.Item) { 45 private static pushTagsForItem(index: Tag.Index, item: Gallery.Item) {
41 console.log("IndexingTagsFor: ", item.path); 46 console.log("IndexingTagsFor: ", item.path);
42 for (const tag of item.tags) { 47 for (const tag of item.tags) {
@@ -44,7 +49,7 @@ export default class GalleryStore extends VuexModule {
44 let lastPart: string | null = null; 49 let lastPart: string | null = null;
45 for (const part of parts) { 50 for (const part of parts) {
46 if (!index[part]) index[part] = { tag: part, items: [], children: {} }; 51 if (!index[part]) index[part] = { tag: part, items: [], children: {} };
47 index[part].items.push(item); 52 if (!index[part].items.includes(item)) index[part].items.push(item);
48 if (lastPart) index[lastPart].children[part] = index[part]; 53 if (lastPart) index[lastPart].children[part] = index[part];
49 lastPart = part; 54 lastPart = part;
50 } 55 }
@@ -52,4 +57,16 @@ export default class GalleryStore extends VuexModule {
52 if (item.properties.type === "directory") 57 if (item.properties.type === "directory")
53 item.properties.items.forEach(item => this.pushTagsForItem(index, item)); 58 item.properties.items.forEach(item => this.pushTagsForItem(index, item));
54 } 59 }
60
61 // Searches for an item by path from a root item (navigation)
62 static searchCurrentItem(item: Gallery.Item, path: string): Gallery.Item | null {
63 if (path === item.path) return item;
64 if (item.properties.type === "directory" && path.startsWith(item.path)) {
65 const itemFound = item.properties.items
66 .map(item => this.searchCurrentItem(item, path))
67 .find(item => Boolean(item));
68 return itemFound || null;
69 }
70 return null;
71 }
55} \ No newline at end of file 72} \ No newline at end of file
diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts
index e04b507..4a6f487 100644
--- a/viewer/src/store/uiStore.ts
+++ b/viewer/src/store/uiStore.ts
@@ -8,11 +8,30 @@ const VuexModule = createModule({
8export default class UIStore extends VuexModule { 8export default class UIStore extends VuexModule {
9 9
10 fullscreen: boolean = false; 10 fullscreen: boolean = false;
11 mode: "navigation" | "search" = "navigation";
11 currentTags: Tag.Node[] = []; 12 currentTags: Tag.Node[] = [];
12 13
13 // --- 14 // ---
14 15
16 get isModeSearch() {
17 return this.mode === "search";
18 }
19
20 get isModeNavigation() {
21 return this.mode === "navigation";
22 }
23
24 // ---
25
15 @mutation toggleFullscreen() { 26 @mutation toggleFullscreen() {
16 this.fullscreen = !this.fullscreen; 27 this.fullscreen = !this.fullscreen;
17 } 28 }
29
30 @mutation setModeNavigation() {
31 this.mode = "navigation";
32 }
33
34 @mutation setModeSearch() {
35 this.mode = "search";
36 }
18} 37}