Skip to content

Commit

Permalink
convert to compositionAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
NiloCK committed Jan 13, 2025
1 parent 8ae2589 commit ed36391
Showing 1 changed file with 51 additions and 18 deletions.
69 changes: 51 additions & 18 deletions packages/vue/src/courses/math/questions/division/horizontal.vue
Original file line number Diff line number Diff line change
@@ -1,30 +1,63 @@
<template>
<div>
{{ question.a * question.b }} &divide; {{ question.b }} =
<UserInputNumber />
<div data-viewable="DivisionHorizontal">
<template v-if="question">
{{ question.a * question.b }} &divide; {{ question.b }} =
<UserInputNumber v-model="answer" />
</template>
</div>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';
import { QuestionView } from '@/base-course/Viewable';
import { defineComponent, ref, computed, PropType } from 'vue';
import { SingleDigitDivisionQuestion } from './index';
import { useViewable, useQuestionView } from '@/base-course/CompositionViewable';
import { ViewData } from '@/base-course/Interfaces/ViewData';
import UserInputNumber from '@/base-course/Components/UserInput/UserInputNumber.vue';
@Component({
export default defineComponent({
name: 'DivisionHorizontal',
components: {
UserInputNumber,
},
})
export default class DivisionHorizontal extends QuestionView<SingleDigitDivisionQuestion> {
public answer: string = '';
public submit() {
alert(this.question.isCorrect(parseInt(this.answer, 10)));
}
get question() {
return new SingleDigitDivisionQuestion(this.data);
}
}
props: {
data: {
type: Array as PropType<ViewData[]>,
required: true,
},
modifyDifficulty: {
type: Number,
required: false,
},
},
setup(props, { emit }) {
const viewableUtils = useViewable(props, emit, 'DivisionHorizontal');
const questionUtils = useQuestionView<SingleDigitDivisionQuestion>(viewableUtils, props.modifyDifficulty);
const answer = ref('');
// Initialize question immediately
questionUtils.question.value = new SingleDigitDivisionQuestion(props.data);
// Expose the question directly for template access
const question = computed(() => questionUtils.question.value);
const submit = () => {
if (question.value) {
const isCorrect = question.value.isCorrect(parseInt(answer.value, 10));
alert(isCorrect);
}
};
return {
...viewableUtils,
...questionUtils,
answer,
question,
submit,
};
},
});
</script>

0 comments on commit ed36391

Please sign in to comment.