diff --git a/components/navigation/pictalk-navbar.vue b/components/navigation/pictalk-navbar.vue index 70ff044..9358f92 100644 --- a/components/navigation/pictalk-navbar.vue +++ b/components/navigation/pictalk-navbar.vue @@ -353,7 +353,6 @@ export default { }, navigateToParentCollection() { const navigation = this.$store.getters.getNavigation - console.log("navigation", navigation) if (navigation.length < 2) { if (this.publicMode) { this.$router.push( @@ -375,10 +374,10 @@ export default { } } } else { - console.log("navigating to", navigation[navigation.length - 2]) + this.$store.commit("popNavigation"); this.$router.push({ path: this.publicMode ? "/public" : "/pictalk", - query: { ...this.$route.query, fatherCollectionId: navigation[navigation.length - 2] }, + query: { ...this.$route.query, fatherCollectionId: navigation[navigation.length - 1] }, }); } }, diff --git a/pages/pictalk/index.vue b/pages/pictalk/index.vue index 411293b..5063a8b 100644 --- a/pages/pictalk/index.vue +++ b/pages/pictalk/index.vue @@ -195,7 +195,6 @@ export default { this.sidebarPictos = await this.loadedSidebarPictos(); } - console.log("sidebarPictos", this.sidebarPictos); const user = this.$store.getters.getUser; if (!user.username) { try { diff --git a/store/index.js b/store/index.js index 3033581..770e9be 100644 --- a/store/index.js +++ b/store/index.js @@ -119,6 +119,9 @@ export const mutations = { if (state.navigation[state.navigation.length - 1] == navigation) return; state.navigation.push(navigation); }, + popNavigation(state) { + state.navigation.pop(); + }, resetNavigation(state) { if (state.user.root) { state.navigation = [String(state.user.root)]; @@ -133,13 +136,30 @@ export const actions = { newCollections = new Array(newCollections); } const db = await getDexieDB(); - // Dexie transition - await db.collection.bulkPut(newCollections); - + let collection; + let toModify = []; + // Merge with the newCollections array + toModify = toModify.concat(newCollections); + for (let newCollection of newCollections) { + if (newCollection.fatherCollectionId) { + collection = await db.collection.get(newCollection.fatherCollectionId); + if (collection) { + const collectionIndex = collection.collections.findIndex( + col => col.id === newCollection.id + ); + if (collection && collectionIndex == -1) { + collection.collections.push({ id: newCollection.id }); + toModify.push(collection); + } + } + } + } + await db.collection.bulkPut(toModify); + return; }, async dbRemoveCollection(state, removedCollection) { const db = await getDexieDB(); - await db.collection.delete(removedCollection.id); + return db.collection.delete(removedCollection.id); }, async dbEditCollection(state, editedCollections) { if (!Array.isArray(editedCollections)) { @@ -177,7 +197,7 @@ export const actions = { } } // Dexie transition - await db.pictogram.bulkPut(pictos); + return db.pictogram.bulkPut(pictos); }, async dbEditPicto(state, editedPictos) { if (!Array.isArray(editedPictos)) { @@ -189,15 +209,15 @@ export const actions = { Object.assign(pct, picto); return pct; })); - await db.pictogram.bulkPut(editedPictos); + return db.pictogram.bulkPut(editedPictos); }, async dbResetCollections(state) { const db = await getDexieDB(); - await db.collection.clear(); + return db.collection.clear(); }, async dbSetCollections(state, collections) { const db = await getDexieDB(); - await db.collection.bulkPut(collections); + return db.collection.bulkPut(collections); }, async fetchCollection(vuexContext, collectionId) { @@ -401,6 +421,7 @@ export const actions = { "Content-Type": "multipart/form-data" } })).data; + console.log("Collection call done"); const editedNewCollection = { speech: collection.speech, meaning: collection.meaning, @@ -420,6 +441,7 @@ export const actions = { ...(collection.pictohubId && { pictohubId: Number(collection.pictohubId) }), }; await vuexContext.dispatch("dbAddCollection", editedNewCollection); + console.log("Collection added to db"); return editedNewCollection; }, async editCollection(vuexContext, collection) {