Skip to content

Commit

Permalink
fix async dexie + logout
Browse files Browse the repository at this point in the history
  • Loading branch information
Ratatinator97 committed Jun 5, 2024
1 parent 36ac498 commit 28edb68
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 66 deletions.
10 changes: 8 additions & 2 deletions components/navigation/modeModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
icon-left="folder-account" class="fullWidth customButton" />
</div>
<div class="option">
<b-button style="background-color: hsl(154, 100%, 70%)" :label="$t('PublicCollections')"
@click="goTo('/public/')" icon-left="web" class="fullWidth customButton" />
<b-button style="background-color: hsl(154, 100%, 70%)" :label="$t('PublicCollections')" @click="goToPublic()"
icon-left="web" class="fullWidth customButton" />
</div>
</section>
</div>
Expand Down Expand Up @@ -43,6 +43,12 @@ export default {
});
this.$parent.close();
},
goToPublic() {
this.$router.push({
path: "/public/pictalk",
});
this.$parent.close();
}
},
computed: {
sharedLink() {
Expand Down
18 changes: 13 additions & 5 deletions components/navigation/pictalk-navbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ export default {
}
},
watch: {
"$route.query.fatherCollectionId": function (newVal, oldVal) {
if (newVal != oldVal) {
if (!newVal) return;
console.log("navigation changed")
this.$store.commit("pushNavigation", newVal);
console.log(this.$store.getters.getNavigation)
}
},
$route(to, from) {
if (to.path.includes("pictalk")) {
this.icon = "home";
Expand Down Expand Up @@ -350,10 +358,9 @@ export default {
});
},
navigateToParentCollection() {
actionsHistory
const speechCollectionArray = this.$store.getters.getSpeech.filter((picto) => !picto.sidebar && picto.collection);
const speechCollectionArrayBeforePosition = speechCollectionArray.slice(0, speechCollectionArray.findIndex((picto) => picto.id == parseInt(this.$route.query.fatherCollectionId)));
if (speechCollectionArrayBeforePosition.length < 1) {
const navigation = this.$store.getters.getNavigation
console.log("navigation", navigation)
if (navigation.length < 2) {
if (this.publicMode) {
this.$router.push(
{
Expand All @@ -374,9 +381,10 @@ export default {
}
}
} else {
console.log("navigating to", navigation[navigation.length - 2])
this.$router.push({
path: this.publicMode ? "/public/pictalk" : "/pictalk",
query: { ...this.$route.query, fatherCollectionId: speechCollectionArrayBeforePosition[speechCollectionArrayBeforePosition.length - 1]?.id },
query: { ...this.$route.query, fatherCollectionId: navigation[navigation.length - 2] },
});
}
},
Expand Down
2 changes: 2 additions & 0 deletions components/pictos/pictoBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ export default {
}
} else {
if (pictalkSpeech.length <= 1) {
this.$store.commit("resetNavigation");
if (this.publicMode) {
this.$router.push("/public/pictalk?fatherCollectionId=346");
} else {
Expand Down Expand Up @@ -253,6 +254,7 @@ export default {
this.$store.commit("removeSpeech");
},
eraseSpeech() {
this.$store.commit("resetNavigation");
if (this.publicMode) {
this.$router.push("/public/pictalk?fatherCollectionId=346");
this.$store.commit("eraseSpeech");
Expand Down
13 changes: 0 additions & 13 deletions middleware/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,4 @@ export default function (context) {
(error) => {
return Promise.reject(error);
});

/*
axios.interceptors.response.use((response) => {
// If err 401 redirect to homepage with notifications
return response;
}, async (error) => {
if (error.response?.status == 401) {
await context.store.dispatch("logout");
context.store.commit('editUser', {});
context.redirect('/');
return Promise.reject(error);
}
});*/
}
1 change: 0 additions & 1 deletion mixins/pictogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export default {
});
if (this.picto.collection == true) {
this.$router.push({
path: "/pictalk",
query: { ...this.$route.query, fatherCollectionId: this.picto.id },
});
}
Expand Down
5 changes: 1 addition & 4 deletions nuxt.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pkg from './package.json'
export default {
ssr: true,
ssr: false,
target: 'static',
server: {
host: '0.0.0.0', // default: localhost,
Expand All @@ -12,9 +12,6 @@ export default {
apiURL: process.env.API_URL || "http://localhost:3001",
clientVersion: pkg.version,
},
generate: {
fallback: true
},
meta: {
ogTitle: false,
ogDescription: false,
Expand Down
1 change: 0 additions & 1 deletion pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ export default {
}
}
},
middleware: ["check-auth"],
methods: {
openSignUpModal() {
this.$buefy.modal.open({
Expand Down
21 changes: 21 additions & 0 deletions pages/public/pictalk/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ export default {
return "#f5f5f5";
}
},
sidebarPictoId() {
return this.$store.getters.getSidebarId;
},
fatherCollectionId() {
return this.$route.query.fatherCollectionId;
},
},
watch: {
async fatherCollectionId(fatherCollectionId, previousId) {
if (fatherCollectionId && fatherCollectionId != previousId) {
await this.fetchCollection(fatherCollectionId);
this.pictos = await this.loadedPictos();
}
},
async sidebarPictoId(sidebarId, previousId) {
if (sidebarId && sidebarId != previousId) {
await this.fetchCollection(sidebarId);
this.sidebarPictos = await this.loadedSidebarPictos();
}
},
},
async fetch() {
if (process.client) {
Expand Down Expand Up @@ -71,6 +91,7 @@ export default {
const collection = await this.$store.dispatch("fetchCollection", collectionId);
return collection;
} catch (error) {
console.log(error);
const notif = this.$buefy.notification.open({
duration: 4500,
message: this.$t("LostConnectivity"),
Expand Down
18 changes: 16 additions & 2 deletions plugins/dexieDB.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
export let db;
if (process.client) {

export async function getDatabase() {
if (db.isOpen()) {
console.log("Database is already open");
return db;
} else {
console.log("Database is not open")
await db.open();
return db;
}
}

function initializeDatabase() {
const Dexie = require('dexie').Dexie;
let username = 'default';
const data = JSON.parse(window.localStorage.getItem('pictalk-data'));
Expand Down Expand Up @@ -40,4 +52,6 @@ export function createDatabaseForUser(username) {
});
}
return db.open();
}
}

initializeDatabase();
Loading

0 comments on commit 28edb68

Please sign in to comment.