-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExerciseView.js
123 lines (101 loc) · 2.71 KB
/
ExerciseView.js
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
import { useEffect, useState } from "react";
import { Text, SafeAreaView, StyleSheet, ScrollView, View } from "react-native";
import SisApi from "./api";
import ExerciseCard from "./ExerciseCard";
import { useNavigation } from "@react-navigation/native";
import Button from "./Button";
/** ExerciseView: See all list of exercises organized by most recent
* exercise, then by future exercises and past exercises
*
* State:
* -isLoading: boolean
* -exerciseData: array
*
* Props:
* none
*/
function ExerciseView() {
const [isLoading, setIsLoading] = useState(true);
const [exerciseData, setExerciseData] = useState();
const navigation = useNavigation();
/**
* Uses api to collect all data on all lectures in the cohort
* then changes staff data to the full names of all staff
* involved in each lecture
*
*/
useEffect(function fetchExercisesWhenMounted() {
async function fetchExercises() {
const allExercises = await SisApi.getExercises();
const exercisePromises = [];
allExercises.map(e => exercisePromises.push(SisApi.getExercise(e.api_url)));
let exerciseDetailedData = await Promise.all(exercisePromises);
console.log("exercisedetaileddata", exerciseDetailedData);
setExerciseData(exerciseDetailedData);
setIsLoading(false);
}
fetchExercises();
}, []);
// Navigates to the homepage upon press
function homepagePress() {
navigation.navigate('Homepage');
}
if (isLoading === true) {
return (
<SafeAreaView style={styles.container}>
<Text>Loading...</Text>
</SafeAreaView>
);
}
return (
<SafeAreaView style={styles.container}>
<ScrollView>
<Button
onPress={homepagePress}
text="Home"
style={styles.button} />
<View>
{exerciseData.length > 0 &&
<Text style={styles.textHeader}>All Exercises:</Text>}
{exerciseData &&
exerciseData.map(e => (
<ExerciseCard
title={e.title}
description={e.description} />
))}
</View>
</ScrollView>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
maxWidth: '100%',
minWidth: '100%',
alignSelf: 'center',
justifyContent: 'center',
},
text: {
alignSelf: 'center',
},
button: {
backgroundColor: '#f86161',
minWidth: '70%',
maxWidth: '70%',
padding: 5,
marginVertical: 10,
alignSelf: 'center',
textAlign: 'center',
borderRadius: 5,
fontWeight: 'bold',
color: 'white',
},
textHeader: {
alignSelf: 'center',
fontWeight: 'bold',
padding: 6,
fontSize: 20,
}
});
export default ExerciseView;