rewrite finished i believe
This commit is contained in:
@ -23,6 +23,18 @@ export const getUser = async () => {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
export const updateUser = async (updatedFields: Partial<any>) => {
|
||||
try {
|
||||
const currentUser: User = await getUser() as User;
|
||||
if (!currentUser) return null;
|
||||
const updatedUser: User = { ...currentUser, ...updatedFields };
|
||||
await saveUser(updatedUser);
|
||||
return updatedUser as User;
|
||||
} catch (error) {
|
||||
console.error('Error updating user data: ', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
export const savePartner = async (partner: User) => {
|
||||
try {
|
||||
await SecureStore.setItemAsync('partner', JSON.stringify(partner));
|
||||
@ -39,6 +51,18 @@ export const getPartner = async () => {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
export const updatePartner = async (updatedFields: Partial<any>) => {
|
||||
try {
|
||||
const currentPartner: User = await getPartner() as User;
|
||||
if (!currentPartner) return null;
|
||||
const updatedPartner: User = { ...currentPartner, ...updatedFields };
|
||||
await saveUser(updatedPartner);
|
||||
return updatedPartner as User;
|
||||
} catch (error) {
|
||||
console.error('Error updating user data: ', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
export const saveRelationship = async (relationship: Relationship) => {
|
||||
try {
|
||||
await SecureStore.setItemAsync('relationship', JSON.stringify(relationship));
|
||||
@ -55,6 +79,18 @@ export const getRelationship = async () => {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
export const updateRelationship = async (updatedFields: Partial<any>) => {
|
||||
try {
|
||||
const currentRelationship: Relationship = await getRelationship() as Relationship;
|
||||
if (!currentRelationship) return null;
|
||||
const updatedRelationship: Relationship = { ...currentRelationship, ...updatedFields };
|
||||
await saveRelationship(updatedRelationship);
|
||||
return updatedRelationship as Relationship;
|
||||
} catch (error) {
|
||||
console.error('Error updating relationship data: ', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
export const saveCountdown = async (countdown: Countdown) => {
|
||||
try {
|
||||
await SecureStore.setItemAsync('countdown', JSON.stringify(countdown));
|
||||
@ -71,6 +107,18 @@ export const getCountdown = async () => {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
export const updateCountdown = async (updatedFields: Partial<any>) => {
|
||||
try {
|
||||
const currentCountdown: Countdown = await getCountdown() as Countdown;
|
||||
if (!currentCountdown) return null;
|
||||
const updatedCountdown: Countdown = { ...currentCountdown, ...updatedFields };
|
||||
await saveCountdown(updatedCountdown);
|
||||
return updatedCountdown as Countdown;
|
||||
} catch (error) {
|
||||
console.error('Error updating countdown data: ', error);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
export const saveRelationshipData = async (relationshipData: RelationshipData) => {
|
||||
try {
|
||||
await SecureStore.setItemAsync('partner', JSON.stringify(relationshipData.Partner));
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { Platform } from 'react-native';
|
||||
import { Alert, Platform } from 'react-native';
|
||||
import * as Device from 'expo-device';
|
||||
import * as Notifications from 'expo-notifications';
|
||||
import Constants from 'expo-constants';
|
||||
@ -13,7 +13,11 @@ Notifications.setNotificationHandler({
|
||||
}),
|
||||
});
|
||||
|
||||
export const sendPushNotification = async(expoPushToken: string, notification: NotificationMessage) => {
|
||||
export const sendPushNotification = async(expoPushToken: string | null, notification: NotificationMessage) => {
|
||||
if (!expoPushToken) {
|
||||
Alert.alert('Error', 'No push token found.');
|
||||
return;
|
||||
}
|
||||
const message = {
|
||||
to: expoPushToken,
|
||||
sound: notification.sound ?? 'default',
|
||||
@ -21,15 +25,22 @@ export const sendPushNotification = async(expoPushToken: string, notification: N
|
||||
body: notification.body,
|
||||
data: notification.data ?? {},
|
||||
};
|
||||
await fetch('https://exp.host/--/api/v2/push/send', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Accept-encoding': 'gzip, deflate',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(message),
|
||||
try {
|
||||
const response = await fetch('https://exp.host/--/api/v2/push/send', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Accept-encoding': 'gzip, deflate',
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(message),
|
||||
});
|
||||
const result = await response.json();
|
||||
console.log('Push notification sent:', result);
|
||||
} catch (error) {
|
||||
console.error('Error sending push notification:', error);
|
||||
Alert.alert('Error', 'Failed to send push notification.');
|
||||
}
|
||||
};
|
||||
|
||||
const handleRegistrationError = (errorMessage: string) => {
|
||||
|
Reference in New Issue
Block a user