Skip to content

Commit 201fb92

Browse files
committed
I DID MOST OF THE WORK! -- Student Working && TA Pending
1 parent 78300eb commit 201fb92

File tree

7 files changed

+495
-90
lines changed

7 files changed

+495
-90
lines changed

TAQ/App.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
import { StatusBar } from "expo-status-bar";
2-
import { FlatList, StyleSheet, Text, View } from "react-native";
3-
import { Colors } from "./config/Colors";
4-
import User from "./screens/User";
5-
import ClassQueue from "./screens/ClassQueue";
61
import Navigation from "./Navigation";
72

83
export default function App() {
9-
// return <User queueLength={5} estimatedTime={40}/>;
10-
// return <ClassQueue/>
114
return <Navigation />;
125
}
13-
14-
const styles = StyleSheet.create({
15-
container: {
16-
flex: 1,
17-
alignItems: "center",
18-
justifyContent: "center",
19-
},
20-
});

TAQ/Navigation.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createNativeStackNavigator } from "@react-navigation/native-stack";
44
import Home from "./screens/Home";
55
import Locations from "./screens/Locations";
66
import Auth from "./screens/Auth";
7-
import User from "./screens/User";
7+
import StudentAdd from "./screens/StudentAdd";
88
import ClassQueue from "./screens/ClassQueue";
99

1010
const Stack = createNativeStackNavigator();
@@ -30,6 +30,13 @@ function RootStack() {
3030
animation: "slide_from_right",
3131
}}
3232
/>
33+
<Stack.Screen
34+
name="SQueue"
35+
component={StudentAdd}
36+
options={{
37+
animation: "slide_from_right",
38+
}}
39+
/>
3340
<Stack.Screen
3441
name="Queue"
3542
component={ClassQueue}

