feat: antwoorden kunnen gepost worden
This commit is contained in:
parent
7d881e6c35
commit
ff702de379
1 changed files with 23 additions and 5 deletions
|
@ -1,10 +1,11 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { useAnswersQuery } from "@/queries/answers";
|
import { useAnswersQuery, useCreateAnswerMutation } from "@/queries/answers";
|
||||||
import type { QuestionDTO, QuestionId } from "@dwengo-1/common/interfaces/question";
|
import type { QuestionDTO, QuestionId } from "@dwengo-1/common/interfaces/question";
|
||||||
import { computed, ref } from "vue";
|
import { computed, ref } from "vue";
|
||||||
import UsingQueryResult from "./UsingQueryResult.vue";
|
import UsingQueryResult from "./UsingQueryResult.vue";
|
||||||
import type { AnswersResponse } from "@/controllers/answers";
|
import type { AnswersResponse } from "@/controllers/answers";
|
||||||
import type { AnswerDTO } from "@dwengo-1/common/interfaces/answer";
|
import type { AnswerData, AnswerDTO } from "@dwengo-1/common/interfaces/answer";
|
||||||
|
import authService from "@/services/auth/auth-service";
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
question: QuestionDTO;
|
question: QuestionDTO;
|
||||||
|
@ -29,11 +30,28 @@
|
||||||
}) as QuestionId,
|
}) as QuestionId,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const questionId : QuestionId = {
|
||||||
|
learningObjectIdentifier: props.question.learningObjectIdentifier,
|
||||||
|
sequenceNumber: props.question.sequenceNumber as number
|
||||||
|
};
|
||||||
|
const createAnswerMutation = useCreateAnswerMutation(questionId);
|
||||||
|
|
||||||
const answer = ref('')
|
const answer = ref('');
|
||||||
|
|
||||||
function submitAnswer() {
|
function submitAnswer() {
|
||||||
console.log('Submitted answer:', answer.value)
|
const answerData: AnswerData = {
|
||||||
|
author: authService.authState.user?.profile.preferred_username as string,
|
||||||
|
content: answer.value
|
||||||
|
};
|
||||||
|
if (answer.value != "") {
|
||||||
|
createAnswerMutation.mutate(answerData, {
|
||||||
|
onSuccess: () => {answer.value = "";}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
alert("Please type an answer before submitting") //TODO: i18n
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
|
@ -61,7 +79,7 @@
|
||||||
>
|
>
|
||||||
{{ question.content }}
|
{{ question.content }}
|
||||||
</div>
|
</div>
|
||||||
<div class="answer-input-container">
|
<div v-if="(authService.authState.activeRole === 'teacher')" class="answer-input-container">
|
||||||
<input
|
<input
|
||||||
v-model="answer"
|
v-model="answer"
|
||||||
type="text"
|
type="text"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue