-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion.js
More file actions
306 lines (272 loc) · 7.2 KB
/
Question.js
File metadata and controls
306 lines (272 loc) · 7.2 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
import React from 'react';
import { StyleSheet, Text, TextInput, View } from 'react-native';
import { connect } from 'react-redux';
import { saveAnswer } from './logic.js';
import * as strings from './strings';
import OnlineButton from './OnlineButton.js';
class WordCloud extends React.Component {
// props: question: reference to parent Question component
constructor(props) {
super(props);
}
render() {
var wordComponents=[];
let i=1;
for (wordId in this.props.question.questionObjectData.words) {
wordComponents.push(
<WordButtonForWordCloudAnswer key={i} title={this.props.question.questionObjectData.words[wordId]}
question={this.props.question}
/>
);
i++;
}
return (
<View style={question_styles.outer_container}>
<View style={question_styles.wordcloud_container} >
{wordComponents}
</View>
</View>
)
}
}
class WordButtonForWordCloudAnswer extends React.Component {
render() {
return (
<OnlineButton
style={question_styles.wordcloud_button}
onPress={() => this.props.question.submitAnswer(this.props.title)}
>
<Text style={question_styles.button_text}>{this.props.title}</Text>
</OnlineButton>
)
}
}
class Scale5 extends React.Component {
// props: question: reference to parent Question component
constructor(props) {
super(props);
}
render() {
var buttons=[];
for (let i=1; i<=5; i++) {
buttons.push(
<CircularButtonForScaleAnswer key={i} title={i.toString()} question={this.props.question} />
);
}
return (
<View style={question_styles.outer_container}>
<View style={question_styles.scale5_container} >
{buttons}
</View>
</View>
)
}
}
class Scale10 extends React.Component {
// props: question: reference to parent Question component
constructor(props) {
super(props);
}
render() {
var buttons1=[], buttons2=[];
for (let i=1; i<=5; i++) {
buttons1.push(<CircularButtonForScaleAnswer key={i} title={i.toString()} question={this.props.question} />);
}
for (let i=6; i<=10; i++) {
buttons2.push(<CircularButtonForScaleAnswer key={i} title={i.toString()} question={this.props.question} />);
}
return (
<View style={question_styles.outer_container}>
<View style={question_styles.scale10_container} >
{buttons1}
</View>
<View style={question_styles.scale10_container} >
{buttons2}
</View>
</View>
)
}
}
class CircularButtonForScaleAnswer extends React.Component {
// props: question: reference to parent Question component
constructor(props) {
super(props);
}
render() {
return (
<OnlineButton
style={question_styles.circular_button}
onPress={() => this.props.question.submitAnswer(this.props.title)}
>
<Text style={question_styles.button_text}>{this.props.title}</Text>
</OnlineButton>
)
}
}
class TextBox extends React.Component {
// props: question: reference to parent Question component
constructor(props) {
super(props);
this.state = { answer: "" };
}
render() {
return (
<View style = {{
flex: 1,
flexDirection: 'column',
justifyContent: 'flex-start',
alignItems: 'center',
}}>
<View style={question_styles.textbox_container} >
<TextInput
style={question_styles.textbox}
placeholder="Rövid válasz."
multiline={true}
blurOnSubmit={true}
onChangeText={(text) => this.setState({answer: text})}
value={this.state.answer}
/>
<OnlineButton
style={question_styles.textbox_button}
onPress={() => this.props.question.submitAnswer(this.state.answer)}
>
<Text style={question_styles.button_text}>Küld</Text>
</OnlineButton>
</View>
</View>
);
}
}
class Question extends React.Component {
constructor(props) {
super(props);
}
submitAnswer(answer) {
let answerObject = {
answer: answer,
name: this.props.name,
timestamp: new Date()
};
saveAnswer(this.props.id, answerObject);
}
render() {
console.log("Q: " + this.props.id);
this.questionObjectData = this.props.questions[this.props.id].data;
var questionComponentForType = (<Text style={question_styles.question_text}>{strings.UNKNOWN_QUESTION}</Text>);
if (this.questionObjectData.type == "scale5") {
questionComponentForType = (<Scale5 question={this} />);
} else if (this.questionObjectData.type == "scale10") {
questionComponentForType = (<Scale10 question={this} />);
} else if (this.questionObjectData.type == "wordcloud") {
questionComponentForType = (<WordCloud question={this} />);
} else if (this.questionObjectData.type == "textbox") {
questionComponentForType = (<TextBox question={this} />);
}
return (
<View style={question_styles.container} >
<Text style={question_styles.question_text} >{this.questionObjectData.text}</Text>
{questionComponentForType}
</View>
);
}
}
const mapStateToProps = state => ({
id: state.questionToShow,
questions: state.questions,
event: state.event,
name: state.name
});
export default connect(mapStateToProps)(Question);
const question_styles = StyleSheet.create({
container: {
flex: 1,
color: '#fff',
alignItems: 'center',
justifyContent: 'flex-start',
},
question_text: {
fontSize: 24,
alignItems: 'center',
justifyContent: 'center',
margin: 20,
color: '#fff',
},
button_text: {
color: '#fff',
textAlign: 'center'
},
circular_button: {
flex: 1,
borderWidth:1,
borderColor:'rgba(255,255,255,0.5)',
alignItems:'center',
justifyContent:'center',
width: 40,
height: 40,
backgroundColor:'#204096',
color: '#fff',
borderRadius: 20,
margin: 5,
padding: 10
},
wordcloud_button: {
borderWidth:1,
borderColor:'rgba(255,255,255,0.5)',
alignItems:'center',
justifyContent:'center',
width: 150,
padding: 8,
backgroundColor:'#204096',
color: '#fff',
borderRadius: 20,
margin: 5,
},
outer_container: {
flex: 1,
flexDirection: 'column',
alignItems: 'center',
},
wordcloud_container: {
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
},
scale5_container: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
marginTop: 50,
},
scale10_container: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
marginTop: 5,
},
textbox_container: {
alignItems: 'center',
justifyContent: 'flex-start',
},
textbox: {
borderWidth: 1,
borderColor: '#fff',
color: '#fff',
width: 300,
height: 80,
justifyContent: 'center',
padding: 8,
margin: 20,
},
textbox_button: {
borderWidth:1,
borderColor:'rgba(255,255,255,0.5)',
alignItems:'center',
justifyContent:'center',
width: 100,
height: 40,
backgroundColor:'#204096',
color: '#fff',
borderRadius: 20,
margin: 5,
}
})