13
13
<div class =" whitespace-pre-wrap mt-14" >
14
14
<ul >
15
15
<li
16
- v-for =" (question , index) in questions"
16
+ v-for =" (item , index) in questions"
17
17
:key =" index"
18
18
class =" mb-2.5 cursor-pointer text-primary-yellow underline"
19
- @click.prevent =" questionClicked(question)"
19
+ :class =" {'text-yellow-300 font-bold': item.selected}"
20
+ @click.prevent =" questionClicked(item)"
20
21
>
21
- {{ question }}
22
+ {{ item. question }}
22
23
</li >
23
24
</ul >
24
25
</div >
@@ -42,18 +43,30 @@ const props = defineProps({
42
43
43
44
const emit = defineEmits ([' questionClicked' ]);
44
45
45
- const questions = ref ([]);
46
+ const questions = ref (JSON . parse ( localStorage . getItem ( ' questions ' )) || []);
46
47
const loading = ref (false );
47
48
48
49
onMounted (() => {
49
- loading .value = true ;
50
- axios .post (' /student/prompts/questions' , {question: props .question }).then (response => {
51
- questions .value = response .data .questions ;
52
- loading .value = false ;
53
- });
50
+ if (questions .value .length === 0 ) {
51
+ loading .value = true ;
52
+
53
+ axios .post (' /student/prompts/questions' , {question: props .question }).then (response => {
54
+ questions .value = response .data .questions ;
55
+ loading .value = false ;
56
+ });
57
+ }
54
58
});
55
59
56
- const questionClicked = (question ) => {
57
- emit (' questionClicked' , question);
60
+ const questionClicked = (item ) => {
61
+ const formattedQuestions = questions .value .map ((q , index ) => {
62
+ return {
63
+ ' question' : q .question ,
64
+ ' selected' : q .question === item .question || q .selected
65
+ }
66
+ });
67
+
68
+ localStorage .setItem (' questions' , JSON .stringify (formattedQuestions));
69
+
70
+ emit (' questionClicked' , {question: item .question });
58
71
}
59
72
</script >
0 commit comments