Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
UnlikelyBuddy1 committed Jun 13, 2024
2 parents a0f98f1 + 7bd28ba commit 3939906
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
5 changes: 2 additions & 3 deletions components/navigation/pictalk-navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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] },
});
}
},
Expand Down
1 change: 0 additions & 1 deletion pages/pictalk/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
38 changes: 30 additions & 8 deletions store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
Expand All @@ -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)) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit 3939906

Please sign in to comment.