Skip to content

feat: delete answer #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/quizzfly/create/answer/Choice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const props = defineProps<{

const emits = defineEmits<{
(e: 'update:modelValue', value: Answer): void
(e: 'delete', value: Answer): void
}>()

const updateAnswer = useDebounceFn((value: Answer) => {
Expand All @@ -32,7 +33,7 @@ onMounted(() => {
</script>
<template>
<div
class="relative flex flex-row-reverse gap-5 py-6 min-h-[120px] items-center px-4 rounded-2xl text-white answer-item"
class="relative flex group flex-row-reverse gap-5 py-6 min-h-[120px] items-center px-4 rounded-2xl text-white answer-item"
:style="{ backgroundColor: colorsHex[index].primary }"
>
<ConfettiExplosion
Expand All @@ -44,6 +45,13 @@ onMounted(() => {
class="overlay-wrong absolute top-0 left-0 z-10 w-full h-[calc(100%+4px)] bg-gray-900 bg-opacity-60 rounded-2xl"
></div>

<div
v-if="editMode"
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"
@click="emits('delete', modelValue)"
>
<span class="text-black i-material-symbols-light-close-rounded text-2xl"></span>
</div>
<img
v-if="isShowRightAnswer && modelValue.is_correct"
v-motion
Expand Down
2 changes: 2 additions & 0 deletions src/components/quizzfly/create/answer/TrueFalse.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defineProps<{
const emits = defineEmits<{
(e: 'select', value: string): void
(e: 'update:modelValue', value: any): void
(e: 'delete', value: any): void
}>()
</script>
<template>
Expand All @@ -28,5 +29,6 @@ const emits = defineEmits<{
:is-show-right-answer="isShowRightAnswer"
@select="emits('select', item.id)"
@update:model-value="emits('update:modelValue', item)"
@delete="emits('delete', item)"
/>
</template>
6 changes: 6 additions & 0 deletions src/components/quizzfly/create/quiz/AnswerSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ const handleUpdateAnswer = (value: any) => {
is_correct: true,
})
}

const handleDeleteAnswer = (value: any) => {
questionsStore.deleteCurrentQuestionAnswer(value)
}
</script>
<template>
<div class="pb-8">
Expand All @@ -55,6 +59,7 @@ const handleUpdateAnswer = (value: any) => {
:edit-mode="true"
:is-true-false="false"
@update:model-value="questionsStore.updateCurrentQuestionAnswer"
@delete="handleDeleteAnswer"
/>
</template>

Expand All @@ -63,6 +68,7 @@ const handleUpdateAnswer = (value: any) => {
:edit-mode="true"
:answers="currentQuestion.answers"
@update:model-value="handleUpdateAnswer"
@delete="handleDeleteAnswer"
/>
</template>
</div>
Expand Down
7 changes: 7 additions & 0 deletions src/pages/groups/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ const pageQueryComputed = computed({
},
})

watch(
() => search.value,
() => {
fetchGroups()
},
)

const fetchGroups = () => {
groupStore.fetchGroups({
page: pageQueryComputed.value,
Expand Down
1 change: 1 addition & 0 deletions src/pages/room/member-play/instructions-play.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ onBeforeMount(() => {
console.log('name', name, 'roomPin', roomPin)
const participant_id = localStorage.getItem('participantID')
participantId.value = participant_id || ''
console.log('participant_id', participant_id)
const joinRoomData: any = {
nick_name: name,
room_pin: roomPin,
Expand Down
2 changes: 1 addition & 1 deletion src/services/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getGroupsApi = async ({ page = 1, keyword = '' }): Promise<BaseResp
method: 'GET',
params: {
page,
keyword,
keywords: keyword,
},
})
}
Expand Down
16 changes: 16 additions & 0 deletions src/stores/quizzfly/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,22 @@ export const useQuestionsStore = defineStore({
throw error
}
},

async deleteCurrentQuestionAnswer(answer: Answer) {
// Delete a specific answer in the current question
try {
await deleteAnswerApi(answer.id)
this.updateCurrentQuestionAnswers(
(this.currentQuestion as Quiz).answers?.filter((a) => a.id !== answer.id) || [],
)
} catch (error) {
console.error(error)
showToast({
description: apiError(error).message,
variant: 'destructive',
})
}
},
},
getters: {
getSlideById: (state) => (id: string) => {
Expand Down
Loading