TAQ/components/Course.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ const Course = ({ course, navigation, disabled }) => {
3030
const handlePressOut = () => {
3131
scale.value = withSpring(1, { damping: 15, stiffness: 200 });
3232
if (disabled) return;
33-
navigation.navigate("Location"); // Navigate after animation
33+
navigation.navigate("Location", {
34+
courseID: course.class.id,
35+
role: course.role,
36+
}); // Navigate after animation
3437
};
3538

3639
return (
@@ -46,12 +49,12 @@ const Course = ({ course, navigation, disabled }) => {
4649
numberOfLines={2}
4750
style={[styles.name, { fontSize: Platform.OS === "android" ? 14 : 18 }]}
4851
>
49-
{course.courses.name}
52+
{course.class.name}
5053
</Text>
5154
<Text
5255
style={[styles.code, { fontSize: Platform.OS === "android" ? 13 : 15 }]}
5356
>
54-
{course.courses.code}
57+
{course.class.code}
5558
</Text>
5659
</AnimatedPressable>
5760
);

TAQ/screens/Auth.jsx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,46 @@ const Auth = ({ navigation }) => {
7575
async function signUpWithEmail() {
7676
setLoading(true);
7777
try {
78+
// First, sign up the user
7879
const { data, error } = await supabase.auth.signUp({
7980
email: email,
8081
password: password,
8182
options: {
8283
data: {
83-
name: "KDT",
84+
name: "Amit",
8485
},
8586
},
86-
// You can remove the options.data part unless you need it for other metadata
8787
});
8888

8989
if (error) {
9090
Alert.alert("Error", error.message);
91-
} else if (data.session) {
92-
navigation.navigate("Courses");
91+
return; // Exit early if there's an error
92+
}
93+
94+
// If signup successful, insert into public.users
95+
if (data.user) {
96+
const { error: insertError } = await supabase.from("users").insert([
97+
{
98+
id: data.user.id, // Use the auth user's ID
99+
name: "Amit",
100+
email: data.user.email,
101+
role: "Student",
102+
},
103+
]);
104+
105+
if (insertError) {
106+
console.error("Error inserting user:", insertError);
107+
Alert.alert("Error", "Failed to create user profile");
108+
return;
109+
}
110+
111+
// If everything successful, navigate
112+
if (data.session) {
113+
navigation.navigate("Courses");
114+
}
93115
}
94116
} catch (error) {
117+
console.error("Unexpected error:", error);
95118
Alert.alert("Error", error.message);
96119
} finally {
97120
setLoading(false);
@@ -115,9 +138,10 @@ const Auth = ({ navigation }) => {
115138
style={styles.input}
116139
placeholder="Password"
117140
value={password}
141+
secureTextEntry
118142
onChangeText={setPassword}
119143
/>
120-
<Pressable onPress={signUpWithEmail} style={styles.login}>
144+
<Pressable onPress={signInWithEmail} style={styles.login}>
121145
<Text style={{ color: Colors.Background, fontWeight: "bold" }}>
122146
Login
123147
</Text>

TAQ/screens/Home.jsx

Lines changed: 84 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { FlatList, StatusBar, StyleSheet, Text, View } from "react-native";
1+
import {
2+
ActivityIndicator,
3+
Alert,
4+
FlatList,
5+
StatusBar,
6+
StyleSheet,
7+
Text,
8+
View,
9+
} from "react-native";
210
import React, { useEffect, useState } from "react";
311
import { SafeAreaView } from "react-native-safe-area-context";
412

@@ -13,6 +21,8 @@ const Home = ({ navigation }) => {
1321
const [isScrolling, setIsScrolling] = React.useState(false);
1422
// const [user, setUser] = useState(null);
1523
const [courses, setCourses] = useState([]);
24+
const [user, setUser] = useState(null);
25+
const [loading, setLoading] = useState(true);
1626

1727
useEffect(() => {
1828
const unsub = navigation.addListener("beforeRemove", (e) => {
@@ -24,9 +34,15 @@ const Home = ({ navigation }) => {
2434

2535
useEffect(() => {
2636
const fetchCourses = async () => {
27-
const { data, error } = await supabase.from("user_courses").select(`
28-
courses (*)
29-
`);
37+
const { data, error } = await supabase
38+
.from("user_courses")
39+
.select(
40+
`
41+
*,
42+
class (*)
43+
`
44+
)
45+
.eq("user", (await supabase.auth.getUser()).data.user.id);
3046

3147
if (error) {
3248
console.error("Error fetching courses:", error);
@@ -36,9 +52,34 @@ const Home = ({ navigation }) => {
3652
}
3753
};
3854

39-
fetchCourses();
55+
const fetchUser = async () => {
56+
const { data, error } = await supabase
57+
.from("users")
58+
.select("*")
59+
.eq("id", (await supabase.auth.getUser()).data.user.id);
60+
61+
if (error) {
62+
console.error("Error fetching user:", error);
63+
Alert.alert("Error", error.message);
64+
} else {
65+
console.log("Fetched user:", data);
66+
setUser(data[0]);
67+
}
68+
};
69+
70+
Promise.all([fetchCourses(), fetchUser()]).then(() => {
71+
setLoading(false);
72+
});
4073
}, []);
4174

75+
if (loading) {
76+
return (
77+
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
78+
<ActivityIndicator size="large" color={Colors.Primary} />
79+
</View>
80+
);
81+
}
82+
4283
return (
4384
<SafeAreaView style={styles.container}>
4485
<View style={{ paddingTop: 10, flex: 1 }}>
@@ -56,10 +97,13 @@ const Home = ({ navigation }) => {
5697
alignItems: "center",
5798
}}
5899
>
59-
<Text style={styles.welcomeText}>Welcome back, Amit!</Text>
100+
<Text style={styles.welcomeText}>Welcome back, {user.name}!</Text>
60101
<MaterialIcons
61102
name="logout"
62-
onPress={() => supabase.auth.signOut()}
103+
onPress={() => {
104+
supabase.auth.signOut();
105+
navigation.goBack();
106+
}}
63107
size={30}
64108
color={Colors.Red}
65109
/>
@@ -73,26 +117,34 @@ const Home = ({ navigation }) => {
73117
<View
74118
style={{ height: 2, backgroundColor: "#fff9", marginVertical: 15 }}
75119
></View>
76-
<FlatList
77-
data={courses}
78-
numColumns={2}
79-
onScrollBeginDrag={() => {
80-
// Disable touch events while scrolling
81-
setIsScrolling(true);
82-
}}
83-
onScrollEndDrag={() => {
84-
// Enable touch events after scrolling
85-
setIsScrolling(false, 150);
86-
}}
87-
renderItem={({ item, index }) => (
88-
<Course
89-
key={index}
90-
course={item}
91-
navigation={navigation}
92-
disabled={isScrolling}
93-
/>
94-
)}
95-
/>
120+
{courses.length === 0 ? (
121+
<View>
122+
<Text style={styles.fallbackText}>
123+
You have no courses yet :( please check back later
124+
</Text>
125+
</View>
126+
) : (
127+
<FlatList
128+
data={courses}
129+
numColumns={2}
130+
onScrollBeginDrag={() => {
131+
// Disable touch events while scrolling
132+
setIsScrolling(true);
133+
}}
134+
onScrollEndDrag={() => {
135+
// Enable touch events after scrolling
136+
setIsScrolling(false, 150);
137+
}}
138+
renderItem={({ item, index }) => (
139+
<Course
140+
key={index}
141+
course={item}
142+
navigation={navigation}
143+
disabled={isScrolling}
144+
/>
145+
)}
146+
/>
147+
)}
96148
</View>
97149
</SafeAreaView>
98150
);
@@ -117,4 +169,9 @@ const styles = StyleSheet.create({
117169
color: Colors.Secondary,
118170
marginVertical: 10,
119171
},
172+
fallbackText: {
173+
color: Colors.Secondary,
174+
fontSize: 16,
175+
textAlign: "center",
176+
},
120177
});

0 commit comments

Comments
 (0)