Skip to content

Commit

Permalink
fix: layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhJae committed Sep 3, 2024
1 parent 5bf2853 commit f0088d5
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 46 deletions.
2 changes: 1 addition & 1 deletion layouts/train.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<template>
<slot/>
<slot />
</template>
4 changes: 4 additions & 0 deletions pages/train/character-guesstimate.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { CharactorGuesstimateResult } from "~/types/result";
import { stimuliCharactorSets } from "~/utils/util";
import { playSound } from "~/utils/playSound";
definePageMeta({
layout: "train",
});
const { t } = useI18n();
// Vue Router
Expand Down
4 changes: 4 additions & 0 deletions pages/train/character-matching.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { playSound } from "~/utils/playSound";
import { jsonToProcedure, CharacterMatchingProcedure } from "~/types/procedure";
import { CharactorMatchingResult } from "~/types/result";
definePageMeta({
layout: "train",
});
// Vue Router
const route = useRoute();
const router = useRouter();
Expand Down
4 changes: 4 additions & 0 deletions pages/train/character-sequencing.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
} from "~/types/procedure";
import { CharactorSequenceingResult } from "~/types/result";
definePageMeta({
layout: "train",
});
const { t } = useI18n();
// Vue Router
Expand Down
89 changes: 44 additions & 45 deletions pages/train/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup lang="ts">
import {ref, computed, watch} from "vue";
import {useRouter} from "vue-router";
import { ref, computed, watch } from "vue";
import { useRouter } from "vue-router";
import {
RapidVisualPerceptionProcedure,
SequentialVisualMemoryProcedure,
Expand All @@ -9,10 +9,10 @@ import {
CharacterGuesstimateProcedure,
Procedure,
} from "~/types/procedure";
import {Parameter, NumParameter, SelectParameter} from "~/types/parameter";
import type {FormError, FormErrorEvent} from "#ui/types";
import { Parameter, NumParameter, SelectParameter } from "~/types/parameter";
import type { FormError, FormErrorEvent } from "#ui/types";
const {t} = useI18n();
const { t } = useI18n();
const router = useRouter();
Expand All @@ -30,20 +30,20 @@ const selectedProcedureName = ref<string>(trainingProcedures[0].name);
// Track selected training procedure parameters
const selectedTrainingParameters = ref<Parameter[]>(
trainingProcedures[0].parameters
trainingProcedures[0].parameters
);
// Compute selected training procedure
const selectedTrainingProcedure = computed<Procedure | undefined>(() =>
trainingProcedures.find(
(procedure) => procedure.name === selectedProcedureName.value
)
trainingProcedures.find(
(procedure) => procedure.name === selectedProcedureName.value
)
);
// Watch for changes in selectedProcedureName to update parameters
watch(selectedProcedureName, (newProcedureName) => {
const procedure = trainingProcedures.find(
(procedure) => procedure.name === newProcedureName
(procedure) => procedure.name === newProcedureName
);
if (procedure) {
selectedTrainingParameters.value = procedure.parameters;
Expand All @@ -55,11 +55,11 @@ const validateForm = (state: { parameters: Parameter[] }): FormError[] => {
const errors: FormError[] = [];
state.parameters.forEach((parameter) => {
if (parameter instanceof SelectParameter && !parameter.selected) {
errors.push({path: parameter.displayName, message: "Required"});
errors.push({ path: parameter.displayName, message: "Required" });
}
if (parameter instanceof NumParameter) {
if (parameter.value == null) {
errors.push({path: parameter.displayName, message: "Required"});
errors.push({ path: parameter.displayName, message: "Required" });
}
if (parameter.min !== undefined && parameter.value < parameter.min) {
errors.push({
Expand All @@ -84,11 +84,11 @@ const handleFormSubmit = async () => {
const jsonString = JSON.stringify(selectedTrainingProcedure.value.toJson());
console.log("Starting training with data:", jsonString);
const routeName = selectedTrainingProcedure.value.name
.toLowerCase()
.replace(/ /g, "-");
.toLowerCase()
.replace(/ /g, "-");
router.push({
name: `train-${routeName}`,
query: {data: encodeURIComponent(jsonString)},
query: { data: encodeURIComponent(jsonString) },
});
}
};
Expand All @@ -97,7 +97,7 @@ const handleFormSubmit = async () => {
const handleFormError = async (event: FormErrorEvent) => {
const element = document.getElementById(event.errors[0].id);
element?.focus();
element?.scrollIntoView({behavior: "smooth", block: "center"});
element?.scrollIntoView({ behavior: "smooth", block: "center" });
};
</script>

Expand All @@ -106,69 +106,68 @@ const handleFormError = async (event: FormErrorEvent) => {
<Title>{{ t("nav.train") }}</Title>
</Head>
<UForm
v-if="selectedTrainingProcedure"
:validate="validateForm"
:state="{ parameters: selectedTrainingParameters }"
class="space-y-4"
@submit="handleFormSubmit"
@error="handleFormError"
v-if="selectedTrainingProcedure"
:validate="validateForm"
:state="{ parameters: selectedTrainingParameters }"
class="space-y-4"
@submit="handleFormSubmit"
@error="handleFormError"
>
<UCard class="mx-auto mt-8 max-w-md">
<template #header>
<h2 class="text-lg font-semibold pb-2">
{{ $t("train.title") }}
</h2>
<USelectMenu
v-model="selectedProcedureName"
:options="
v-model="selectedProcedureName"
:options="
trainingProcedures.map((p) => ({
label: $t('procedure.' + p.name),
value: p.name,
}))
"
option-attribute="label"
value-attribute="value"
option-attribute="label"
value-attribute="value"
/>
</template>

<div
v-for="parameter in selectedTrainingParameters"
:key="parameter.displayName"
class="py-2"
v-for="parameter in selectedTrainingParameters"
:key="parameter.displayName"
class="py-2"
>
<UFormGroup
:label="t(parameter.displayName)"
:name="parameter.displayName"
:label="t(parameter.displayName)"
:name="parameter.displayName"
>
<UInput
v-if="parameter instanceof NumParameter"
v-model="parameter.value"
type="number"
:min="parameter.min"
:max="parameter.max"
:step="parameter.step"
v-if="parameter instanceof NumParameter"
v-model="parameter.value"
type="number"
:min="parameter.min"
:max="parameter.max"
:step="parameter.step"
/>

<USelectMenu
v-else-if="parameter instanceof SelectParameter"
v-model="parameter.selected"
:options="
v-else-if="parameter instanceof SelectParameter"
v-model="parameter.selected"
:options="
parameter.options.map((option) => ({
label: $t('parameter.' + option),
value: option,
}))
"
option-attribute="label"
value-attribute="value"
option-attribute="label"
value-attribute="value"
/>
</UFormGroup>
</div>

<template #footer>
<div class="flex justify-center space-x-4 pb-4">
<UButton color="primary" type="submit">{{
$t("train.start")
}}
<UButton color="primary" type="submit"
>{{ $t("train.start") }}
</UButton>
</div>
<!-- <UAlert
Expand Down
4 changes: 4 additions & 0 deletions pages/train/rapid-visual-perception.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { stimuliCharactorSets } from "~/utils/util";
import { RapidVisualPerceptionProcedureResult } from "~/types/result";
import { playSound } from "~/utils/playSound";
definePageMeta({
layout: "train",
});
// Vue Router
const route = useRoute();
const router = useRouter();
Expand Down
4 changes: 4 additions & 0 deletions pages/train/sequential-visual-memory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { SequentialVisualMemoryResult } from "~/types/result";
import { stimuliCharactorSets } from "~/utils/util";
import { playSound } from "~/utils/playSound";
definePageMeta({
layout: "train",
});
const { t } = useI18n();
// Vue Router
Expand Down

0 comments on commit f0088d5

Please sign in to comment.