Skip to content

Commit

Permalink
Try to fix embed saving
Browse files Browse the repository at this point in the history
  • Loading branch information
krystof-k committed Sep 17, 2024
1 parent 8f5e5b4 commit 6f105cb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
36 changes: 21 additions & 15 deletions frontend/src/routes/result/ResultPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -106,21 +106,27 @@ const handleShareClick = () => {
shareModal.value?.open();
};
onBeforeMount(async () => {
if (userStore.user || userStore.user === null) {
const res = await electionStore.saveResults({
embedName: currentEmbed,
user: userStore.user as User | null | undefined,
});
console.debug(res);
} else {
userStore.$subscribe(async (mutation, state) => {
const res = await electionStore.saveResults({
embedName: currentEmbed,
user: state.user as User | null | undefined,
});
console.debug(res);
});
}
// if (userStore.user || userStore.user === null) {
// const res = await electionStore.saveResults({
// embedName: currentEmbed,
// user: userStore.user as User | null | undefined,
// });
// console.debug(res);
// } else {
// userStore.$subscribe(async (mutation, state) => {
// const res = await electionStore.saveResults({
// embedName: currentEmbed,
// user: state.user as User | null | undefined,
// });
// console.debug(res);
// });
// }
const res = await electionStore.saveResults({
embedName: currentEmbed,
user: userStore.user as User | null | undefined,
});
console.debug(res);
});
const signUpParams = computed(() => {
Expand Down
20 changes: 10 additions & 10 deletions frontend/src/stores/electionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,16 @@ export const useElectionStore = defineStore('election', {
embedName: string | undefined;
user: User | null | undefined;
}) {
if (user) {
const res = await fetch('/api/answers');
const answers = await res.json();
const calculatorAnswers = answers.filter(
(answer: any) => answer.calculatorId === this.calculator?.id,
);
if (calculatorAnswers.length > 0) {
this.resultsId = calculatorAnswers[0].id;
}
}
// if (user) {
// const res = await fetch('/api/answers');
// const answers = await res.json();
// const calculatorAnswers = answers.filter(
// (answer: any) => answer.calculatorId === this.calculator?.id,
// );
// if (calculatorAnswers.length > 0) {
// this.resultsId = calculatorAnswers[0].id;
// }
// }

//if results already saved do not save them again
const newEncodedResults = encodeResults(this.answers);
Expand Down

0 comments on commit 6f105cb

Please sign in to comment.