Skip to content

Commit b62f48c

Browse files
authored
feat: Add note functionality for questions (#23)
1 parent d3e7b46 commit b62f48c

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

app/pages/admin.vue

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ const allQuestions = ref<Question[]>([])
1010
const newQuestion = ref<{
1111
question_text: string
1212
answer_options: AnswerOption[]
13+
note?: string
1314
}>({
1415
question_text: '',
15-
answer_options: [{ text: '' }, { text: '' }]
16+
answer_options: [{ text: '' }, { text: '' }],
17+
note: ''
1618
})
1719
1820
// Load questions
@@ -63,7 +65,8 @@ async function handleCreateQuestion() {
6365
method: 'POST',
6466
body: {
6567
question_text: newQuestion.value.question_text,
66-
answer_options: filteredOptions
68+
answer_options: filteredOptions,
69+
note: newQuestion.value.note
6770
}
6871
})
6972
@@ -72,7 +75,8 @@ async function handleCreateQuestion() {
7275
// Reset form
7376
newQuestion.value = {
7477
question_text: '',
75-
answer_options: [{ text: '' }, { text: '' }]
78+
answer_options: [{ text: '' }, { text: '' }],
79+
note: ''
7680
}
7781
7882
// alert('Question created successfully')
@@ -177,6 +181,12 @@ function removeOption(index: number) {
177181
class="p-3 border-2 border-black text-base min-h-[100px] resize-y bg-white font-sans"
178182
></textarea>
179183

184+
<textarea
185+
v-model="newQuestion.note"
186+
placeholder="Enter a note for the question (optional, only for admins)"
187+
class="p-3 border-2 border-black text-base min-h-[70px] resize-y bg-white font-sans"
188+
></textarea>
189+
180190
<div>
181191
<h3 class="mb-2.5 text-lg">Answer Options</h3>
182192
<div v-for="(option, index) in newQuestion.answer_options" :key="index" class="flex gap-2.5 mb-2.5">
@@ -221,6 +231,7 @@ function removeOption(index: number) {
221231
:class="{ 'opacity-50': question.alreadyPublished }"
222232
>
223233
<p class="font-bold mb-2.5">{{ question.question_text }}</p>
234+
<p v-if="question.note" class="text-sm text-gray-600 mb-2.5 p-2 bg-gray-200 border border-black">{{ question.note }}</p>
224235
<ul class="list-disc list-inside p-0 mb-4">
225236
<li v-for="(option, index) in question.answer_options" :key="index">
226237
{{ option.text }} <span v-if="option.emoji">{{ option.emoji }}</span>

app/pages/index.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ async function submitAnswer() {
103103
}
104104
}
105105
}
106-
107-
108106
</script>
109107

110108
<template>

app/pages/results.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ function getPercentage(count: number) {
135135
</div>
136136
</div>
137137
</div>
138+
139+
<!-- Note Display -->
140+
<div v-if="results.question.note && !hideResults" class="mt-8 p-4 bg-gray-100 border-2 border-black">
141+
<p>{{ results.question.note }}</p>
142+
</div>
138143
</UiSection>
139144

140145
<!-- No Active Question -->

app/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ export interface Question {
1010
is_locked: boolean
1111
createdAt: string
1212
alreadyPublished: boolean
13+
note?: string
1314
}
1415

15-
export type UserQuestion = Omit<Question, 'answer_options'> & {
16+
export type UserQuestion = Omit<Question, 'answer_options' | 'note'> & {
1617
answer_options: string[]
1718
}
1819

server/api/questions/active.get.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ export default defineEventHandler(async (): Promise<UserQuestion | { message: st
44
const question = await getActiveQuestion()
55

66
if (question) {
7-
// Strip emojis from answer options before sending to the client
7+
// Strip emojis and notes from the question before sending to the client
8+
const { note, ...questionForUser } = question
89
return {
9-
...question,
10+
...questionForUser,
1011
answer_options: question.answer_options.map(option => option.text)
1112
}
1213
}

server/api/questions/create.post.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default defineEventHandler(async (event) => {
44
verifyAdmin(event)
55

66
const body = await readBody(event) as Omit<Question, 'id' | 'is_locked'>
7-
const { question_text: raw_question_text, answer_options: raw_answer_options } = body
7+
const { question_text: raw_question_text, answer_options: raw_answer_options, note: raw_note } = body
88

99
// Validate and sanitize question_text
1010
const question_text = typeof raw_question_text === 'string' ? raw_question_text.trim() : ''
@@ -37,9 +37,12 @@ export default defineEventHandler(async (event) => {
3737
})
3838
}
3939

40+
const note = typeof raw_note === 'string' ? raw_note.trim() : undefined
41+
4042
const question = await createQuestion({
4143
question_text,
42-
answer_options
44+
answer_options,
45+
note
4346
})
4447

4548
return question

0 commit comments

Comments
 (0)