Fixed initial errors
This commit is contained in:
parent
3eeffb789f
commit
cc8e0c623c
6
.gitignore
vendored
6
.gitignore
vendored
@ -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
|
@ -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<string | null>(null);
|
||||
@ -12,11 +12,12 @@ const IndexScreen = () => {
|
||||
return (
|
||||
<ThemedView style={styles.container}>
|
||||
<UserInfo onPfpUpdate={handlePfpUpdate} />
|
||||
<Relationship pfpUrl={pfpUrl} />
|
||||
<RelationshipView pfpUrl={pfpUrl} />
|
||||
<ThemedView style={styles.footerContainer}>
|
||||
</ThemedView>
|
||||
</ThemedView>
|
||||
);
|
||||
|
||||
};
|
||||
export default IndexScreen;
|
||||
|
||||
|
@ -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 (<SignInScreen onSignIn={() => setIsSignedIn(true)} />);
|
||||
|
||||
console.log('RootLayout rendering, isSignedIn:', isSignedIn);
|
||||
if (!isSignedIn) {
|
||||
console.log('Rendering SignInScreen');
|
||||
return (
|
||||
<SignInScreen onSignIn={() => setIsSignedIn(true)} />
|
||||
);
|
||||
}
|
||||
console.log('PushNotificationManager & Stack');
|
||||
return (
|
||||
<PushNotificationManager>
|
||||
<Stack>
|
||||
@ -19,3 +24,4 @@ export default function RootLayout() {
|
||||
</PushNotificationManager>
|
||||
);
|
||||
}
|
||||
export default RootLayout;
|
||||
|
@ -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);
|
||||
|
@ -13,7 +13,7 @@ type RelationshipProps = {
|
||||
pfpUrl: string | null;
|
||||
};
|
||||
|
||||
const Relationship: React.FC<RelationshipProps> = ({ pfpUrl }) => {
|
||||
const RelationshipView: React.FC<RelationshipProps> = ({ pfpUrl }) => {
|
||||
const [status, setStatus] = useState<RelationshipData | null>(null);
|
||||
const [user, setUser] = useState<User | null>(null);
|
||||
const [showRequestRelationship, setShowRequestRelationship] = useState(false);
|
||||
@ -253,7 +253,7 @@ const Relationship: React.FC<RelationshipProps> = ({ pfpUrl }) => {
|
||||
</ThemedView>
|
||||
);
|
||||
};
|
||||
export default Relationship;
|
||||
export default RelationshipView;
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
container: {
|
@ -121,7 +121,7 @@ export const updateCountdown = async (updatedFields: Partial<any>) => {
|
||||
};
|
||||
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));
|
||||
if (initialData.relationshipData) {
|
||||
await SecureStore.setItemAsync(
|
||||
'relationship', JSON.stringify(initialData.relationshipData.relationship)
|
||||
);
|
||||
await SecureStore.setItemAsync(
|
||||
'partner', JSON.stringify(initialData.relationshipData.Partner)
|
||||
'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);
|
||||
}
|
||||
|
@ -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 (
|
||||
<ErrorBoundary>
|
||||
{children}
|
||||
</ErrorBoundary>
|
||||
);
|
||||
};
|
||||
|
||||
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 <ThemedText>Something went wrong.</ThemedText>;
|
||||
}
|
||||
|
||||
return this.props.children;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ const TextButton = ({ width, height, text, fontSize, onPress }: Props ) => {
|
||||
<ThemedText
|
||||
style={[
|
||||
{
|
||||
color: Colors[scheme].text,
|
||||
color: Colors[scheme].background,
|
||||
fontSize: fontSize ?? DEFAULT_FONT_SIZE
|
||||
}
|
||||
]}
|
||||
|
@ -11,15 +11,17 @@ export const getInitialDataByAppleId = async (appleId: string) => {
|
||||
'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;
|
||||
}
|
||||
};
|
||||
|
@ -17,8 +17,8 @@ export const Colors = {
|
||||
tabIconSelected: tintColorLight,
|
||||
},
|
||||
dark: {
|
||||
text: dark,
|
||||
background: light,
|
||||
text: light,
|
||||
background: dark,
|
||||
tint: tintColorDark,
|
||||
icon: iconColorDark,
|
||||
tabIconDefault: iconColorDark,
|
||||
|
Loading…
Reference in New Issue
Block a user