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
|
# macOS
|
||||||
.DS_Store
|
.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 React, { useState } from 'react';
|
||||||
import { StyleSheet } from 'react-native';
|
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 UserInfo from '@/components/home/UserInfo';
|
||||||
import Relationship from '@/components/home/Relationship';
|
import RelationshipView from '@/components/home/RelationshipView';
|
||||||
|
|
||||||
const IndexScreen = () => {
|
const IndexScreen = () => {
|
||||||
const [pfpUrl, setPfpUrl] = useState<string | null>(null);
|
const [pfpUrl, setPfpUrl] = useState<string | null>(null);
|
||||||
@ -12,11 +12,12 @@ const IndexScreen = () => {
|
|||||||
return (
|
return (
|
||||||
<ThemedView style={styles.container}>
|
<ThemedView style={styles.container}>
|
||||||
<UserInfo onPfpUpdate={handlePfpUpdate} />
|
<UserInfo onPfpUpdate={handlePfpUpdate} />
|
||||||
<Relationship pfpUrl={pfpUrl} />
|
<RelationshipView pfpUrl={pfpUrl} />
|
||||||
<ThemedView style={styles.footerContainer}>
|
<ThemedView style={styles.footerContainer}>
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
);
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
export default IndexScreen;
|
export default IndexScreen;
|
||||||
|
|
||||||
|
@ -5,11 +5,16 @@ import {
|
|||||||
PushNotificationManager
|
PushNotificationManager
|
||||||
} from "@/components/services/notifications/PushNotificationManager";
|
} from "@/components/services/notifications/PushNotificationManager";
|
||||||
|
|
||||||
export default function RootLayout() {
|
const RootLayout = () => {
|
||||||
const [isSignedIn, setIsSignedIn] = useState(false);
|
const [isSignedIn, setIsSignedIn] = useState(false);
|
||||||
if (!isSignedIn)
|
console.log('RootLayout rendering, isSignedIn:', isSignedIn);
|
||||||
return (<SignInScreen onSignIn={() => setIsSignedIn(true)} />);
|
if (!isSignedIn) {
|
||||||
|
console.log('Rendering SignInScreen');
|
||||||
|
return (
|
||||||
|
<SignInScreen onSignIn={() => setIsSignedIn(true)} />
|
||||||
|
);
|
||||||
|
}
|
||||||
|
console.log('PushNotificationManager & Stack');
|
||||||
return (
|
return (
|
||||||
<PushNotificationManager>
|
<PushNotificationManager>
|
||||||
<Stack>
|
<Stack>
|
||||||
@ -19,3 +24,4 @@ export default function RootLayout() {
|
|||||||
</PushNotificationManager>
|
</PushNotificationManager>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
export default RootLayout;
|
||||||
|
@ -32,12 +32,12 @@ const SignInScreen = ({onSignIn}: {onSignIn: () => void}) => {
|
|||||||
});
|
});
|
||||||
console.log(
|
console.log(
|
||||||
credential.user, credential.email, credential.fullName?.givenName,
|
credential.user, credential.email, credential.fullName?.givenName,
|
||||||
credential.fullName?.familyName, pushToken
|
credential.fullName?.familyName, pushToken.data
|
||||||
);
|
);
|
||||||
|
|
||||||
const initialDataResponse = await getInitialDataByAppleId(credential.user);
|
const initialDataResponse = await getInitialDataByAppleId(credential.user);
|
||||||
|
|
||||||
console.log(initialDataResponse);
|
console.log("InitialData response: ", initialDataResponse);
|
||||||
if (initialDataResponse.status === 404 || !initialDataResponse.ok) {
|
if (initialDataResponse.status === 404 || !initialDataResponse.ok) {
|
||||||
if (!credential.user || !credential.email ||
|
if (!credential.user || !credential.email ||
|
||||||
!credential.fullName?.givenName || !credential.fullName?.familyName ||
|
!credential.fullName?.givenName || !credential.fullName?.familyName ||
|
||||||
@ -56,7 +56,7 @@ const SignInScreen = ({onSignIn}: {onSignIn: () => void}) => {
|
|||||||
const user: User = await createUser(
|
const user: User = await createUser(
|
||||||
credential.user,
|
credential.user,
|
||||||
credential.email,
|
credential.email,
|
||||||
credential.fullName?.givenName + credential.fullName?.familyName,
|
credential.fullName?.givenName + ' ' + credential.fullName?.familyName,
|
||||||
pushToken.data
|
pushToken.data
|
||||||
) as User;
|
) as User;
|
||||||
await saveUser(user);
|
await saveUser(user);
|
||||||
|
@ -13,7 +13,7 @@ type RelationshipProps = {
|
|||||||
pfpUrl: string | null;
|
pfpUrl: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Relationship: React.FC<RelationshipProps> = ({ pfpUrl }) => {
|
const RelationshipView: React.FC<RelationshipProps> = ({ pfpUrl }) => {
|
||||||
const [status, setStatus] = useState<RelationshipData | null>(null);
|
const [status, setStatus] = useState<RelationshipData | null>(null);
|
||||||
const [user, setUser] = useState<User | null>(null);
|
const [user, setUser] = useState<User | null>(null);
|
||||||
const [showRequestRelationship, setShowRequestRelationship] = useState(false);
|
const [showRequestRelationship, setShowRequestRelationship] = useState(false);
|
||||||
@ -253,7 +253,7 @@ const Relationship: React.FC<RelationshipProps> = ({ pfpUrl }) => {
|
|||||||
</ThemedView>
|
</ThemedView>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default Relationship;
|
export default RelationshipView;
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
@ -121,7 +121,7 @@ export const updateCountdown = async (updatedFields: Partial<any>) => {
|
|||||||
};
|
};
|
||||||
export const saveRelationshipData = async (relationshipData: RelationshipData) => {
|
export const saveRelationshipData = async (relationshipData: RelationshipData) => {
|
||||||
try {
|
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));
|
await SecureStore.setItemAsync('relationship', JSON.stringify(relationshipData.relationship));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error saving partner & relationship to SecureStore:', 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) => {
|
export const saveInitialData = async (initialData: InitialData) => {
|
||||||
try {
|
try {
|
||||||
await SecureStore.setItemAsync('user', JSON.stringify(initialData.user));
|
await SecureStore.setItemAsync('user', JSON.stringify(initialData.user));
|
||||||
|
if (initialData.relationshipData) {
|
||||||
await SecureStore.setItemAsync(
|
await SecureStore.setItemAsync(
|
||||||
'relationship', JSON.stringify(initialData.relationshipData.relationship)
|
'relationship', JSON.stringify(initialData.relationshipData.relationship)
|
||||||
);
|
);
|
||||||
await SecureStore.setItemAsync(
|
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));
|
await SecureStore.setItemAsync('countdown', JSON.stringify(initialData.countdown));
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error saving initial data to SecureStore:', 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 { Alert, Platform } from 'react-native';
|
||||||
import * as Device from 'expo-device';
|
import * as Device from 'expo-device';
|
||||||
import * as Notifications from 'expo-notifications';
|
import * as Notifications from 'expo-notifications';
|
||||||
import Constants from 'expo-constants';
|
import Constants from 'expo-constants';
|
||||||
import type { NotificationMessage } from '@/constants/Types';
|
import type { NotificationMessage } from '@/constants/Types';
|
||||||
|
import { ThemedText } from '@/components/theme/Theme';
|
||||||
|
|
||||||
Notifications.setNotificationHandler({
|
Notifications.setNotificationHandler({
|
||||||
handleNotification: async () => ({
|
handleNotification: async () => ({
|
||||||
@ -114,5 +115,33 @@ export const PushNotificationManager = ({children}: {children: React.ReactNode})
|
|||||||
Notifications.removeNotificationSubscription(responseListener.current);
|
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
|
<ThemedText
|
||||||
style={[
|
style={[
|
||||||
{
|
{
|
||||||
color: Colors[scheme].text,
|
color: Colors[scheme].background,
|
||||||
fontSize: fontSize ?? DEFAULT_FONT_SIZE
|
fontSize: fontSize ?? DEFAULT_FONT_SIZE
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
|
@ -11,15 +11,17 @@ export const getInitialDataByAppleId = async (appleId: string) => {
|
|||||||
'x-api-key': process.env.EXPO_PUBLIC_API_KEY ?? '',
|
'x-api-key': process.env.EXPO_PUBLIC_API_KEY ?? '',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
console.log("InitialData API response: ", response);
|
||||||
return response;
|
return response;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error('Error getting user by Apple ID:', error);
|
console.error('Error getting Initial Data by Apple ID:', error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createUser =
|
export const createUser = async (
|
||||||
async (appleId: string, email: string, fullName: string, pushToken: string) => {
|
appleId: string, email: string, fullName: string, pushToken: string
|
||||||
|
) => {
|
||||||
try {
|
try {
|
||||||
const apiUrl = `${process.env.EXPO_PUBLIC_API_URL}/api/users/createUser`;
|
const apiUrl = `${process.env.EXPO_PUBLIC_API_URL}/api/users/createUser`;
|
||||||
const response = await fetch(apiUrl, {
|
const response = await fetch(apiUrl, {
|
||||||
@ -100,7 +102,8 @@ export const updateProfilePicture = async (userId: number, pfpUrl: string) => {
|
|||||||
|
|
||||||
export const checkRelationshipStatus = async (userId: number) => {
|
export const checkRelationshipStatus = async (userId: number) => {
|
||||||
try {
|
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}`), {
|
const response = await fetch((apiUrl + `?userId=${userId}`), {
|
||||||
headers: {
|
headers: {
|
||||||
'x-api-key': process.env.EXPO_PUBLIC_API_KEY ?? '',
|
'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;
|
const relationshipData = await response.json() as RelationshipData;
|
||||||
return relationshipData;
|
return relationshipData;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error('Error checking relationship status:', error);
|
console.log('Error checking relationship status:', error);
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -17,8 +17,8 @@ export const Colors = {
|
|||||||
tabIconSelected: tintColorLight,
|
tabIconSelected: tintColorLight,
|
||||||
},
|
},
|
||||||
dark: {
|
dark: {
|
||||||
text: dark,
|
text: light,
|
||||||
background: light,
|
background: dark,
|
||||||
tint: tintColorDark,
|
tint: tintColorDark,
|
||||||
icon: iconColorDark,
|
icon: iconColorDark,
|
||||||
tabIconDefault: iconColorDark,
|
tabIconDefault: iconColorDark,
|
||||||
|
Loading…
Reference in New Issue
Block a user