Skip to content

Commit e0a2221

Browse files
Merge pull request #72 from techstartucalgary/mobile-connections
Connecting current design changes to connections
2 parents 11e4f40 + ef2c732 commit e0a2221

67 files changed

Lines changed: 3787 additions & 2312 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import { getStoredAuth } from "@/src/components/general/AsyncStorage";
2-
import AsyncStorage from "@react-native-async-storage/async-storage";
3-
import { router, useFocusEffect } from "expo-router";
1+
import { getStoredAuth } from "@/src/components/context/AsyncStorage";
2+
import { useAuth } from "@/src/components/context/AuthContext";
3+
import { useGame } from "@/src/components/context/GameContext";
4+
import { useFocusEffect } from "expo-router";
45
import { useCallback, useState } from "react";
56
import { FlatList, StyleSheet, Text, View } from "react-native";
67
import EventCard from "../../src/components/events/EventCard";
7-
import type Event from "../../src/interfaces/Event";
88
import EventIB from "../../src/interfaces/Event";
99
import { getUserEvents } from "../../src/services/event.service";
1010

11-
const NewEvents = () => {
12-
const [events, setEvents] = useState<Event[]>([]);
11+
export default function EventsPage() {
12+
const { user } = useAuth();
13+
const { setCurrentParticipantId } = useGame();
14+
const [events, setEvents] = useState<EventIB[]>([]);
1315
const [loading, setLoading] = useState(true);
1416
const [expandedEventId, setExpandedEventId] = useState<string | null>(null);
1517

@@ -19,16 +21,11 @@ const NewEvents = () => {
1921

2022
try {
2123
const stored = await getStoredAuth();
22-
23-
if (stored.isGuest) {
24-
const local = await AsyncStorage.getItem("guestEvents");
25-
const events: EventIB[] = local ? JSON.parse(local) : [];
26-
setEvents(events);
27-
return;
24+
if (stored.userId) {
25+
//guest that has joined event or user with account
26+
const data = await getUserEvents(stored.userId, stored.accessToken); //TODO: Needs to return participant data
27+
setEvents(data.events || []);
2828
}
29-
30-
const data = await getUserEvents(stored.userId, stored.accessToken);
31-
setEvents(data?.events || []);
3229
} finally {
3330
setLoading(false);
3431
}
@@ -42,8 +39,21 @@ const NewEvents = () => {
4239
);
4340

4441
//dropdown of event
45-
const handlePress = (eventId: string) => {
46-
setExpandedEventId((prev) => (prev === eventId ? null : eventId));
42+
const handlePress = async (event: EventIB) => {
43+
//set participantId based on event pressed
44+
const myParticipantId = event.participantIds?.find(
45+
(p) => p.userId === user?._id,
46+
)?.participantId;
47+
48+
if (myParticipantId) {
49+
await setCurrentParticipantId(myParticipantId); //update context for participantId for tapped event
50+
} else {
51+
console.log("No participantId found for current user in this event.");
52+
await setCurrentParticipantId(""); //reset if not found
53+
}
54+
55+
//expand event based on ID
56+
setExpandedEventId((prev) => (prev === event._id ? null : event._id));
4757
};
4858

4959
if (loading) {
@@ -76,21 +86,13 @@ const NewEvents = () => {
7686
<EventCard
7787
event={item}
7888
expanded={expandedEventId === item._id}
79-
onPress={() => handlePress(item._id)}
80-
onJoinGame={() => {
81-
router.push({
82-
pathname: "/GamePages/Game",
83-
params: { eventId: item._id },
84-
});
85-
}}
89+
onPress={() => handlePress(item)}
8690
/>
8791
)}
8892
/>
8993
</View>
9094
);
91-
};
92-
93-
export default NewEvents;
95+
}
9496

9597
const styles = StyleSheet.create({
9698
container: {

shatter-mobile/app/(tabs)/JoinEvent.tsx renamed to shatter-mobile/app/(tabs)/JoinEventPage.tsx

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,26 @@ export default function JoinEventPage() {
1010
const [showScanner, setShowScanner] = useState(false);
1111
const [eventCode, setEventCode] = useState("");
1212
const { joinEvent } = useJoinEvent();
13+
const [loading, setLoading] = useState(false);
1314
const [errorMessage, setErrorMessage] = useState<string | null>(null);
1415

16+
//for manual code entry
17+
const handleJoinEvent = async () => {
18+
setLoading(true);
19+
try {
20+
const eventId = await joinEvent(eventCode);
21+
setErrorMessage("");
22+
router.push({
23+
pathname: "/EventPages/EventLobby",
24+
params: { eventId },
25+
});
26+
} catch (err) {
27+
setErrorMessage((err as Error).message);
28+
} finally {
29+
setLoading(false);
30+
}
31+
};
32+
1533
return (
1634
<View style={styles.container}>
1735
{user ? (
@@ -34,38 +52,18 @@ export default function JoinEventPage() {
3452
value={eventCode}
3553
onChangeText={(text) => {
3654
setEventCode(text);
37-
setErrorMessage(null);
55+
setErrorMessage("");
3856
}}
3957
autoCapitalize="characters"
4058
autoCorrect={false}
4159
/>
4260

4361
<Button
4462
title="Join Event"
45-
onPress={async () => {
46-
const joinRes = await joinEvent(eventCode);
47-
48-
switch (joinRes.status) {
49-
case "event-not-found":
50-
setErrorMessage("We couldn’t find an event with that code.");
51-
break;
52-
case "no-user":
53-
setErrorMessage("Your profile is missing a name.");
54-
break;
55-
case "no-user-id":
56-
setErrorMessage("Please sign in again and retry.");
57-
break;
58-
case "join-error":
59-
setErrorMessage("Something went wrong joining the event.");
60-
break;
61-
case "success":
62-
setErrorMessage(null);
63-
router.push({ pathname: "/Events" });
64-
break;
65-
}
66-
}}
63+
onPress={() => handleJoinEvent()}
6764
disabled={!eventCode.trim()}
6865
/>
66+
6967
{errorMessage && <Text style={styles.errorText}>{errorMessage}</Text>}
7068
</View>
7169
</View>
@@ -98,6 +96,7 @@ const styles = StyleSheet.create({
9896
},
9997
errorText: {
10098
color: "#d32f2f",
99+
textAlign: "center",
101100
marginTop: 8,
102101
fontSize: 14,
103102
justifyContent: "center",

shatter-mobile/app/(tabs)/Profile.tsx

Lines changed: 0 additions & 142 deletions
This file was deleted.

0 commit comments

Comments
 (0)