try to fix examstore value change between pages, improve & add loading screen

This commit is contained in:
NetMan 2025-03-08 14:49:02 +01:00
parent 652550a41d
commit 64fe08f749
4 changed files with 52 additions and 22 deletions

View file

@ -75,9 +75,11 @@ const abc_model = defineModel();
<style scoped> <style scoped>
label { label {
@apply cursor-pointer flex flex-row gap-2 items-center; @apply cursor-pointer flex flex-row gap-2 items-center;
&:hover {
@apply bg-slate-200;
}
} }
span {
label:hover { @apply text-lg;
@apply bg-slate-200;
} }
</style> </style>

View file

@ -101,6 +101,11 @@ async function next() {
} }
if (countAdvanced.value + 1 < dataAdvanced.value?.length!) { if (countAdvanced.value + 1 < dataAdvanced.value?.length!) {
countAdvanced.value++; countAdvanced.value++;
useHead({
title: `Pytanie ${countAdvanced.value + 1}/${
dataAdvanced.value?.length
}`,
});
} }
if (countAdvanced.value == dataAdvanced.value?.length! - 1) { if (countAdvanced.value == dataAdvanced.value?.length! - 1) {
ending.value = true; ending.value = true;
@ -110,12 +115,13 @@ async function next() {
} }
function endExam() { function endExam() {
loading.value = true;
while (!ending.value) { while (!ending.value) {
next(); next();
} }
next(); next();
examStore.result = result.value; examStore.setResult(result.value);
examStore.end = true; examStore.setEnd(true);
return navigateTo("/result", { replace: true }); return navigateTo("/result", { replace: true });
} }
@ -149,10 +155,12 @@ const result: Ref<ResultEndType> = ref({
basic: [], basic: [],
advanced: [], advanced: [],
}); });
const loading = ref(false);
</script> </script>
<template> <template>
<div> <div>
<Loading v-if="loading" />
<div v-if="statusBasic === 'success' && statusAdvanced === 'success'"> <div v-if="statusBasic === 'success' && statusAdvanced === 'success'">
<div class="grid grid-cols-4 min-h-dvh"> <div class="grid grid-cols-4 min-h-dvh">
<div class="col-span-3 flex flex-col gap-4"> <div class="col-span-3 flex flex-col gap-4">

View file

@ -14,30 +14,36 @@ const categories = [
"PT", "PT",
]; ];
const loading = ref(false);
const examStore = useExamStore(); const examStore = useExamStore();
function setAndGo(category: string) { function setAndGo(category: string) {
examStore.category = category; loading.value = true;
examStore.setCategory(category);
return navigateTo("/exam"); return navigateTo("/exam");
} }
</script> </script>
<template> <template>
<div class="text-3xl"> <div>
<span>Test na prawo jazdy</span> <div v-if="!loading" class="text-3xl">
<p> <span>Test na prawo jazdy</span>
Witaj w teście na prawo jazdy, aby rozpocząć, naciśnij jeden z poniższych <p>
przycisków: Witaj w teście na prawo jazdy, aby rozpocząć, naciśnij jeden z
<br /> poniższych przycisków:
</p> <br />
<div class="flex flex-row flex-wrap gap-2"> </p>
<button <div class="flex flex-row flex-wrap gap-2">
class="btn btn-xl btn-secondary" <button
v-for="category in categories" class="btn btn-xl btn-secondary"
@click="setAndGo(category)" v-for="category in categories"
> @click="setAndGo(category)"
{{ category }} >
</button> {{ category }}
</button>
</div>
</div> </div>
<Loading v-else />
</div> </div>
</template> </template>

View file

@ -18,12 +18,26 @@ export const useExamStore = defineStore("exam-store", () => {
advanced: [], advanced: [],
}; };
} }
function setEnd(value: boolean) {
end.value = value;
return end.value;
}
function setCategory(value: string) {
category.value = value;
return category.value;
}
function setResult(value: ResultEndType) {
result.value = value;
return result.value;
}
return { return {
category, category,
end, end,
result, result,
resetExam, resetExam,
mildReset, mildReset,
setEnd,
setCategory,
setResult,
}; };
}); });