From b3113dffd239258c2ecc5d3a86135ec01ad5ad32 Mon Sep 17 00:00:00 2001 From: Aryan-Bahl Date: Mon, 16 Sep 2024 15:20:48 -0500 Subject: [PATCH 1/6] hot fix for events navigator --- Components/Text.tsx | 8 +++++++- navigation/DayEvent.tsx | 14 ++++++++++---- navigation/EventDaysNavigator.tsx | 7 ++++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Components/Text.tsx b/Components/Text.tsx index 935951d..1bcc261 100644 --- a/Components/Text.tsx +++ b/Components/Text.tsx @@ -1,6 +1,6 @@ import { styled } from "@gluestack-style/react"; import { Text } from "@gluestack-ui/themed"; -import { useFonts, Kufam_400Regular, Kufam_700Bold, Kufam_700Bold_Italic } from "@expo-google-fonts/kufam"; +import { useFonts, Kufam_400Regular, Kufam_700Bold, Kufam_700Bold_Italic, Kufam_600SemiBold } from "@expo-google-fonts/kufam"; const StyledText = styled(Text, { @@ -17,6 +17,12 @@ const StyledText = styled(Text, textAlign: 'center', fontFamily: "Kufam_700Bold" }, + footerText: { + fontSize: 40, + fontWeight: '$bold', + textAlign: 'center', + fontFamily: "Kufam_600SemiBold" + }, basic: { fontSize: "$md", fontWeight: "$normal", diff --git a/navigation/DayEvent.tsx b/navigation/DayEvent.tsx index c5b7e7e..e0e38df 100644 --- a/navigation/DayEvent.tsx +++ b/navigation/DayEvent.tsx @@ -2,6 +2,7 @@ import React from "react"; import { Text, View, ScrollView, StyleSheet } from "react-native"; import EventCard from "../Components/EventCard"; import Colors from "../constants/Colors"; +import { StyledText } from "../Components/Text"; export const formatTime = (timestamp) => { const date = new Date(timestamp); @@ -30,10 +31,11 @@ export const formatLocation = (location) => { const DayEvent = ({ day, events }) => { return ( - + {!events ? ( + {events.map((event) => ( { points={event.points} /> ))} + No more events for the day! + ) : ( + No events on this day + )} ); }; diff --git a/navigation/EventDaysNavigator.tsx b/navigation/EventDaysNavigator.tsx index ae4ffae..79a99b7 100644 --- a/navigation/EventDaysNavigator.tsx +++ b/navigation/EventDaysNavigator.tsx @@ -8,6 +8,9 @@ import { Inter_500Medium, Inter_700Bold, } from "@expo-google-fonts/inter"; + +import { Kufam_400Regular, Kufam_700Bold, Kufam_700Bold_Italic, Kufam_600SemiBold } from "@expo-google-fonts/kufam"; + import { useFocusEffect } from "@react-navigation/native"; const eventsURL = "https://api.reflectionsprojections.org/events/"; @@ -17,7 +20,7 @@ const WeekTab = createMaterialTopTabNavigator(); const EventDaysNavigator = () => { const [eventsData, setEventsData] = useState([]); const loaded = useRef(false) - + useFocusEffect( useCallback(() => { if (!loaded.current) { @@ -71,6 +74,8 @@ const EventDaysNavigator = () => { Inter_400Regular, Inter_500Medium, Inter_700Bold, + Kufam_600SemiBold, + Kufam_700Bold }); if (!fontsLoaded) { From 4babfc64cb4b8343b7953e3dfcf67dfb45052390 Mon Sep 17 00:00:00 2001 From: Aryan-Bahl Date: Mon, 16 Sep 2024 15:35:16 -0500 Subject: [PATCH 2/6] extra fix --- navigation/DayEvent.tsx | 2 +- navigation/EventDaysNavigator.tsx | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/navigation/DayEvent.tsx b/navigation/DayEvent.tsx index e0e38df..53c4bc2 100644 --- a/navigation/DayEvent.tsx +++ b/navigation/DayEvent.tsx @@ -31,7 +31,7 @@ export const formatLocation = (location) => { const DayEvent = ({ day, events }) => { return ( - {!events ? ( + {events ? ( { setEventsData(data); // Update eventsData state with fetched data } catch (error) { console.error("Error fetching events:", error); + setEventsData(null); } }; fetchEvents(); From 8776d489f03b4014a03ddd952face177ca8eab09 Mon Sep 17 00:00:00 2001 From: Aryan-Bahl Date: Mon, 16 Sep 2024 15:39:32 -0500 Subject: [PATCH 3/6] changed to check for empty not null --- navigation/DayEvent.tsx | 2 +- navigation/EventDaysNavigator.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/navigation/DayEvent.tsx b/navigation/DayEvent.tsx index 53c4bc2..2eece09 100644 --- a/navigation/DayEvent.tsx +++ b/navigation/DayEvent.tsx @@ -31,7 +31,7 @@ export const formatLocation = (location) => { const DayEvent = ({ day, events }) => { return ( - {events ? ( + {events.length > 0 ? ( { setEventsData(data); // Update eventsData state with fetched data } catch (error) { console.error("Error fetching events:", error); - setEventsData(null); + setEventsData([]); } }; fetchEvents(); From 5543a2e79add1b28d2092c9f62ffbde181e59a19 Mon Sep 17 00:00:00 2001 From: Aryan-Bahl Date: Tue, 17 Sep 2024 21:13:12 -0500 Subject: [PATCH 4/6] fixing login issue --- App.tsx | 14 +++-- api/getAttendee.tsx | 4 +- api/getEvents.tsx | 2 +- api/getQRCode.tsx | 28 +++++----- screens/GuestLogin.tsx | 114 +++++++++++++++++++++++++++++++++++++++++ screens/Login.tsx | 17 +----- screens/Profile.tsx | 10 ++-- screens/Shop.tsx | 5 +- 8 files changed, 151 insertions(+), 43 deletions(-) create mode 100644 screens/GuestLogin.tsx diff --git a/App.tsx b/App.tsx index b6826fd..ef76993 100644 --- a/App.tsx +++ b/App.tsx @@ -12,6 +12,7 @@ import Navigation from "./navigation/Navigation"; import Home from "./screens/Home"; import * as Linking from "expo-linking"; import Login from "./screens/Login"; +import GuestLogin from "./screens/GuestLogin"; import { createStackNavigator, StackNavigationProp, @@ -36,6 +37,7 @@ const prefix = Linking.createURL("/"); type RootStackParamList = { Login: undefined; + Guest: undefined; Main: undefined; }; @@ -53,6 +55,7 @@ const App = (props) => { config: { screens: { Login: "Login", + Guest: "Guest", Main: "Main", Home: "home", Camera: "camera", @@ -78,13 +81,13 @@ const App = (props) => { useEffect(() => { const handleDeepLink = (event: { url: string }) => { - console.log("handling deep link:", event.url); + // console.log("handling deep link:", event.url); const searchParams = new URL(event.url).searchParams; const token = searchParams.get("token"); if (token) { const decoded = decodeToken(token); - console.log("token", token, "decoded token", decoded); - console.log(decoded.roles); + //console.log("token", token, "decoded token", decoded); + //console.log(decoded.roles); if (!decoded.roles.includes("USER")) { Toast.show({ @@ -106,7 +109,7 @@ const App = (props) => { async function getInitialURL() { const initialURL = await Linking.getInitialURL(); - console.log("getting initial URL:", initialURL); + //console.log("getting initial URL:", initialURL); if (initialURL) handleDeepLink({ url: initialURL }); } @@ -117,7 +120,7 @@ const App = (props) => { useEffect(() => { if (isReady && deepLinkHandled) { - console.log("navigating"); + //console.log("navigating"); navigationRef.navigate("Main"); } }, [isReady, deepLinkHandled]); @@ -136,6 +139,7 @@ const App = (props) => { initialRouteName="Login" > + diff --git a/api/getAttendee.tsx b/api/getAttendee.tsx index 1919e41..606ea10 100644 --- a/api/getAttendee.tsx +++ b/api/getAttendee.tsx @@ -9,13 +9,11 @@ export const getAttendee = (token: string) => { Authorization: token }, }); - - clone = response.clone(); if (!response.ok) { throw new Error(`HTTP error! Status: ${response.status}`); } - + const data = await response.json(); dispatch(setAttendee(data)); } catch (error) { diff --git a/api/getEvents.tsx b/api/getEvents.tsx index 7882399..8134115 100644 --- a/api/getEvents.tsx +++ b/api/getEvents.tsx @@ -4,7 +4,7 @@ export const getEvents = async (token: string) => { try{ const response = await axios.get('https://api.reflectionsprojections.org/events/', { headers: { - Authorization: token + } }); return response.data; diff --git a/api/getQRCode.tsx b/api/getQRCode.tsx index 3b4a9c9..f608832 100644 --- a/api/getQRCode.tsx +++ b/api/getQRCode.tsx @@ -1,18 +1,18 @@ import { setQRCode } from "../redux/actions"; export const getQRCode = async (token: string, callback:Function) => { - try { - const response = await fetch('https://api.reflectionsprojections.org/attendee/qr/', { - headers: { - Authorization: token, - 'Content-Type': 'application/json' - }, - }); - const data = await response.json(); - console.log(data) - //dispatch(setQRCode(data.qrCode)); - callback(data.qrCode) - } catch (error) { - console.error('Error fetching qrcode:', error); - }; + try { + const response = await fetch('https://api.reflectionsprojections.org/attendee/qr/', { + headers: { + Authorization: token, + 'Content-Type': 'application/json' + }, + }); + const data = await response.json(); + console.log(data) + //dispatch(setQRCode(data.qrCode)); + callback(data.qrCode) + } catch (error) { + console.error('Error fetching qrcode:', error); + }; }; \ No newline at end of file diff --git a/screens/GuestLogin.tsx b/screens/GuestLogin.tsx new file mode 100644 index 0000000..6b2aa1c --- /dev/null +++ b/screens/GuestLogin.tsx @@ -0,0 +1,114 @@ +import React, { useEffect, useState } from "react"; +import { + Dimensions, + SafeAreaView, + StyleSheet, + Text, + View, +} from "react-native"; +import { Button, ButtonText } from '@gluestack-ui/themed'; +import * as WebBrowser from "expo-web-browser"; +import { NavigationProp, ParamListBase } from "@react-navigation/native"; +import { useAppSelector } from "../redux/hooks"; +import { RootState } from "../redux/store"; +import Colors from "../constants/Colors"; +import * as Linking from "expo-linking" +import { StyledText } from "../Components/Text"; + +const authUrl = "https://api.reflectionsprojections.org/auth/login/mobile/"; +const redirectURL = "reflectionsprojections://--/Main"; + +interface LoginProps { + navigation: NavigationProp; +} + +const GuestLogin: React.FC = ({ navigation }) => { + const token = useAppSelector((state: RootState) => state.token); + const roles = useAppSelector((state: RootState) => state.roles); + const [loggedIn, setLoggedIn] = useState(false); + + useEffect(() => { + if (token && roles.includes('USER')) { + setLoggedIn(true); + } else { + setLoggedIn(false); + } + }, [token, roles]); + + const handleLoginPress = () => { + if(loggedIn) { + navigation.navigate("Main"); + } else { + WebBrowser.openAuthSessionAsync( + `${authUrl}?redirect_uri=${redirectURL}`, + redirectURL + ).then((result) => { + if (result.type === "success") { + Linking.openURL(result.url); + navigation.navigate("Main"); + } + }).catch((err) => { + console.error("Failed to open URL:", err.message); + alert("Failed to open URL"); + }); + } + }; + + return ( + + + Haven't registered? + + OR + + + Already registered? + + + + ); +}; + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: "center", + alignItems: "center", + backgroundColor: Colors.DARK_BLUE, + }, + loginContainer: { + width: "80%", + alignItems: 'center', + backgroundColor: 'transparent', + }, + button: { + marginBottom: 20, + width: '100%', + marginTop: 20, + backgroundColor: Colors.YELLOW + }, + separator: { + color: Colors.WHITE, + fontSize: 16, + }, + spacing: { + height: 60, // Increased space before the already registered section + } +}); + +export default GuestLogin; diff --git a/screens/Login.tsx b/screens/Login.tsx index ca2fc77..61332ee 100644 --- a/screens/Login.tsx +++ b/screens/Login.tsx @@ -37,26 +37,13 @@ const Login: React.FC = ({ navigation }) => { } else { setLoggedIn(false); } - }, [token, roles, navigation]); + }, []); const handleLoginPress = () => { if(loggedIn) { navigation.navigate("Main"); } else { - WebBrowser.openAuthSessionAsync( - `${authUrl}?redirect_uri=${redirectURL}`, - redirectURL - ) - .then((result) => { - if (result.type === "success") { - Linking.openURL(result.url); - navigation.navigate("Main"); - } - }) - .catch((err) => { - console.error("Failed to open URL:", err.message); - alert("Failed to open URL"); - }); + navigation.navigate("Guest"); } }; diff --git a/screens/Profile.tsx b/screens/Profile.tsx index 72fd8ab..e13e529 100644 --- a/screens/Profile.tsx +++ b/screens/Profile.tsx @@ -58,11 +58,15 @@ const Profile: React.FC = () => { const foodwave = await getFoodWave(token); setFoodWave(foodwave.foodwave); } - fetchFoodWave(); - }) + if (token) { + fetchFoodWave(); + } + }); useEffect(() => { - setInterval(async () => {await getQRCode(token, setQRCode)}, 18000 + (Math.random() * 5000)); + if (token) { + setInterval(async () => {await getQRCode(token, setQRCode)}, 18000 + (Math.random() * 5000)); + } }, []); const handleLogOut = () => { diff --git a/screens/Shop.tsx b/screens/Shop.tsx index 17f6220..3996924 100644 --- a/screens/Shop.tsx +++ b/screens/Shop.tsx @@ -31,8 +31,9 @@ const Shop: React.FC = () => { console.error("error fetching points for user:", error); } }; - console.log("points") - fetchUserPoints(); // Fetch points when component mounts + if (token) { + fetchUserPoints(); + } }); // Empty dependency array means this effect runs once on mount if (!fontsLoaded) { From 8e913b776986652ca607c84ffcf87d06907a2fab Mon Sep 17 00:00:00 2001 From: Aryan-Bahl Date: Tue, 17 Sep 2024 21:27:57 -0500 Subject: [PATCH 5/6] another quick fix --- screens/GuestLogin.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/screens/GuestLogin.tsx b/screens/GuestLogin.tsx index 6b2aa1c..b0d290d 100644 --- a/screens/GuestLogin.tsx +++ b/screens/GuestLogin.tsx @@ -14,6 +14,7 @@ import { RootState } from "../redux/store"; import Colors from "../constants/Colors"; import * as Linking from "expo-linking" import { StyledText } from "../Components/Text"; +import { useFonts, Kufam_400Regular, Kufam_700Bold, Kufam_700Bold_Italic, Kufam_600SemiBold } from "@expo-google-fonts/kufam"; const authUrl = "https://api.reflectionsprojections.org/auth/login/mobile/"; const redirectURL = "reflectionsprojections://--/Main"; @@ -26,7 +27,10 @@ const GuestLogin: React.FC = ({ navigation }) => { const token = useAppSelector((state: RootState) => state.token); const roles = useAppSelector((state: RootState) => state.roles); const [loggedIn, setLoggedIn] = useState(false); - + let [fontsLoaded] = useFonts({ + Kufam_600SemiBold, + Kufam_700Bold + }); useEffect(() => { if (token && roles.includes('USER')) { setLoggedIn(true); @@ -62,14 +66,14 @@ const GuestLogin: React.FC = ({ navigation }) => { onPress={() => navigation.navigate("Main")} style={styles.button} > - Login as Guest + Login as Guest OR Already registered? @@ -77,7 +81,7 @@ const GuestLogin: React.FC = ({ navigation }) => { onPress={handleLoginPress} style={styles.button} > - Login + Login From 72893ebbfcff00bf32cc3278fd2d2ba8dc3e075d Mon Sep 17 00:00:00 2001 From: Aryan-Bahl Date: Tue, 17 Sep 2024 21:32:00 -0500 Subject: [PATCH 6/6] package update --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 068803d..fa8efcc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rp-mobile-2024", - "version": "1.6.1", + "version": "1.6.2", "main": "node_modules/expo/AppEntry.js", "scripts": { "start": "expo start",