@@ -131,36 +131,50 @@ const HomeScreen: React.FC<HomeScreenProps> = ({ username }) => {
131
131
switch ( gameState ) {
132
132
case "idle" :
133
133
return (
134
- < >
134
+ < View style = { styles . gameContainer } >
135
135
< Text style = { styles . welcomeText } > Welcome { username } !</ Text >
136
- < Button title = "Search Game" onPress = { handleSearchGame } />
137
- </ >
136
+ < View style = { styles . buttonContainer } >
137
+ < Button
138
+ title = "Search Game"
139
+ onPress = { handleSearchGame }
140
+ color = "#eba74c"
141
+ />
142
+ </ View >
143
+ </ View >
138
144
) ;
139
145
case "searching" :
140
146
return (
141
- < >
147
+ < View style = { styles . gameContainer } >
142
148
< Text style = { styles . quizText } > Searching for a game now</ Text >
143
- < ActivityIndicator style = { styles . activityIndicator } size = "large" />
144
- </ >
149
+ < ActivityIndicator
150
+ style = { styles . activityIndicator }
151
+ size = "large"
152
+ color = "#eba74c"
153
+ />
154
+ </ View >
145
155
) ;
146
156
case "found" :
147
157
return (
148
- < >
158
+ < View style = { styles . gameContainer } >
149
159
< Text style = { styles . quizText } >
150
160
Questions are getting generated now...
151
161
</ Text >
152
- < ActivityIndicator style = { styles . activityIndicator } size = "large" />
153
- </ >
162
+ < ActivityIndicator
163
+ style = { styles . activityIndicator }
164
+ size = "large"
165
+ color = "#eba74c"
166
+ />
167
+ </ View >
154
168
) ;
155
169
case "quiz" :
156
- if ( ! game ) return < Text > Loading game...</ Text > ;
170
+ if ( ! game ) return < Text style = { styles . quizText } > Loading game...</ Text > ;
157
171
158
172
const question = game . questions [ currentQuestion ] ;
159
173
if ( currentQuestion === game . questions . length ) {
160
174
return (
161
- < >
175
+ < View style = { styles . gameContainer } >
162
176
< Text style = { styles . quizText } > Quiz is over!</ Text >
163
- < Text style = { styles . quizText } >
177
+ < Text style = { styles . resultText } >
164
178
{ game . playerOneScore === game . playerTwoScore
165
179
? `It's a tie with ${ game . playerOneScore } !`
166
180
: ( game . playerOneScore ?? 0 ) > ( game . playerTwoScore ?? 0 )
@@ -171,52 +185,137 @@ const HomeScreen: React.FC<HomeScreenProps> = ({ username }) => {
171
185
game . playerTwoId === username ? "You" : game . playerTwoId
172
186
} won with ${ game . playerTwoScore } points!`}
173
187
</ Text >
174
- </ >
188
+ </ View >
175
189
) ;
176
190
}
177
191
return (
178
- < >
179
- < Text > { question ?. question } </ Text >
180
- { question ?. options . map ( ( option ) => (
181
- < Button
182
- key = { option }
183
- title = { option }
184
- onPress = { ( ) => {
185
- if ( option === question . correctAnswer ) {
186
- if ( game . playerOneId === username ) {
187
- client . models . Game . update ( {
188
- id : game . id ,
189
- playerOneScore : ( game . playerOneScore ?? 0 ) + 10 ,
190
- currentQuestion,
191
- } ) ;
192
- } else {
193
- client . models . Game . update ( {
194
- id : game . id ,
195
- playerTwoScore : ( game . playerTwoScore ?? 0 ) + 10 ,
196
- currentQuestion,
197
- } ) ;
198
- }
199
- } else {
200
- client . models . Game . update ( {
201
- id : game . id ,
202
- currentQuestion,
203
- } ) ;
204
- }
205
- } }
206
- />
207
- ) ) }
208
- </ >
192
+ < View style = { styles . gameContainer } >
193
+ < Text style = { styles . questionText } > { question ?. question } </ Text >
194
+ < View style = { styles . optionsContainer } >
195
+ { question ?. options . map ( ( option ) => (
196
+ < View style = { styles . optionButton } key = { option } >
197
+ < Button
198
+ title = { option }
199
+ color = "#eba74c"
200
+ onPress = { ( ) => {
201
+ if ( option === question . correctAnswer ) {
202
+ if ( game . playerOneId === username ) {
203
+ client . models . Game . update ( {
204
+ id : game . id ,
205
+ playerOneScore : ( game . playerOneScore ?? 0 ) + 10 ,
206
+ currentQuestion,
207
+ } ) ;
208
+ } else {
209
+ client . models . Game . update ( {
210
+ id : game . id ,
211
+ playerTwoScore : ( game . playerTwoScore ?? 0 ) + 10 ,
212
+ currentQuestion,
213
+ } ) ;
214
+ }
215
+ } else {
216
+ client . models . Game . update ( {
217
+ id : game . id ,
218
+ currentQuestion,
219
+ } ) ;
220
+ }
221
+ } }
222
+ />
223
+ </ View >
224
+ ) ) }
225
+ </ View >
226
+ </ View >
209
227
) ;
210
228
case "error" :
211
- return < Text style = { styles . welcomeText } > There is an error.</ Text > ;
229
+ return (
230
+ < View style = { styles . gameContainer } >
231
+ < Text style = { [ styles . welcomeText , styles . errorText ] } >
232
+ There is an error.
233
+ </ Text >
234
+ </ View >
235
+ ) ;
212
236
default :
213
- return < Text > Unknown state</ Text > ;
237
+ return < Text style = { styles . quizText } > Unknown state</ Text > ;
214
238
}
215
239
} ;
216
240
217
241
return < View style = { styles . contentContainer } > { renderContent ( ) } </ View > ;
218
242
} ;
219
243
244
+ const styles = StyleSheet . create ( {
245
+ container : {
246
+ flex : 1 ,
247
+ backgroundColor : "#fff" ,
248
+ } ,
249
+ signOutButton : {
250
+ alignSelf : "flex-end" ,
251
+ margin : 16 ,
252
+ } ,
253
+ contentContainer : {
254
+ flex : 1 ,
255
+ justifyContent : "center" ,
256
+ alignItems : "center" ,
257
+ padding : 20 ,
258
+ } ,
259
+ gameContainer : {
260
+ width : "100%" ,
261
+ alignItems : "center" ,
262
+ padding : 20 ,
263
+ borderRadius : 10 ,
264
+ backgroundColor : "#fff" ,
265
+ shadowColor : "#000" ,
266
+ shadowOffset : {
267
+ width : 0 ,
268
+ height : 2 ,
269
+ } ,
270
+ shadowOpacity : 0.25 ,
271
+ shadowRadius : 3.84 ,
272
+ elevation : 5 ,
273
+ } ,
274
+ welcomeText : {
275
+ fontSize : 24 ,
276
+ fontWeight : "bold" ,
277
+ color : "#333" ,
278
+ marginBottom : 20 ,
279
+ } ,
280
+ buttonContainer : {
281
+ width : "80%" ,
282
+ marginTop : 20 ,
283
+ } ,
284
+ quizText : {
285
+ fontSize : 18 ,
286
+ marginBottom : 16 ,
287
+ color : "#333" ,
288
+ textAlign : "center" ,
289
+ } ,
290
+ questionText : {
291
+ fontSize : 20 ,
292
+ fontWeight : "600" ,
293
+ color : "#333" ,
294
+ marginBottom : 24 ,
295
+ textAlign : "center" ,
296
+ } ,
297
+ resultText : {
298
+ fontSize : 20 ,
299
+ fontWeight : "600" ,
300
+ color : "#eba74c" ,
301
+ textAlign : "center" ,
302
+ } ,
303
+ optionsContainer : {
304
+ width : "100%" ,
305
+ marginTop : 20 ,
306
+ } ,
307
+ optionButton : {
308
+ marginVertical : 8 ,
309
+ width : "100%" ,
310
+ } ,
311
+ activityIndicator : {
312
+ padding : 16 ,
313
+ } ,
314
+ errorText : {
315
+ color : "red" ,
316
+ } ,
317
+ } ) ;
318
+
220
319
const App : React . FC = ( ) => {
221
320
const [ username , setUsername ] = useState < string > ( "" ) ;
222
321
@@ -241,29 +340,4 @@ const App: React.FC = () => {
241
340
) ;
242
341
} ;
243
342
244
- const styles = StyleSheet . create ( {
245
- container : {
246
- flex : 1 ,
247
- } ,
248
- signOutButton : {
249
- alignSelf : "flex-end" ,
250
- } ,
251
- contentContainer : {
252
- flex : 1 ,
253
- justifyContent : "center" ,
254
- alignItems : "center" ,
255
- } ,
256
- welcomeText : {
257
- fontSize : 18 ,
258
- fontWeight : "bold" ,
259
- } ,
260
- quizText : {
261
- fontSize : 16 ,
262
- marginBottom : 16 ,
263
- } ,
264
- activityIndicator : {
265
- padding : 16 ,
266
- } ,
267
- } ) ;
268
-
269
343
export default App ;
0 commit comments