Skip to content

Commit 0aa3e63

Browse files
authored
feat: delete answer (#123)
1 parent 6ee8b1b commit 0aa3e63

File tree

7 files changed

+42
-2
lines changed

7 files changed

+42
-2
lines changed

Diff for: src/components/quizzfly/create/answer/Choice.vue

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const props = defineProps<{
1616
1717
const emits = defineEmits<{
1818
(e: 'update:modelValue', value: Answer): void
19+
(e: 'delete', value: Answer): void
1920
}>()
2021
2122
const updateAnswer = useDebounceFn((value: Answer) => {
@@ -32,7 +33,7 @@ onMounted(() => {
3233
</script>
3334
<template>
3435
<div
35-
class="relative flex flex-row-reverse gap-5 py-6 min-h-[120px] items-center px-4 rounded-2xl text-white answer-item"
36+
class="relative flex group flex-row-reverse gap-5 py-6 min-h-[120px] items-center px-4 rounded-2xl text-white answer-item"
3637
:style="{ backgroundColor: colorsHex[index].primary }"
3738
>
3839
<ConfettiExplosion
@@ -44,6 +45,13 @@ onMounted(() => {
4445
class="overlay-wrong absolute top-0 left-0 z-10 w-full h-[calc(100%+4px)] bg-gray-900 bg-opacity-60 rounded-2xl"
4546
></div>
4647

48+
<div
49+
v-if="editMode"
50+
class="absolute group-hover:flex cursor-pointer w-8 h-8 justify-center items-center hidden -top-3 -right-3 bg-white rounded-full shadow-md"
51+
@click="emits('delete', modelValue)"
52+
>
53+
<span class="text-black i-material-symbols-light-close-rounded text-2xl"></span>
54+
</div>
4755
<img
4856
v-if="isShowRightAnswer && modelValue.is_correct"
4957
v-motion

Diff for: src/components/quizzfly/create/answer/TrueFalse.vue

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ defineProps<{
1111
const emits = defineEmits<{
1212
(e: 'select', value: string): void
1313
(e: 'update:modelValue', value: any): void
14+
(e: 'delete', value: any): void
1415
}>()
1516
</script>
1617
<template>
@@ -28,5 +29,6 @@ const emits = defineEmits<{
2829
:is-show-right-answer="isShowRightAnswer"
2930
@select="emits('select', item.id)"
3031
@update:model-value="emits('update:modelValue', item)"
32+
@delete="emits('delete', item)"
3133
/>
3234
</template>

Diff for: src/components/quizzfly/create/quiz/AnswerSetting.vue

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const handleUpdateAnswer = (value: any) => {
3333
is_correct: true,
3434
})
3535
}
36+
37+
const handleDeleteAnswer = (value: any) => {
38+
questionsStore.deleteCurrentQuestionAnswer(value)
39+
}
3640
</script>
3741
<template>
3842
<div class="pb-8">
@@ -55,6 +59,7 @@ const handleUpdateAnswer = (value: any) => {
5559
:edit-mode="true"
5660
:is-true-false="false"
5761
@update:model-value="questionsStore.updateCurrentQuestionAnswer"
62+
@delete="handleDeleteAnswer"
5863
/>
5964
</template>
6065

@@ -63,6 +68,7 @@ const handleUpdateAnswer = (value: any) => {
6368
:edit-mode="true"
6469
:answers="currentQuestion.answers"
6570
@update:model-value="handleUpdateAnswer"
71+
@delete="handleDeleteAnswer"
6672
/>
6773
</template>
6874
</div>

Diff for: src/pages/groups/index.vue

+7
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ const pageQueryComputed = computed({
3939
},
4040
})
4141
42+
watch(
43+
() => search.value,
44+
() => {
45+
fetchGroups()
46+
},
47+
)
48+
4249
const fetchGroups = () => {
4350
groupStore.fetchGroups({
4451
page: pageQueryComputed.value,

Diff for: src/pages/room/member-play/instructions-play.vue

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ onBeforeMount(() => {
6262
console.log('name', name, 'roomPin', roomPin)
6363
const participant_id = localStorage.getItem('participantID')
6464
participantId.value = participant_id || ''
65+
console.log('participant_id', participant_id)
6566
const joinRoomData: any = {
6667
nick_name: name,
6768
room_pin: roomPin,

Diff for: src/services/group.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const getGroupsApi = async ({ page = 1, keyword = '' }): Promise<BaseResp
1313
method: 'GET',
1414
params: {
1515
page,
16-
keyword,
16+
keywords: keyword,
1717
},
1818
})
1919
}

Diff for: src/stores/quizzfly/question.ts

+16
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,22 @@ export const useQuestionsStore = defineStore({
364364
throw error
365365
}
366366
},
367+
368+
async deleteCurrentQuestionAnswer(answer: Answer) {
369+
// Delete a specific answer in the current question
370+
try {
371+
await deleteAnswerApi(answer.id)
372+
this.updateCurrentQuestionAnswers(
373+
(this.currentQuestion as Quiz).answers?.filter((a) => a.id !== answer.id) || [],
374+
)
375+
} catch (error) {
376+
console.error(error)
377+
showToast({
378+
description: apiError(error).message,
379+
variant: 'destructive',
380+
})
381+
}
382+
},
367383
},
368384
getters: {
369385
getSlideById: (state) => (id: string) => {

0 commit comments

Comments
 (0)