mirror of
https://github.com/urosran/cally.git
synced 2025-11-26 16:34:54 +00:00
Merge branch 'main' into dev
This commit is contained in:
2
app.json
2
app.json
@ -16,7 +16,7 @@
|
|||||||
"supportsTablet": true,
|
"supportsTablet": true,
|
||||||
"bundleIdentifier": "com.cally.app",
|
"bundleIdentifier": "com.cally.app",
|
||||||
"googleServicesFile": "./ios/GoogleService-Info.plist",
|
"googleServicesFile": "./ios/GoogleService-Info.plist",
|
||||||
"buildNumber": "40",
|
"buildNumber": "52",
|
||||||
"usesAppleSignIn": true
|
"usesAppleSignIn": true
|
||||||
},
|
},
|
||||||
"android": {
|
"android": {
|
||||||
|
|||||||
@ -161,6 +161,7 @@ export const ManuallyAddEventModal = () => {
|
|||||||
if (editEvent?.id) eventData.id = editEvent?.id
|
if (editEvent?.id) eventData.id = editEvent?.id
|
||||||
|
|
||||||
await createEvent(eventData);
|
await createEvent(eventData);
|
||||||
|
setEditEvent(undefined)
|
||||||
|
|
||||||
close();
|
close();
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,7 +8,7 @@ const Entry = () => {
|
|||||||
const [tab, setTab] = useState<"register" | "login" | "reset-password">("login");
|
const [tab, setTab] = useState<"register" | "login" | "reset-password">("login");
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View>
|
<View style={{height:"100%"}}>
|
||||||
{tab === "register" && <SignUpPage setTab={setTab}/>}
|
{tab === "register" && <SignUpPage setTab={setTab}/>}
|
||||||
{tab === "login" && <SignInPage setTab={setTab}/>}
|
{tab === "login" && <SignInPage setTab={setTab}/>}
|
||||||
{tab === "reset-password" && <ResetPasswordPage setTab={setTab}/>}
|
{tab === "reset-password" && <ResetPasswordPage setTab={setTab}/>}
|
||||||
|
|||||||
@ -167,7 +167,7 @@ const SignInPage = ({
|
|||||||
bottom
|
bottom
|
||||||
width="100%"
|
width="100%"
|
||||||
height="70%"
|
height="70%"
|
||||||
containerStyle={{ padding: 0 }}
|
containerStyle={{ padding: 15, backgroundColor:"white" }}
|
||||||
>
|
>
|
||||||
{hasPermission === null ? (
|
{hasPermission === null ? (
|
||||||
<Text>Requesting camera permissions...</Text>
|
<Text>Requesting camera permissions...</Text>
|
||||||
@ -175,7 +175,7 @@ const SignInPage = ({
|
|||||||
<Text>No access to camera</Text>
|
<Text>No access to camera</Text>
|
||||||
) : (
|
) : (
|
||||||
<CameraView
|
<CameraView
|
||||||
style={{ flex: 1 }}
|
style={{ flex: 1, borderRadius: 15 }}
|
||||||
onBarcodeScanned={handleQrCodeScanned}
|
onBarcodeScanned={handleQrCodeScanned}
|
||||||
barcodeScannerSettings={{
|
barcodeScannerSettings={{
|
||||||
barcodeTypes: ["qr"],
|
barcodeTypes: ["qr"],
|
||||||
@ -186,7 +186,7 @@ const SignInPage = ({
|
|||||||
label="Cancel"
|
label="Cancel"
|
||||||
onPress={() => setShowCameraDialog(false)}
|
onPress={() => setShowCameraDialog(false)}
|
||||||
backgroundColor="#fd1775"
|
backgroundColor="#fd1775"
|
||||||
style={{ margin: 10 }}
|
style={{ margin: 10, marginBottom: 30 }}
|
||||||
/>
|
/>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
@ -1,218 +1,218 @@
|
|||||||
import React, { useRef, useState } from "react";
|
import React, {useRef, useState} from "react";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
ButtonSize,
|
ButtonSize,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
Text,
|
Text,
|
||||||
TextField,
|
TextField,
|
||||||
TextFieldRef,
|
TextFieldRef,
|
||||||
TouchableOpacity,
|
TouchableOpacity,
|
||||||
View,
|
View,
|
||||||
} from "react-native-ui-lib";
|
} from "react-native-ui-lib";
|
||||||
import { useSignUp } from "@/hooks/firebase/useSignUp";
|
import {useSignUp} from "@/hooks/firebase/useSignUp";
|
||||||
import { ProfileType } from "@/contexts/AuthContext";
|
import {StyleSheet} from "react-native";
|
||||||
import { Dimensions, StyleSheet } from "react-native";
|
import {AntDesign} from "@expo/vector-icons";
|
||||||
import { AntDesign } from "@expo/vector-icons";
|
|
||||||
|
|
||||||
const SignUpPage = ({
|
const SignUpPage = ({
|
||||||
setTab,
|
setTab,
|
||||||
}: {
|
}: {
|
||||||
setTab: React.Dispatch<
|
setTab: React.Dispatch<
|
||||||
React.SetStateAction<"register" | "login" | "reset-password">
|
React.SetStateAction<"register" | "login" | "reset-password">
|
||||||
>;
|
>;
|
||||||
}) => {
|
}) => {
|
||||||
const [email, setEmail] = useState<string>("");
|
const [email, setEmail] = useState<string>("");
|
||||||
const [firstName, setFirstName] = useState<string>("");
|
const [firstName, setFirstName] = useState<string>("");
|
||||||
const [lastName, setLastName] = useState<string>("");
|
const [lastName, setLastName] = useState<string>("");
|
||||||
const [password, setPassword] = useState<string>("");
|
const [password, setPassword] = useState<string>("");
|
||||||
|
|
||||||
const [isPasswordVisible, setIsPasswordVisible] = useState<boolean>(false);
|
const [isPasswordVisible, setIsPasswordVisible] = useState<boolean>(false);
|
||||||
const [allowFaceID, setAllowFaceID] = useState<boolean>(false);
|
const [allowFaceID, setAllowFaceID] = useState<boolean>(false);
|
||||||
const [acceptTerms, setAcceptTerms] = useState<boolean>(false);
|
const [acceptTerms, setAcceptTerms] = useState<boolean>(false);
|
||||||
const { mutateAsync: signUp } = useSignUp();
|
const {mutateAsync: signUp} = useSignUp();
|
||||||
|
|
||||||
const lnameRef = useRef<TextFieldRef>(null);
|
const lnameRef = useRef<TextFieldRef>(null);
|
||||||
const emailRef = useRef<TextFieldRef>(null);
|
const emailRef = useRef<TextFieldRef>(null);
|
||||||
const passwordRef = useRef<TextFieldRef>(null);
|
const passwordRef = useRef<TextFieldRef>(null);
|
||||||
|
|
||||||
const handleSignUp = async () => {
|
const handleSignUp = async () => {
|
||||||
await signUp({ email, password, firstName, lastName });
|
await signUp({email, password, firstName, lastName});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View padding-15 marginT-30 height={Dimensions.get("window").height} flexG>
|
<View height={"100%"} padding-15 marginT-30>
|
||||||
<Text style={styles.title}>Get started with Cally</Text>
|
<Text style={styles.title}>Get started with Cally</Text>
|
||||||
<Text style={styles.subtitle} marginT-15 color="#919191">
|
<Text style={styles.subtitle} marginT-15 color="#919191">
|
||||||
Please enter your details.
|
Please enter your details.
|
||||||
</Text>
|
|
||||||
<TextField
|
|
||||||
marginT-30
|
|
||||||
autoFocus
|
|
||||||
placeholder="First name"
|
|
||||||
value={firstName}
|
|
||||||
onChangeText={setFirstName}
|
|
||||||
style={styles.textfield}
|
|
||||||
onSubmitEditing={() => {
|
|
||||||
lnameRef.current?.focus();
|
|
||||||
}}
|
|
||||||
blurOnSubmit={false}
|
|
||||||
/>
|
|
||||||
<TextField
|
|
||||||
ref={lnameRef}
|
|
||||||
placeholder="Last name"
|
|
||||||
value={lastName}
|
|
||||||
onChangeText={setLastName}
|
|
||||||
style={styles.textfield}
|
|
||||||
onSubmitEditing={() => {
|
|
||||||
emailRef.current?.focus();
|
|
||||||
}}
|
|
||||||
blurOnSubmit={false}
|
|
||||||
/>
|
|
||||||
<TextField
|
|
||||||
ref={emailRef}
|
|
||||||
placeholder="Email"
|
|
||||||
value={email}
|
|
||||||
onChangeText={setEmail}
|
|
||||||
style={styles.textfield}
|
|
||||||
onSubmitEditing={() => {
|
|
||||||
passwordRef.current?.focus();
|
|
||||||
}}
|
|
||||||
blurOnSubmit={false}
|
|
||||||
/>
|
|
||||||
<View
|
|
||||||
centerV
|
|
||||||
style={[styles.textfield, { padding: 0, paddingHorizontal: 30 }]}
|
|
||||||
>
|
|
||||||
<TextField
|
|
||||||
ref={passwordRef}
|
|
||||||
placeholder="Password"
|
|
||||||
style={styles.jakartaLight}
|
|
||||||
value={password}
|
|
||||||
onChangeText={setPassword}
|
|
||||||
secureTextEntry={!isPasswordVisible}
|
|
||||||
trailingAccessory={
|
|
||||||
<TouchableOpacity
|
|
||||||
onPress={() => setIsPasswordVisible(!isPasswordVisible)}
|
|
||||||
>
|
|
||||||
<AntDesign
|
|
||||||
name={isPasswordVisible ? "eye" : "eyeo"}
|
|
||||||
size={24}
|
|
||||||
color="gray"
|
|
||||||
/>
|
|
||||||
</TouchableOpacity>
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
</View>
|
|
||||||
<View gap-5 marginT-15>
|
|
||||||
<View row centerV>
|
|
||||||
<Checkbox
|
|
||||||
style={[styles.check]}
|
|
||||||
color="#919191"
|
|
||||||
value={allowFaceID}
|
|
||||||
onValueChange={(value) => {
|
|
||||||
setAllowFaceID(value);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Text style={styles.jakartaLight} marginL-10>
|
|
||||||
Allow FaceID for login in future
|
|
||||||
</Text>
|
|
||||||
</View>
|
|
||||||
<View row centerV>
|
|
||||||
<Checkbox
|
|
||||||
style={styles.check}
|
|
||||||
color="#919191"
|
|
||||||
value={acceptTerms}
|
|
||||||
onValueChange={(value) => setAcceptTerms(value)}
|
|
||||||
/>
|
|
||||||
<View row>
|
|
||||||
<Text style={styles.jakartaLight} marginL-10>
|
|
||||||
I accept the
|
|
||||||
</Text>
|
</Text>
|
||||||
<TouchableOpacity>
|
<TextField
|
||||||
<Text text90 style={styles.jakartaMedium}>
|
marginT-30
|
||||||
{" "}
|
autoFocus
|
||||||
terms and conditions
|
placeholder="First name"
|
||||||
</Text>
|
value={firstName}
|
||||||
</TouchableOpacity>
|
onChangeText={setFirstName}
|
||||||
<Text style={styles.jakartaLight}> and </Text>
|
style={styles.textfield}
|
||||||
<TouchableOpacity>
|
onSubmitEditing={() => {
|
||||||
<Text text90 style={styles.jakartaMedium}>
|
lnameRef.current?.focus();
|
||||||
{" "}
|
}}
|
||||||
privacy policy
|
blurOnSubmit={false}
|
||||||
</Text>
|
/>
|
||||||
</TouchableOpacity>
|
<TextField
|
||||||
</View>
|
ref={lnameRef}
|
||||||
</View>
|
placeholder="Last name"
|
||||||
</View>
|
value={lastName}
|
||||||
<View style={styles.bottomView}>
|
onChangeText={setLastName}
|
||||||
<Button
|
style={styles.textfield}
|
||||||
label="Register"
|
onSubmitEditing={() => {
|
||||||
labelStyle={{
|
emailRef.current?.focus();
|
||||||
fontFamily: "PlusJakartaSans_600SemiBold",
|
}}
|
||||||
fontSize: 16,
|
blurOnSubmit={false}
|
||||||
}}
|
/>
|
||||||
onPress={handleSignUp}
|
<TextField
|
||||||
style={{ marginBottom: 0, backgroundColor: "#fd1775", height: 50 }}
|
ref={emailRef}
|
||||||
/>
|
placeholder="Email"
|
||||||
<View row centerH marginT-10 marginB-2 gap-5>
|
value={email}
|
||||||
<Text style={[styles.jakartaLight, { fontSize: 16, color: "#484848" }]} center>
|
onChangeText={setEmail}
|
||||||
Already have an account?
|
style={styles.textfield}
|
||||||
</Text>
|
onSubmitEditing={() => {
|
||||||
|
passwordRef.current?.focus();
|
||||||
|
}}
|
||||||
|
blurOnSubmit={false}
|
||||||
|
/>
|
||||||
|
<View
|
||||||
|
centerV
|
||||||
|
style={[styles.textfield, {padding: 0, paddingHorizontal: 30}]}
|
||||||
|
>
|
||||||
|
<TextField
|
||||||
|
ref={passwordRef}
|
||||||
|
placeholder="Password"
|
||||||
|
style={styles.jakartaLight}
|
||||||
|
value={password}
|
||||||
|
onChangeText={setPassword}
|
||||||
|
secureTextEntry={!isPasswordVisible}
|
||||||
|
trailingAccessory={
|
||||||
|
<TouchableOpacity
|
||||||
|
onPress={() => setIsPasswordVisible(!isPasswordVisible)}
|
||||||
|
>
|
||||||
|
<AntDesign
|
||||||
|
name={isPasswordVisible ? "eye" : "eyeo"}
|
||||||
|
size={24}
|
||||||
|
color="gray"
|
||||||
|
/>
|
||||||
|
</TouchableOpacity>
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
<View gap-5 marginT-15>
|
||||||
|
<View row centerV>
|
||||||
|
<Checkbox
|
||||||
|
style={[styles.check]}
|
||||||
|
color="#919191"
|
||||||
|
value={allowFaceID}
|
||||||
|
onValueChange={(value) => {
|
||||||
|
setAllowFaceID(value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Text style={styles.jakartaLight} marginL-10>
|
||||||
|
Allow FaceID for login in future
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
<View row centerV>
|
||||||
|
<Checkbox
|
||||||
|
style={styles.check}
|
||||||
|
color="#919191"
|
||||||
|
value={acceptTerms}
|
||||||
|
onValueChange={(value) => setAcceptTerms(value)}
|
||||||
|
/>
|
||||||
|
<View row>
|
||||||
|
<Text style={styles.jakartaLight} marginL-10>
|
||||||
|
I accept the
|
||||||
|
</Text>
|
||||||
|
<TouchableOpacity>
|
||||||
|
<Text text90 style={styles.jakartaMedium}>
|
||||||
|
{" "}
|
||||||
|
terms and conditions
|
||||||
|
</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
<Text style={styles.jakartaLight}> and </Text>
|
||||||
|
<TouchableOpacity>
|
||||||
|
<Text text90 style={styles.jakartaMedium}>
|
||||||
|
{" "}
|
||||||
|
privacy policy
|
||||||
|
</Text>
|
||||||
|
</TouchableOpacity>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
<View flex-1/>
|
||||||
|
<View style={styles.bottomView}>
|
||||||
|
<Button
|
||||||
|
label="Register"
|
||||||
|
labelStyle={{
|
||||||
|
fontFamily: "PlusJakartaSans_600SemiBold",
|
||||||
|
fontSize: 16,
|
||||||
|
}}
|
||||||
|
onPress={handleSignUp}
|
||||||
|
style={{marginBottom: 0, backgroundColor: "#fd1775", height: 50}}
|
||||||
|
/>
|
||||||
|
<View row centerH marginT-10 marginB-2 gap-5>
|
||||||
|
<Text style={[styles.jakartaLight, {fontSize: 16, color: "#484848"}]} center>
|
||||||
|
Already have an account?
|
||||||
|
</Text>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
label="Log in"
|
label="Log in"
|
||||||
labelStyle={[
|
labelStyle={[
|
||||||
styles.jakartaMedium,
|
styles.jakartaMedium,
|
||||||
{ fontSize: 16, textDecorationLine: "none", color: "#fd1775" },
|
{fontSize: 16, textDecorationLine: "none", color: "#fd1775"},
|
||||||
]}
|
]}
|
||||||
flexS
|
flexS
|
||||||
margin-0
|
margin-0
|
||||||
link
|
link
|
||||||
color="#fd1775"
|
color="#fd1775"
|
||||||
size={ButtonSize.small}
|
size={ButtonSize.small}
|
||||||
text70
|
text70
|
||||||
onPress={() => setTab("login")}
|
onPress={() => setTab("login")}
|
||||||
/>
|
/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
);
|
||||||
</View>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default SignUpPage;
|
export default SignUpPage;
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
textfield: {
|
textfield: {
|
||||||
backgroundColor: "white",
|
backgroundColor: "white",
|
||||||
marginVertical: 8,
|
marginVertical: 8,
|
||||||
padding: 30,
|
padding: 30,
|
||||||
height: 44,
|
height: 44,
|
||||||
borderRadius: 50,
|
borderRadius: 50,
|
||||||
fontFamily: "PlusJakartaSans_300Light",
|
fontFamily: "PlusJakartaSans_300Light",
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
color: "#919191",
|
color: "#919191",
|
||||||
},
|
},
|
||||||
//mora da se izmeni kako treba
|
//mora da se izmeni kako treba
|
||||||
bottomView: { marginTop: "auto", marginBottom: 30 },
|
bottomView: {marginTop: "auto", marginBottom: 30, marginTop: "auto"},
|
||||||
jakartaLight: {
|
jakartaLight: {
|
||||||
fontFamily: "PlusJakartaSans_300Light",
|
fontFamily: "PlusJakartaSans_300Light",
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
color: "#919191",
|
color: "#919191",
|
||||||
},
|
},
|
||||||
jakartaMedium: {
|
jakartaMedium: {
|
||||||
fontFamily: "PlusJakartaSans_500Medium",
|
fontFamily: "PlusJakartaSans_500Medium",
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
color: "#919191",
|
color: "#919191",
|
||||||
textDecorationLine: "underline",
|
textDecorationLine: "underline",
|
||||||
},
|
},
|
||||||
title: { fontFamily: "Manrope_600SemiBold", fontSize: 34, marginTop: 50 },
|
title: {fontFamily: "Manrope_600SemiBold", fontSize: 34, marginTop: 50},
|
||||||
subtitle: { fontFamily: "PlusJakartaSans_400Regular", fontSize: 16 },
|
subtitle: {fontFamily: "PlusJakartaSans_400Regular", fontSize: 16},
|
||||||
check: {
|
check: {
|
||||||
borderRadius: 3,
|
borderRadius: 3,
|
||||||
aspectRatio: 1,
|
aspectRatio: 1,
|
||||||
width: 18,
|
width: 18,
|
||||||
color: "#919191",
|
color: "#919191",
|
||||||
borderColor: "#919191",
|
borderColor: "#919191",
|
||||||
borderWidth: 1,
|
borderWidth: 1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@ -67,10 +67,10 @@ const MyGroup = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedStatus !== ProfileType.FAMILY_DEVICE && !email) {
|
// if (selectedStatus !== ProfileType.FAMILY_DEVICE && !email) {
|
||||||
console.error("Email is required for non-family device users");
|
// console.error("Email is required for non-family device users");
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (email && !email.includes("@")) {
|
if (email && !email.includes("@")) {
|
||||||
console.error("Invalid email address");
|
console.error("Invalid email address");
|
||||||
|
|||||||
@ -18,7 +18,12 @@ exports.sendNotificationOnEventCreation = functions.firestore
|
|||||||
.document('Events/{eventId}')
|
.document('Events/{eventId}')
|
||||||
.onCreate(async (snapshot, context) => {
|
.onCreate(async (snapshot, context) => {
|
||||||
const eventData = snapshot.data();
|
const eventData = snapshot.data();
|
||||||
const {familyId, creatorId} = eventData;
|
const {familyId, creatorId, email} = eventData;
|
||||||
|
|
||||||
|
if (email) {
|
||||||
|
console.log('Event has an email field. Skipping notification.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!familyId || !creatorId) {
|
if (!familyId || !creatorId) {
|
||||||
console.error('Missing familyId or creatorId in event data');
|
console.error('Missing familyId or creatorId in event data');
|
||||||
@ -33,14 +38,12 @@ exports.sendNotificationOnEventCreation = functions.firestore
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increment event count for debouncing
|
|
||||||
eventCount++;
|
eventCount++;
|
||||||
|
|
||||||
if (notificationTimeout) {
|
if (notificationTimeout) {
|
||||||
clearTimeout(notificationTimeout); // Reset the timer if events keep coming
|
clearTimeout(notificationTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set a debounce time (e.g., 5 seconds)
|
|
||||||
notificationTimeout = setTimeout(async () => {
|
notificationTimeout = setTimeout(async () => {
|
||||||
const eventMessage = eventCount === 1
|
const eventMessage = eventCount === 1
|
||||||
? `An event "${eventData.title}" has been added. Check it out!`
|
? `An event "${eventData.title}" has been added. Check it out!`
|
||||||
@ -88,7 +91,7 @@ exports.sendNotificationOnEventCreation = functions.firestore
|
|||||||
eventCount = 0; // Reset the event count after sending notification
|
eventCount = 0; // Reset the event count after sending notification
|
||||||
pushTokens = []; // Reset push tokens for the next round
|
pushTokens = []; // Reset push tokens for the next round
|
||||||
|
|
||||||
}, 5000); // Debounce time (5 seconds)
|
}, 5000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -15,7 +15,7 @@ export const useCreateSubUser = () => {
|
|||||||
return await functions().httpsCallable("createSubUser")({
|
return await functions().httpsCallable("createSubUser")({
|
||||||
...userProfile,
|
...userProfile,
|
||||||
email,
|
email,
|
||||||
familyId: profileData?.familyId
|
familyId: profileData?.familyId!
|
||||||
}) as HttpsCallableResult<{ userId: string }>
|
}) as HttpsCallableResult<{ userId: string }>
|
||||||
} else {
|
} else {
|
||||||
throw Error("Can't create sub-users as a non-parent.")
|
throw Error("Can't create sub-users as a non-parent.")
|
||||||
|
|||||||
@ -1,23 +1,24 @@
|
|||||||
import {useQuery} from "react-query";
|
import { useQuery } from "react-query";
|
||||||
import firestore from "@react-native-firebase/firestore";
|
import firestore from "@react-native-firebase/firestore";
|
||||||
import {useAuthContext} from "@/contexts/AuthContext";
|
import { useAuthContext } from "@/contexts/AuthContext";
|
||||||
import {useAtomValue} from "jotai";
|
import { useAtomValue } from "jotai";
|
||||||
import {isFamilyViewAtom} from "@/components/pages/calendar/atoms";
|
import { isFamilyViewAtom } from "@/components/pages/calendar/atoms";
|
||||||
import {colorMap} from "@/constants/colorMap";
|
import { colorMap } from "@/constants/colorMap";
|
||||||
|
|
||||||
export const useGetEvents = () => {
|
export const useGetEvents = () => {
|
||||||
const {user, profileData} = useAuthContext();
|
const { user, profileData } = useAuthContext();
|
||||||
const isFamilyView = useAtomValue(isFamilyViewAtom);
|
const isFamilyView = useAtomValue(isFamilyViewAtom);
|
||||||
|
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: ["events", user?.uid, isFamilyView],
|
queryKey: ["events", user?.uid, isFamilyView],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const db = firestore();
|
const db = firestore();
|
||||||
|
|
||||||
const userId = user?.uid;
|
const userId = user?.uid;
|
||||||
const familyId = profileData?.familyId;
|
const familyId = profileData?.familyId;
|
||||||
|
|
||||||
let allEvents = [];
|
let allEvents = [];
|
||||||
|
|
||||||
|
// If family view is active, include family, creator, and attendee events
|
||||||
if (isFamilyView) {
|
if (isFamilyView) {
|
||||||
const familyQuery = db.collection("Events").where("familyID", "==", familyId);
|
const familyQuery = db.collection("Events").where("familyID", "==", familyId);
|
||||||
const creatorQuery = db.collection("Events").where("creatorId", "==", userId);
|
const creatorQuery = db.collection("Events").where("creatorId", "==", userId);
|
||||||
@ -29,12 +30,14 @@ export const useGetEvents = () => {
|
|||||||
attendeeQuery.get(),
|
attendeeQuery.get(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Collect all events
|
||||||
const familyEvents = familySnapshot.docs.map(doc => doc.data());
|
const familyEvents = familySnapshot.docs.map(doc => doc.data());
|
||||||
const creatorEvents = creatorSnapshot.docs.map(doc => doc.data());
|
const creatorEvents = creatorSnapshot.docs.map(doc => doc.data());
|
||||||
const attendeeEvents = attendeeSnapshot.docs.map(doc => doc.data());
|
const attendeeEvents = attendeeSnapshot.docs.map(doc => doc.data());
|
||||||
|
|
||||||
allEvents = [...familyEvents, ...creatorEvents, ...attendeeEvents];
|
allEvents = [...familyEvents, ...creatorEvents, ...attendeeEvents];
|
||||||
} else {
|
} else {
|
||||||
|
// Only include creator and attendee events when family view is off
|
||||||
const creatorQuery = db.collection("Events").where("creatorId", "==", userId);
|
const creatorQuery = db.collection("Events").where("creatorId", "==", userId);
|
||||||
const attendeeQuery = db.collection("Events").where("attendees", "array-contains", userId);
|
const attendeeQuery = db.collection("Events").where("attendees", "array-contains", userId);
|
||||||
|
|
||||||
@ -49,19 +52,28 @@ export const useGetEvents = () => {
|
|||||||
allEvents = [...creatorEvents, ...attendeeEvents];
|
allEvents = [...creatorEvents, ...attendeeEvents];
|
||||||
}
|
}
|
||||||
|
|
||||||
allEvents = allEvents.filter((event, index, self) =>
|
// Use a Map to ensure uniqueness only for events with IDs
|
||||||
index === self.findIndex(e => e.id === event.id)
|
const uniqueEventsMap = new Map();
|
||||||
);
|
allEvents.forEach(event => {
|
||||||
|
if (event.id) {
|
||||||
|
uniqueEventsMap.set(event.id, event); // Ensure uniqueness for events with IDs
|
||||||
|
} else {
|
||||||
|
uniqueEventsMap.set(Math.random().toString(36), event); // Generate a temp key for events without ID
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const uniqueEvents = Array.from(uniqueEventsMap.values());
|
||||||
|
|
||||||
allEvents = allEvents.filter(event => {
|
// Filter out private events unless the user is the creator
|
||||||
|
const filteredEvents = uniqueEvents.filter(event => {
|
||||||
if (event.private) {
|
if (event.private) {
|
||||||
return event.creatorId === userId;
|
return event.creatorId === userId;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Attach event colors and return the final list of events
|
||||||
return await Promise.all(
|
return await Promise.all(
|
||||||
allEvents.map(async (event) => {
|
filteredEvents.map(async (event) => {
|
||||||
const profileSnapshot = await db
|
const profileSnapshot = await db
|
||||||
.collection("Profiles")
|
.collection("Profiles")
|
||||||
.doc(event.creatorId)
|
.doc(event.creatorId)
|
||||||
@ -71,13 +83,13 @@ export const useGetEvents = () => {
|
|||||||
const eventColor = profileData?.eventColor || colorMap.pink;
|
const eventColor = profileData?.eventColor || colorMap.pink;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: event.id,
|
id: event.id || Math.random().toString(36).substr(2, 9), // Generate temp ID if missing
|
||||||
title: event.title,
|
title: event.title,
|
||||||
start: new Date(event.startDate.seconds * 1000),
|
start: new Date(event.startDate.seconds * 1000),
|
||||||
end: new Date(event.endDate.seconds * 1000),
|
end: new Date(event.endDate.seconds * 1000),
|
||||||
hideHours: event.allDay,
|
hideHours: event.allDay,
|
||||||
eventColor: eventColor,
|
eventColor,
|
||||||
notes: event.notes
|
notes: event.notes,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@ -47,7 +47,7 @@
|
|||||||
</dict>
|
</dict>
|
||||||
</array>
|
</array>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>40</string>
|
<string>52</string>
|
||||||
<key>LSRequiresIPhoneOS</key>
|
<key>LSRequiresIPhoneOS</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>NSAppTransportSecurity</key>
|
<key>NSAppTransportSecurity</key>
|
||||||
@ -119,6 +119,18 @@
|
|||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
|
<string>$(PRODUCT_BUNDLE_IDENTIFIER).expo.index_route</string>
|
||||||
</array>
|
</array>
|
||||||
<key>UILaunchStoryboardName</key>
|
<key>UILaunchStoryboardName</key>
|
||||||
<string>SplashScreen</string>
|
<string>SplashScreen</string>
|
||||||
|
|||||||
17
package-lock.json
generated
17
package-lock.json
generated
@ -56,6 +56,7 @@
|
|||||||
"react-native-app-auth": "^8.0.0",
|
"react-native-app-auth": "^8.0.0",
|
||||||
"react-native-big-calendar": "^4.14.0",
|
"react-native-big-calendar": "^4.14.0",
|
||||||
"react-native-calendars": "^1.1306.0",
|
"react-native-calendars": "^1.1306.0",
|
||||||
|
"react-native-element-dropdown": "^2.12.2",
|
||||||
"react-native-gesture-handler": "~2.16.1",
|
"react-native-gesture-handler": "~2.16.1",
|
||||||
"react-native-gifted-charts": "^1.4.41",
|
"react-native-gifted-charts": "^1.4.41",
|
||||||
"react-native-keyboard-manager": "^6.5.16-0",
|
"react-native-keyboard-manager": "^6.5.16-0",
|
||||||
@ -15939,6 +15940,22 @@
|
|||||||
"moment": "^2.29.4"
|
"moment": "^2.29.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/react-native-element-dropdown": {
|
||||||
|
"version": "2.12.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-native-element-dropdown/-/react-native-element-dropdown-2.12.2.tgz",
|
||||||
|
"integrity": "sha512-Tf8hfRuniYEXo+LGoVgIMoItKWuPLX6jbqlwAFgMbBhmWGTuV+g1OVOAx/ny16kgnwp+NhgJoWpxhVvr7HSmXA==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"lodash": "^4.17.21"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 16.0.0"
|
||||||
|
},
|
||||||
|
"peerDependencies": {
|
||||||
|
"react": "*",
|
||||||
|
"react-native": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/react-native-gesture-handler": {
|
"node_modules/react-native-gesture-handler": {
|
||||||
"version": "2.16.2",
|
"version": "2.16.2",
|
||||||
"resolved": "https://registry.npmjs.org/react-native-gesture-handler/-/react-native-gesture-handler-2.16.2.tgz",
|
"resolved": "https://registry.npmjs.org/react-native-gesture-handler/-/react-native-gesture-handler-2.16.2.tgz",
|
||||||
|
|||||||
@ -8852,7 +8852,7 @@ react-native-calendars@^1.1306.0:
|
|||||||
|
|
||||||
react-native-element-dropdown@^2.12.2:
|
react-native-element-dropdown@^2.12.2:
|
||||||
version "2.12.2"
|
version "2.12.2"
|
||||||
resolved "https://registry.yarnpkg.com/react-native-element-dropdown/-/react-native-element-dropdown-2.12.2.tgz#48d0c12b87591e2498c73bbde80e18374a4c262e"
|
resolved "https://registry.npmjs.org/react-native-element-dropdown/-/react-native-element-dropdown-2.12.2.tgz"
|
||||||
integrity sha512-Tf8hfRuniYEXo+LGoVgIMoItKWuPLX6jbqlwAFgMbBhmWGTuV+g1OVOAx/ny16kgnwp+NhgJoWpxhVvr7HSmXA==
|
integrity sha512-Tf8hfRuniYEXo+LGoVgIMoItKWuPLX6jbqlwAFgMbBhmWGTuV+g1OVOAx/ny16kgnwp+NhgJoWpxhVvr7HSmXA==
|
||||||
dependencies:
|
dependencies:
|
||||||
lodash "^4.17.21"
|
lodash "^4.17.21"
|
||||||
|
|||||||
Reference in New Issue
Block a user