aboutsummaryrefslogtreecommitdiff
path: root/viewer/src/store
diff options
context:
space:
mode:
authorZero~Informatique2020-02-27 17:23:32 +0100
committerZero~Informatique2020-02-27 17:53:41 +0100
commit7c2a2ff46469d5e8f44fb3ec7feae5f798e0baf8 (patch)
tree9b4c12bd263013687f8cec3f0002122bd458aa49 /viewer/src/store
parentd862c99d6ee74f25261c00fcfee3a6e551501f16 (diff)
downloadldgallery-7c2a2ff46469d5e8f44fb3ec7feae5f798e0baf8.tar.gz
viewer: architectural fixes and improvements
Make use of VueX's strict mode (which is different from vuex-class-component strict mode) Fixed issues and bad-practices with search filter tags mutations Correctly implement the new index.json format
Diffstat (limited to 'viewer/src/store')
-rw-r--r--viewer/src/store/galleryStore.ts23
-rw-r--r--viewer/src/store/index.ts3
-rw-r--r--viewer/src/store/uiStore.ts1
3 files changed, 17 insertions, 10 deletions
diff --git a/viewer/src/store/galleryStore.ts b/viewer/src/store/galleryStore.ts
index cd09996..84673b5 100644
--- a/viewer/src/store/galleryStore.ts
+++ b/viewer/src/store/galleryStore.ts
@@ -29,9 +29,10 @@ const VuexModule = createModule({
29export default class GalleryStore extends VuexModule { 29export default class GalleryStore extends VuexModule {
30 30
31 config: Gallery.Config | null = null; 31 config: Gallery.Config | null = null;
32 galleryItemsRoot: Gallery.Item | null = null; 32 galleryIndex: Gallery.Index | null = null;
33 tagsIndex: Tag.Index = {}; 33 tagsIndex: Tag.Index = {};
34 currentPath: string = "/"; 34 currentPath: string = "/";
35 currentSearch: Tag.Search[] = [];
35 36
36 // --- 37 // ---
37 38
@@ -39,20 +40,26 @@ export default class GalleryStore extends VuexModule {
39 this.config = config; 40 this.config = config;
40 } 41 }
41 42
42 @mutation setGalleryItemsRoot(galleryItemsRoot: Gallery.Item) { 43 @mutation setGalleryIndex(galleryIndex: Gallery.Index) {
43 this.galleryItemsRoot = galleryItemsRoot; 44 this.galleryIndex = Object.freeze(galleryIndex);
44 } 45 }
45 46
46 @mutation private setTagsIndex(tagsIndex: Tag.Index) { 47 @mutation private setTagsIndex(tagsIndex: Tag.Index) {
47 this.tagsIndex = tagsIndex; 48 this.tagsIndex = Object.freeze(tagsIndex);
48 } 49 }
49 50
50 @mutation setCurrentPath(currentPath: string) { 51 @mutation setCurrentPath(currentPath: string) {
51 this.currentPath = currentPath; 52 this.currentPath = currentPath;
52 } 53 }
53 54
55 @mutation setCurrentSearch(currentSearch: Tag.Search[]) {
56 this.currentSearch = currentSearch;
57 }
58
59 // ---
60
54 get currentItemPath(): Gallery.Item[] { 61 get currentItemPath(): Gallery.Item[] {
55 const root = this.galleryItemsRoot; 62 const root = this.galleryIndex?.tree;
56 if (root) 63 if (root)
57 return Navigation.searchCurrentItemPath(root, this.currentPath); 64 return Navigation.searchCurrentItemPath(root, this.currentPath);
58 return []; 65 return [];
@@ -77,14 +84,14 @@ export default class GalleryStore extends VuexModule {
77 const root = this.config?.galleryRoot ?? ''; 84 const root = this.config?.galleryRoot ?? '';
78 return fetch(`${process.env.VUE_APP_DATA_URL}${root}index.json`, { cache: "no-cache" }) 85 return fetch(`${process.env.VUE_APP_DATA_URL}${root}index.json`, { cache: "no-cache" })
79 .then(response => response.json()) 86 .then(response => response.json())
80 .then(index => index.tree) 87 .then(this.setGalleryIndex)
81 .then(this.setGalleryItemsRoot)
82 .then(this.indexTags); 88 .then(this.indexTags);
83 } 89 }
84 90
85 // Indexes the gallery 91 // Indexes the gallery
86 @action async indexTags() { 92 @action async indexTags() {
87 this.setTagsIndex(IndexFactory.generateTags(this.galleryItemsRoot)); 93 const root = this.galleryIndex?.tree ?? null;
94 this.setTagsIndex(IndexFactory.generateTags(root));
88 } 95 }
89 96
90} 97}
diff --git a/viewer/src/store/index.ts b/viewer/src/store/index.ts
index 0277fa4..956d4fd 100644
--- a/viewer/src/store/index.ts
+++ b/viewer/src/store/index.ts
@@ -30,7 +30,8 @@ const store = new Vuex.Store({
30 modules: { 30 modules: {
31 ...extractVuexModule(UIStore), 31 ...extractVuexModule(UIStore),
32 ...extractVuexModule(GalleryStore) 32 ...extractVuexModule(GalleryStore)
33 } 33 },
34 strict: process.env.NODE_ENV !== "production",
34}); 35});
35 36
36Vue.use((vue) => vue.prototype.$uiStore = createProxy(store, UIStore)); 37Vue.use((vue) => vue.prototype.$uiStore = createProxy(store, UIStore));
diff --git a/viewer/src/store/uiStore.ts b/viewer/src/store/uiStore.ts
index 5b6e1ca..1e63b3e 100644
--- a/viewer/src/store/uiStore.ts
+++ b/viewer/src/store/uiStore.ts
@@ -29,7 +29,6 @@ export default class UIStore extends VuexModule {
29 fullscreen: boolean = false; 29 fullscreen: boolean = false;
30 fullWidth: boolean = true; 30 fullWidth: boolean = true;
31 searchMode: boolean = false; 31 searchMode: boolean = false;
32 searchFilters: Tag.Search[] = [];
33 32
34 // --- 33 // ---
35 34