11<script setup lang="ts">
2- import type { Question } from ' ~/types'
2+ import type { Question , AnswerOption } from ' ~/types'
33
44definePageMeta ({
55 middleware: ' auth'
66})
77
88const activeQuestion = ref <Question | null >(null )
99const allQuestions = ref <Question []>([])
10- const newQuestion = ref ({
10+ const newQuestion = ref <{
11+ question_text: string
12+ answer_options: AnswerOption []
13+ }>({
1114 question_text: ' ' ,
12- answer_options: [' ' , ' ' ]
15+ answer_options: [{ text: ' ' }, { text: ' ' } ]
1316})
1417
1518// Load questions
@@ -44,7 +47,12 @@ async function handleLogout() {
4447async function handleCreateQuestion() {
4548 try {
4649 // Filter out empty options
47- const filteredOptions = newQuestion .value .answer_options .filter ((opt : string ) => opt .trim ())
50+ const filteredOptions = newQuestion .value .answer_options
51+ .map (opt => ({
52+ text: opt .text .trim (),
53+ emoji: opt .emoji ?.trim () || undefined
54+ }))
55+ .filter (opt => opt .text )
4856
4957 if (filteredOptions .length < 2 ) {
5058 alert (' At least 2 answer options required' )
@@ -64,7 +72,7 @@ async function handleCreateQuestion() {
6472 // Reset form
6573 newQuestion .value = {
6674 question_text: ' ' ,
67- answer_options: [' ' , ' ' ]
75+ answer_options: [{ text: ' ' }, { text: ' ' } ]
6876 }
6977
7078 // alert('Question created successfully')
@@ -111,7 +119,7 @@ async function toggleLock() {
111119
112120// Add option
113121function addOption() {
114- newQuestion .value .answer_options .push (' ' )
122+ newQuestion .value .answer_options .push ({ text: ' ' } )
115123}
116124
117125// Remove option
@@ -136,7 +144,7 @@ function removeOption(index: number) {
136144 <p class =" text-lg mb-4 font-bold" >{{ activeQuestion.question_text }}</p >
137145 <ul class =" list-none p-0 mb-5" >
138146 <li v-for =" (option, index) in activeQuestion.answer_options" :key =" index" class =" p-2.5 bg-white border border-black mb-1.5" >
139- {{ option }}
147+ {{ option.text }} < span v-if = " option.emoji " >{{ option.emoji }}</ span >
140148 </li >
141149 </ul >
142150 <div class =" flex justify-between items-center" >
@@ -173,11 +181,18 @@ function removeOption(index: number) {
173181 <h3 class =" mb-2.5 text-lg" >Answer Options</h3 >
174182 <div v-for =" (option, index) in newQuestion.answer_options" :key =" index" class =" flex gap-2.5 mb-2.5" >
175183 <UiInput
176- v-model =" newQuestion.answer_options[index]! "
184+ v-model =" option.text "
177185 :placeholder =" `Option ${index + 1}`"
178186 required
179187 class =" flex-1"
180188 />
189+ <UiInput
190+ :model-value =" option.emoji || ''"
191+ placeholder =" Emoji"
192+ class =" w-24"
193+ maxlength =" 10"
194+ @update:model-value =" option.emoji = String($event || '').trim() || undefined"
195+ />
181196 <UiButton
182197 v-if =" newQuestion.answer_options.length > 2"
183198 variant =" danger"
@@ -208,7 +223,7 @@ function removeOption(index: number) {
208223 <p class =" font-bold mb-2.5" >{{ question.question_text }}</p >
209224 <ul class =" list-disc list-inside p-0 mb-4" >
210225 <li v-for =" (option, index) in question.answer_options" :key =" index" >
211- {{ option }}
226+ {{ option.text }} < span v-if = " option.emoji " >{{ option.emoji }}</ span >
212227 </li >
213228 </ul >
214229 <UiButton @click =" publishQuestion(question.id)" >
0 commit comments