Skip to content

Commit

Permalink
fixed collection creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratatinator97 committed Jun 13, 2024
1 parent fe66cef commit 7bd28ba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
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
35 changes: 27 additions & 8 deletions store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,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 @@ -180,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 @@ -192,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 @@ -404,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 @@ -423,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 7bd28ba

Please sign in to comment.