From cc8e0c623c3bd5092288275ac9978ac214172dcb Mon Sep 17 00:00:00 2001 From: gibbyb Date: Fri, 18 Oct 2024 12:39:54 -0500 Subject: [PATCH] Fixed initial errors --- .gitignore | 6 ++++ app/(tabs)/index.tsx | 7 ++-- app/_layout.tsx | 14 +++++--- components/auth/SignInScreen.tsx | 6 ++-- ...{Relationship.tsx => RelationshipView.tsx} | 4 +-- components/services/SecureStore.tsx | 19 ++++++----- .../notifications/PushNotificationManager.tsx | 33 +++++++++++++++++-- components/theme/buttons/TextButton.tsx | 2 +- constants/APIs.ts | 13 +++++--- constants/Colors.ts | 4 +-- 10 files changed, 78 insertions(+), 30 deletions(-) rename components/home/{Relationship.tsx => RelationshipView.tsx} (98%) diff --git a/.gitignore b/.gitignore index dae9b76..2d1b664 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,9 @@ web-build/ # macOS .DS_Store + +# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb +# The following patterns were generated by expo-cli + +expo-env.d.ts +# @end expo-cli \ No newline at end of file diff --git a/app/(tabs)/index.tsx b/app/(tabs)/index.tsx index c5a718d..96f0c84 100644 --- a/app/(tabs)/index.tsx +++ b/app/(tabs)/index.tsx @@ -1,8 +1,8 @@ import React, { useState } from 'react'; import { StyleSheet } from 'react-native'; -import { ThemedView } from '@/components/theme/Theme'; +import { ThemedText, ThemedView } from '@/components/theme/Theme'; import UserInfo from '@/components/home/UserInfo'; -import Relationship from '@/components/home/Relationship'; +import RelationshipView from '@/components/home/RelationshipView'; const IndexScreen = () => { const [pfpUrl, setPfpUrl] = useState(null); @@ -12,11 +12,12 @@ const IndexScreen = () => { return ( - + ); + }; export default IndexScreen; diff --git a/app/_layout.tsx b/app/_layout.tsx index 975a63c..9aee471 100644 --- a/app/_layout.tsx +++ b/app/_layout.tsx @@ -5,11 +5,16 @@ import { PushNotificationManager } from "@/components/services/notifications/PushNotificationManager"; -export default function RootLayout() { +const RootLayout = () => { const [isSignedIn, setIsSignedIn] = useState(false); - if (!isSignedIn) - return ( setIsSignedIn(true)} />); - + console.log('RootLayout rendering, isSignedIn:', isSignedIn); + if (!isSignedIn) { + console.log('Rendering SignInScreen'); + return ( + setIsSignedIn(true)} /> + ); + } + console.log('PushNotificationManager & Stack'); return ( @@ -19,3 +24,4 @@ export default function RootLayout() { ); } +export default RootLayout; diff --git a/components/auth/SignInScreen.tsx b/components/auth/SignInScreen.tsx index d92000d..d449eef 100644 --- a/components/auth/SignInScreen.tsx +++ b/components/auth/SignInScreen.tsx @@ -32,12 +32,12 @@ const SignInScreen = ({onSignIn}: {onSignIn: () => void}) => { }); console.log( credential.user, credential.email, credential.fullName?.givenName, - credential.fullName?.familyName, pushToken + credential.fullName?.familyName, pushToken.data ); const initialDataResponse = await getInitialDataByAppleId(credential.user); - console.log(initialDataResponse); + console.log("InitialData response: ", initialDataResponse); if (initialDataResponse.status === 404 || !initialDataResponse.ok) { if (!credential.user || !credential.email || !credential.fullName?.givenName || !credential.fullName?.familyName || @@ -56,7 +56,7 @@ const SignInScreen = ({onSignIn}: {onSignIn: () => void}) => { const user: User = await createUser( credential.user, credential.email, - credential.fullName?.givenName + credential.fullName?.familyName, + credential.fullName?.givenName + ' ' + credential.fullName?.familyName, pushToken.data ) as User; await saveUser(user); diff --git a/components/home/Relationship.tsx b/components/home/RelationshipView.tsx similarity index 98% rename from components/home/Relationship.tsx rename to components/home/RelationshipView.tsx index 9adbafa..306f3b0 100644 --- a/components/home/Relationship.tsx +++ b/components/home/RelationshipView.tsx @@ -13,7 +13,7 @@ type RelationshipProps = { pfpUrl: string | null; }; -const Relationship: React.FC = ({ pfpUrl }) => { +const RelationshipView: React.FC = ({ pfpUrl }) => { const [status, setStatus] = useState(null); const [user, setUser] = useState(null); const [showRequestRelationship, setShowRequestRelationship] = useState(false); @@ -253,7 +253,7 @@ const Relationship: React.FC = ({ pfpUrl }) => { ); }; -export default Relationship; +export default RelationshipView; const styles = StyleSheet.create({ container: { diff --git a/components/services/SecureStore.tsx b/components/services/SecureStore.tsx index 26c7398..53e7bb1 100644 --- a/components/services/SecureStore.tsx +++ b/components/services/SecureStore.tsx @@ -121,7 +121,7 @@ export const updateCountdown = async (updatedFields: Partial) => { }; export const saveRelationshipData = async (relationshipData: RelationshipData) => { try { - await SecureStore.setItemAsync('partner', JSON.stringify(relationshipData.Partner)); + await SecureStore.setItemAsync('partner', JSON.stringify(relationshipData.partner)); await SecureStore.setItemAsync('relationship', JSON.stringify(relationshipData.relationship)); } catch (error) { console.error('Error saving partner & relationship to SecureStore:', error); @@ -130,13 +130,16 @@ export const saveRelationshipData = async (relationshipData: RelationshipData) = export const saveInitialData = async (initialData: InitialData) => { try { await SecureStore.setItemAsync('user', JSON.stringify(initialData.user)); - await SecureStore.setItemAsync( - 'relationship', JSON.stringify(initialData.relationshipData.relationship) - ); - await SecureStore.setItemAsync( - 'partner', JSON.stringify(initialData.relationshipData.Partner) - ); - await SecureStore.setItemAsync('countdown', JSON.stringify(initialData.countdown)); + if (initialData.relationshipData) { + await SecureStore.setItemAsync( + 'relationship', JSON.stringify(initialData.relationshipData.relationship) + ); + await SecureStore.setItemAsync( + 'partner', JSON.stringify(initialData.relationshipData.partner) + ); + if (initialData.countdown) + await SecureStore.setItemAsync('countdown', JSON.stringify(initialData.countdown)); + } } catch (error) { console.error('Error saving initial data to SecureStore:', error); } diff --git a/components/services/notifications/PushNotificationManager.tsx b/components/services/notifications/PushNotificationManager.tsx index 4504166..eec6440 100644 --- a/components/services/notifications/PushNotificationManager.tsx +++ b/components/services/notifications/PushNotificationManager.tsx @@ -1,9 +1,10 @@ -import React, { useState, useEffect, useRef } from 'react'; +import React, { useState, useEffect, useRef, ErrorInfo } from 'react'; import { Alert, Platform } from 'react-native'; import * as Device from 'expo-device'; import * as Notifications from 'expo-notifications'; import Constants from 'expo-constants'; import type { NotificationMessage } from '@/constants/Types'; +import { ThemedText } from '@/components/theme/Theme'; Notifications.setNotificationHandler({ handleNotification: async () => ({ @@ -114,5 +115,33 @@ export const PushNotificationManager = ({children}: {children: React.ReactNode}) Notifications.removeNotificationSubscription(responseListener.current); }; }, []); - return ( <> {children} ); + //return ( <> {children} ); + return ( + + {children} + + ); }; + +class ErrorBoundary extends React.Component<{children: React.ReactNode}, {hasError: boolean}> { + constructor(props: {children: React.ReactNode}) { + super(props); + this.state = { hasError: false }; + } + + static getDerivedStateFromError(_: Error) { + return { hasError: true }; + } + + componentDidCatch(error: Error, errorInfo: ErrorInfo) { + console.log('Error caught by ErrorBoundary:', error, errorInfo); + } + + render() { + if (this.state.hasError) { + return Something went wrong.; + } + + return this.props.children; + } +} diff --git a/components/theme/buttons/TextButton.tsx b/components/theme/buttons/TextButton.tsx index 3144657..5d1d09b 100644 --- a/components/theme/buttons/TextButton.tsx +++ b/components/theme/buttons/TextButton.tsx @@ -24,7 +24,7 @@ const TextButton = ({ width, height, text, fontSize, onPress }: Props ) => { { 'x-api-key': process.env.EXPO_PUBLIC_API_KEY ?? '', }, }); + console.log("InitialData API response: ", response); return response; } catch (error: unknown) { - console.error('Error getting user by Apple ID:', error); + console.error('Error getting Initial Data by Apple ID:', error); throw error; } }; -export const createUser = - async (appleId: string, email: string, fullName: string, pushToken: string) => { +export const createUser = async ( + appleId: string, email: string, fullName: string, pushToken: string +) => { try { const apiUrl = `${process.env.EXPO_PUBLIC_API_URL}/api/users/createUser`; const response = await fetch(apiUrl, { @@ -100,7 +102,8 @@ export const updateProfilePicture = async (userId: number, pfpUrl: string) => { export const checkRelationshipStatus = async (userId: number) => { try { - const apiUrl = `${process.env.EXPO_PUBLIC_API_URL}/api/users/checkRelationship`; + const apiUrl = + `${process.env.EXPO_PUBLIC_API_URL}/api/relationships/checkRelationship`; const response = await fetch((apiUrl + `?userId=${userId}`), { headers: { 'x-api-key': process.env.EXPO_PUBLIC_API_KEY ?? '', @@ -114,7 +117,7 @@ export const checkRelationshipStatus = async (userId: number) => { const relationshipData = await response.json() as RelationshipData; return relationshipData; } catch (error: unknown) { - console.error('Error checking relationship status:', error); + console.log('Error checking relationship status:', error); throw error; } }; diff --git a/constants/Colors.ts b/constants/Colors.ts index c57d228..b1d4081 100644 --- a/constants/Colors.ts +++ b/constants/Colors.ts @@ -17,8 +17,8 @@ export const Colors = { tabIconSelected: tintColorLight, }, dark: { - text: dark, - background: light, + text: light, + background: dark, tint: tintColorDark, icon: iconColorDark, tabIconDefault: iconColorDark,