1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
import React from 'react'
import {UpkQuestion} from "@/api";
import {UpkQuestionChoice} from "@/api/models/upk-question-choice.ts";
import {Card, CardContent, CardHeader} from "@/components/ui/card.tsx";
import {useAppSelector} from "@/hooks.ts";
const TextEntry: React.FC<{ question: UpkQuestion }> = ({question}) => {
// const dispatch = useAppDispatch()
// const buckets = useAppSelector(state => state.buckets)
// const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
// // Don't allow any input changes after they triggered submission...
// if (question._complete || question._processing) {
// return
// }
//
// // Assign the input value as an answer to the question
// const newValue = event.target.value;
// dispatch(setAnswer({questionId: question.questionId, val: newValue}))
// };
return (
<Card className="@container/card">
<CardHeader>
{question.question_text}
</CardHeader>
<CardContent>
<input type="text"
id="text-entry-input"
aria-describedby=""
placeholder=""
// onInput={handleInputChange}
/>
{/*<small id="text-entry-msg">{question.error_msg}</small>*/}
</CardContent>
</Card>
)
}
const MultiChoiceItem: React.FC<{ question: UpkQuestion, choice: UpkQuestionChoice }> = ({question, choice}) => {
// const onclick = function () {
// // Assign the input value as an answer to the question
// let answer = getAnswer;
// let click_value = childView.model.get("choice_id")
//
// switch (question.selector) {
//
// case "SA": /// Single Answer
// answer.set("values", [{"value": click_value}]);
// break
//
// case "MA": /// Multi Answer
// let current_values: AnswerValueItemType[] = answer.get("values") ?? [];
//
// if (includes(map(current_values, "value"), click_value)) {
// // The item has already been selected
// current_values = remove(current_values, (v) => {
// return v["value"] != click_value
// })
//
// } else {
// // It's a new selection
// current_values.push({"value": click_value})
// }
//
// answer.set("values", current_values);
// break
// }
// childView.render();
//
// // Validate the answer and show any information
// let res: QuestionValidationResult = this.model.validateAnswer()
// this.ui.message.text(res["message"]);
// }
// const render = function () {
// let answer = this.getOption("answer");
// let current_values: AnswerValueItemType[] = answer.get("values") ?? [];
// let current_values_values = map(current_values, "value");
//
// if (includes(current_values_values, this.model.get("choice_id"))) {
// this.$el.addClass("selected");
// }
// }
return (
<>
{choice.choice_text}
</>
)
}
const MultipleChoice: React.FC<{ question: UpkQuestion }> = ({question}) => {
return (
<Card>
<CardHeader>
{question.question_text}
{/*<small id="text-entry-msg">{question.error_msg}</small>*/}
</CardHeader>
<CardContent>
{
question.choices.map(c => {
return <MultiChoiceItem key={`${question.question_id}-${c.choice_id}`} question={question} choice={c}/>
})
}
</CardContent>
</Card>
)
}
const ProfileQuestionFull: React.FC<UpkQuestion> = ({question}) => {
switch (question.question_type) {
case "TE":
return <TextEntry question={question}/>
case "MC":
return <MultipleChoice question={question}/>
default:
throw new Error("Incorrect Question Type provided");
}
}
const QuestionsPage = () => {
const questions = useAppSelector(state => state.questions)
return (
<div>
<p>
A total of {questions.length} questions are available.
</p>
{
questions.map(q => {
return <ProfileQuestionFull key={q.question_id} question={q} className="mt-4 mb-4"/>;
})
}
</div>
);
}
export {
QuestionsPage
}
|