-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainQuestion.tsx
102 lines (97 loc) · 2.9 KB
/
MainQuestion.tsx
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
import React, { useState } from "react";
import {
SafeAreaView,
ScrollView,
StatusBar,
View,
Text,
TextInput,
TouchableOpacity,
} from "react-native";
import Styles from "./Styles";
import { RootStackParamList } from "./ScavengerHuntEnter";
import { StackScreenProps } from "@react-navigation/stack";
import { showMessage } from "react-native-flash-message";
import { useAuth } from "./context/AuthContext";
type Props = StackScreenProps<RootStackParamList, "Question">;
export default function MainQuestion({ route, navigation }: Props) {
const { userInfo, updateQuestionScavengerHuntStatus } = useAuth();
const [userInput, setUserInput] = useState("");
const { question, answer, question_num } = route.params;
const onPress = async function onPress() {
if (userInput === answer) {
showMessage({
message: "Correct!",
type: "success",
color: "white",
titleStyle: { textAlign: "center", fontSize: 19 },
});
// TODO Update db
const question_field: string = "question" + question_num;
await updateQuestionScavengerHuntStatus(
question_field,
userInfo.uid,
question_num,
userInfo.points
);
navigation.navigate("Scavenger_Hunt");
} else {
showMessage({
message: "Incorrect Answer!",
type: "warning",
color: "black",
titleStyle: { textAlign: "center", fontSize: 19 },
});
setUserInput("");
}
};
return (
<>
<StatusBar />
<SafeAreaView style={Styles.login_container}>
<ScrollView>
<View style={{ marginTop: 15 }}>
<Text style={{ color: "white", fontSize: 24, textAlign: "center" }}>
Question:
</Text>
</View>
<Text
style={{
color: "white",
marginTop: 15,
marginBottom: 20,
fontSize: 18,
textAlign: "center",
}}
>
{question}
</Text>
<TextInput
style={Styles.clue_submit_button}
value={userInput}
placeholder={""}
onChangeText={(text) => setUserInput(text)}
/>
<TouchableOpacity
style={{ marginLeft: 20, marginRight: 20, marginBottom: 20 }}
onPress={onPress}
>
<View style={Styles.button}>
<Text style={Styles.button_label}>{"Submit"}</Text>
</View>
</TouchableOpacity>
<TouchableOpacity
style={{ marginLeft: 20, marginRight: 20 }}
onPress={() => navigation.navigate("Scavenger_Hunt")}
>
<View style={Styles.button}>
<Text style={Styles.button_label}>
{"Return to Scavenger Hunt Home"}
</Text>
</View>
</TouchableOpacity>
</ScrollView>
</SafeAreaView>
</>
);
}