-
Notifications
You must be signed in to change notification settings - Fork 1
/
Lesson.tsx
339 lines (312 loc) · 9.65 KB
/
Lesson.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
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
import React, { useState } from "react";
import {
StyleSheet,
View,
Image,
Platform,
useWindowDimensions,
Pressable,
} from "react-native";
import { Text, useTheme, ActivityIndicator } from "react-native-paper";
import { useNavigation } from "@react-navigation/native";
import { AntDesign, MaterialCommunityIcons } from "@expo/vector-icons";
import Alert from "react-native-awesome-alerts";
import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
import { useFocusEffect } from "@react-navigation/core";
import { PreferencesContext } from "../Contexts/PreferencesContext";
import {
Lessons,
getLessonMode,
lessonOfflineMode,
lessonOnlineMode,
} from "../Functions/Api/Lessons";
import { Statistics } from "../Functions/Api/Statistics";
const Lesson = (props: { route: { params: { params: any } } }) => {
//Brings in name of strategy from carousel
let name = props.route.params
? props.route.params.params
: "no props.route.params in LessonPage";
const navigation: any = useNavigation();
const size = useWindowDimensions();
const reSize = Math.min(size.width, size.height);
const { updateLearnedLessons, learnedLessons } =
React.useContext(PreferencesContext);
const [learnHelpVisible, setLearnHelpVisible] = React.useState(false);
const showLearnHelp = () => setLearnHelpVisible(true);
const hideLearnHelp = () => setLearnHelpVisible(false);
const [steps, setSteps] = React.useState([]);
const [isLoading, setIsLoading] = React.useState(true);
const theme = useTheme();
function getTitle(name: string): string {
let lessonName: string;
name == "AMEND_NOTES"
? (lessonName = "Amend Notes")
: name == "NAKED_SINGLE"
? (lessonName = "Naked Single")
: name == "NAKED_SET"
? (lessonName = "Naked Set")
: name == "HIDDEN_SINGLE"
? (lessonName = "Hidden Single")
: name == "HIDDEN_SET"
? (lessonName = "Hidden Set")
: name == "SUDOKU_101"
? (lessonName = "Sudoku 101")
: name == "SIMPLIFY_NOTES"
? (lessonName = "Simplify Notes")
: name == "POINTING_SET"
? (lessonName = "Pointing Set")
: (lessonName = "Null");
return lessonName;
}
let title = getTitle(name);
if (Lessons == null) {
return;
}
// setting lesson mode to offline
let LESSON_MODE = getLessonMode.Offline;
let getlessonArgs: lessonOfflineMode | lessonOnlineMode = {
mode: LESSON_MODE,
};
//2d array - [[],[]]. 1st array indicates which step, 2nd array indicates text or image.
// This useFocusEffect stores the steps in state when page is loaded in.
useFocusEffect(
React.useCallback(() => {
Lessons.getSteps(name, getlessonArgs).then((result: any) => {
setSteps(result);
setIsLoading(false);
});
}, [])
);
async function saveUserLearnedLessons(learnedLessons: string[]) {
await Statistics.saveLearnedLessons(learnedLessons).then((res: any) => {
if (res) {
console.log("Lessons save successfully!");
} else {
console.log("Lesson not saved");
}
});
}
const clickCheckMark = () => {
if (!learnedLessons.includes(name)) {
learnedLessons.push(name);
updateLearnedLessons(learnedLessons);
saveUserLearnedLessons(learnedLessons);
}
navigation.navigate("LearnPage");
};
const [count, setCount] = useState(0);
//Separate view for mobile and web
const Page = () => {
// Wait for page to load the stuff
if (isLoading) {
return (
<ActivityIndicator animating={true} color={theme.colors.primary} />
);
}
//web view
else if (Platform.OS === "web") {
return (
<View style={styles.container1}>
<View style={{ justifyContent: "center", flexDirection: "row" }}>
<Pressable
style={{
top: reSize / 4.5,
height: reSize / 10,
right: reSize / 25,
}}
disabled={count - 1 == -1}
onPress={() => setCount(count - 1)}
>
<AntDesign
color={
count - 1 == -1
? theme.colors.background
: theme.colors.onBackground
}
name="leftcircleo"
size={reSize / 15}
/>
</Pressable>
{steps[count][1] != null ? (
<Image
style={{ width: reSize / 2, height: reSize / 2 }}
source={
LESSON_MODE === getLessonMode.Online
? { uri: steps[count][1] }
: steps[count][1]
}
/>
) : (
<></>
)}
<Pressable
style={{
top: reSize / 4.5,
height: reSize / 10,
left: reSize / 25,
}}
onPress={() =>
count + 1 == steps.length
? clickCheckMark()
: setCount(count + 1)
}
>
<AntDesign
color={theme.colors.onBackground}
name={
count + 1 == steps.length ? "checkcircleo" : "rightcircleo"
}
size={reSize / 15}
/>
</Pressable>
</View>
<Text> </Text>
<View style={{ width: reSize / 1.5 }}>
{steps[count][0] != null ? (
<Text
style={{
color: theme.colors.onBackground,
textAlign: "justify",
fontSize: size.height / 50,
}}
>
{steps[count][0]}
</Text>
) : (
<></>
)}
</View>
</View>
);
}
//mobile view
else {
return (
<View style={styles.container1}>
{steps[count][1] != null ? (
<Image
style={{ width: reSize / 1.3, height: reSize / 1.3 }}
source={
LESSON_MODE === getLessonMode.Online
? { uri: steps[count][1] }
: steps[count][1]
}
/>
) : (
<></>
)}
<Text> </Text>
<View style={{ justifyContent: "center", flexDirection: "row" }}>
<Pressable
style={{ top: reSize / 2, height: reSize / 8, left: reSize / 10 }}
disabled={count - 1 == -1}
onPress={() => setCount(count - 1)}
>
<AntDesign
color={
count - 1 == -1
? theme.colors.background
: theme.colors.onBackground
}
name="leftcircleo"
size={reSize / 10}
/>
</Pressable>
<View style={{ width: reSize / 1.2 }}>
{steps[count][0] != null ? (
<Text
style={{
color: theme.colors.onBackground,
textAlign: "justify",
fontSize: size.height / 50,
}}
>
{steps[count][0]}
</Text>
) : (
<></>
)}
</View>
<Pressable
style={{
top: reSize / 2,
height: reSize / 8,
right: reSize / 10,
}}
onPress={() =>
count + 1 == steps.length
? clickCheckMark()
: setCount(count + 1)
}
>
<AntDesign
color={theme.colors.onBackground}
name={
count + 1 == steps.length ? "checkcircleo" : "rightcircleo"
}
size={reSize / 10}
/>
</Pressable>
</View>
</View>
);
}
};
return (
<SafeAreaProvider>
<SafeAreaView style={{ height: "100%", width: "100%" }}>
<View>
<View style={styles.container1}>
<View style={{ flexDirection: "row" }}>
<Text
style={{
color: theme.colors.primary,
fontSize: reSize / 25,
fontWeight: "bold",
}}
>
{title + " Lesson"}
</Text>
<Pressable onPress={() => showLearnHelp()}>
<MaterialCommunityIcons
color={theme.colors.onBackground}
name="help"
/>
</Pressable>
</View>
<Page />
</View>
</View>
<Alert
show={learnHelpVisible}
title="Learning Help"
message={
`This is the ` +
title +
" lesson page.\n\n" +
"Navigate through the lesson by using the left and right arrows.\n\n" +
"Each page of the lesson will contain a board as well as a description to help you understand the process for using the " +
title +
" strategy"
}
messageStyle={{ maxWidth: 500 }}
showConfirmButton={true}
closeOnTouchOutside={false}
closeOnHardwareBackPress={false}
confirmText={"OK"}
confirmButtonColor={theme.colors.primary}
onConfirmPressed={() => {
hideLearnHelp();
}}
/>
</SafeAreaView>
</SafeAreaProvider>
);
};
const styles = StyleSheet.create({
container1: {
alignItems: "center",
justifyContent: "center",
},
});
export default Lesson;