Merge remote-tracking branch 'origin/dev' into tablet

This commit is contained in:
ivic00
2024-11-10 13:54:23 +01:00
14 changed files with 1227 additions and 1081 deletions

View File

@ -1,315 +1,337 @@
import React, {useCallback, useEffect, useMemo, useState} from "react"; import React, { useCallback, useEffect, useMemo, useState } from "react";
import {Calendar} from "react-native-big-calendar"; import { Calendar } from "react-native-big-calendar";
import {ActivityIndicator, StyleSheet, View, ViewStyle} from "react-native"; import { ActivityIndicator, StyleSheet, View, ViewStyle } from "react-native";
import {useGetEvents} from "@/hooks/firebase/useGetEvents"; import { useGetEvents } from "@/hooks/firebase/useGetEvents";
import {useAtom, useSetAtom} from "jotai"; import { useAtom, useSetAtom } from "jotai";
import { import {
editVisibleAtom, editVisibleAtom,
eventForEditAtom, eventForEditAtom,
modeAtom, isAllDayAtom,
selectedDateAtom, modeAtom,
selectedNewEventDateAtom, selectedDateAtom,
selectedNewEventDateAtom,
} from "@/components/pages/calendar/atoms"; } from "@/components/pages/calendar/atoms";
import {useAuthContext} from "@/contexts/AuthContext"; import { useAuthContext } from "@/contexts/AuthContext";
import {CalendarEvent} from "@/components/pages/calendar/interfaces"; import { CalendarEvent } from "@/components/pages/calendar/interfaces";
import {Text} from "react-native-ui-lib"; import { Text } from "react-native-ui-lib";
import {addDays, compareAsc, isWithinInterval, subDays} from "date-fns"; import { addDays, compareAsc, isWithinInterval, subDays } from "date-fns";
interface EventCalendarProps { interface EventCalendarProps {
calendarHeight: number; calendarHeight: number;
// WAS USED FOR SCROLLABLE CALENDARS, PERFORMANCE WAS NOT OPTIMAL // WAS USED FOR SCROLLABLE CALENDARS, PERFORMANCE WAS NOT OPTIMAL
calendarWidth: number; calendarWidth: number;
} }
const getTotalMinutes = () => { const getTotalMinutes = () => {
const date = new Date(); const date = new Date();
return Math.abs(date.getUTCHours() * 60 + date.getUTCMinutes() - 200); return Math.abs(date.getUTCHours() * 60 + date.getUTCMinutes() - 200);
}; };
export const EventCalendar: React.FC<EventCalendarProps> = React.memo( export const EventCalendar: React.FC<EventCalendarProps> = React.memo(
({calendarHeight}) => { ({ calendarHeight }) => {
const {data: events, isLoading} = useGetEvents(); const { data: events, isLoading } = useGetEvents();
const {profileData} = useAuthContext(); const { profileData } = useAuthContext();
const [selectedDate, setSelectedDate] = useAtom(selectedDateAtom); const [selectedDate, setSelectedDate] = useAtom(selectedDateAtom);
const [mode, setMode] = useAtom(modeAtom); const [mode, setMode] = useAtom(modeAtom);
const setEditVisible = useSetAtom(editVisibleAtom); const setEditVisible = useSetAtom(editVisibleAtom);
const setEventForEdit = useSetAtom(eventForEditAtom); const [isAllDay, setIsAllDay] = useAtom(isAllDayAtom);
const setSelectedNewEndDate = useSetAtom(selectedNewEventDateAtom); const setEventForEdit = useSetAtom(eventForEditAtom);
const setSelectedNewEndDate = useSetAtom(selectedNewEventDateAtom);
const [offsetMinutes, setOffsetMinutes] = useState(getTotalMinutes()); const [offsetMinutes, setOffsetMinutes] = useState(getTotalMinutes());
const todaysDate = new Date(); const todaysDate = new Date();
const handlePressEvent = useCallback( const handlePressEvent = useCallback(
(event: CalendarEvent) => { (event: CalendarEvent) => {
if (mode === "day" || mode === "week") { if (mode === "day" || mode === "week") {
setEditVisible(true); setEditVisible(true);
console.log({event}); console.log({ event });
setEventForEdit(event); setEventForEdit(event);
} else { } else {
setMode("day"); setMode("day");
setSelectedDate(event.start); setSelectedDate(event.start);
}
},
[setEditVisible, setEventForEdit, mode]
);
const handlePressCell = useCallback(
(date: Date) => {
if (mode === "day" || mode === "week") {
setSelectedNewEndDate(date);
} else {
setMode("day");
setSelectedDate(date);
}
},
[mode, setSelectedNewEndDate, setSelectedDate]
);
const handleSwipeEnd = useCallback(
(date: Date) => {
setSelectedDate(date);
},
[setSelectedDate]
);
const memoizedEventCellStyle = useCallback(
(event: CalendarEvent) => ({backgroundColor: event.eventColor}),
[]
);
const memoizedWeekStartsOn = useMemo(
() => (profileData?.firstDayOfWeek === "Mondays" ? 1 : 0),
[profileData]
);
console.log({memoizedWeekStartsOn, profileData: profileData?.firstDayOfWeek})
const isSameDate = useCallback((date1: Date, date2: Date) => {
return (
date1.getDate() === date2.getDate() &&
date1.getMonth() === date2.getMonth() &&
date1.getFullYear() === date2.getFullYear()
);
}, []);
const dayHeaderColor = useMemo(() => {
return isSameDate(todaysDate, selectedDate) ? "white" : "#4d4d4d";
}, [selectedDate, mode]);
const dateStyle = useMemo(() => {
if (mode === "week") return undefined;
return isSameDate(todaysDate, selectedDate) && mode === "day"
? styles.dayHeader
: styles.otherDayHeader;
}, [selectedDate, mode]);
const memoizedHeaderContentStyle = useMemo(() => {
if (mode === "day") {
return styles.dayModeHeader;
} else if (mode === "week") {
return styles.weekModeHeader;
} else if (mode === "month") {
return styles.monthModeHeader;
} else {
return {};
}
}, [mode]);
const {enrichedEvents, filteredEvents} = useMemo(() => {
const startTime = Date.now(); // Start timer
const startOffset = mode === "month" ? 40 : mode === "week" ? 10 : 1;
const endOffset = mode === "month" ? 40 : mode === "week" ? 10 : 1;
const filteredEvents = events?.filter(event =>
event.start && event.end &&
isWithinInterval(event.start, {
start: subDays(selectedDate, startOffset),
end: addDays(selectedDate, endOffset)
}) &&
isWithinInterval(event.end, {
start: subDays(selectedDate, startOffset),
end: addDays(selectedDate, endOffset)
})
) ?? [];
const enrichedEvents = filteredEvents.reduce((acc, event) => {
const dateKey = event.start.toISOString().split('T')[0];
acc[dateKey] = acc[dateKey] || [];
acc[dateKey].push({
...event,
overlapPosition: false,
overlapCount: 0
});
acc[dateKey].sort((a, b) => compareAsc(a.start, b.start));
return acc;
}, {} as Record<string, CalendarEvent[]>);
const endTime = Date.now();
console.log("memoizedEvents computation time:", endTime - startTime, "ms");
return {enrichedEvents, filteredEvents};
}, [events, selectedDate, mode]);
const renderCustomDateForMonth = (date: Date) => {
const circleStyle = useMemo<ViewStyle>(
() => ({
width: 30,
height: 30,
justifyContent: "center",
alignItems: "center",
borderRadius: 15,
}),
[]
);
const defaultStyle = useMemo<ViewStyle>(
() => ({
...circleStyle,
}),
[circleStyle]
);
const currentDateStyle = useMemo<ViewStyle>(
() => ({
...circleStyle,
backgroundColor: "#4184f2",
}),
[circleStyle]
);
const renderDate = useCallback(
(date: Date) => {
const isCurrentDate = isSameDate(todaysDate, date);
const appliedStyle = isCurrentDate ? currentDateStyle : defaultStyle;
return (
<View style={{alignItems: "center"}}>
<View style={appliedStyle}>
<Text style={{color: isCurrentDate ? "white" : "black"}}>
{date.getDate()}
</Text>
</View>
</View>
);
},
[todaysDate, currentDateStyle, defaultStyle] // dependencies
);
return renderDate(date);
};
useEffect(() => {
setOffsetMinutes(getTotalMinutes());
}, [events, mode]);
if (isLoading) {
return (
<View style={styles.loadingContainer}>
<ActivityIndicator size="large" color="#0000ff"/>
</View>
);
} }
},
[setEditVisible, setEventForEdit, mode]
);
// console.log(enrichedEvents, filteredEvents) const handlePressCell = useCallback(
(date: Date) => {
if (mode === "day" || mode === "week") {
setSelectedNewEndDate(date);
} else {
setMode("day");
setSelectedDate(date);
}
},
[mode, setSelectedNewEndDate, setSelectedDate]
);
return ( const handlePressDayHeader = useCallback(
<Calendar (date: Date) => {
bodyContainerStyle={styles.calHeader} setIsAllDay(true);
swipeEnabled console.log(isAllDay);
mode={mode} setSelectedNewEndDate(date);
enableEnrichedEvents={true} setEditVisible(true);
sortedMonthView },
// enrichedEventsByDate={enrichedEvents} [setSelectedNewEndDate]
events={filteredEvents} );
// eventCellStyle={memoizedEventCellStyle}
onPressEvent={handlePressEvent} const handleSwipeEnd = useCallback(
weekStartsOn={memoizedWeekStartsOn} (date: Date) => {
height={calendarHeight} setSelectedDate(date);
activeDate={todaysDate} },
date={selectedDate} [setSelectedDate]
onPressCell={handlePressCell} );
headerContentStyle={memoizedHeaderContentStyle}
onSwipeEnd={handleSwipeEnd} const memoizedEventCellStyle = useCallback(
scrollOffsetMinutes={offsetMinutes} (event: CalendarEvent) => ({ backgroundColor: event.eventColor }),
theme={{ []
palette: { );
nowIndicator: profileData?.eventColor || "#fd1575",
gray: { const memoizedWeekStartsOn = useMemo(
"100": "#e8eaed", () => (profileData?.firstDayOfWeek === "Mondays" ? 1 : 0),
"200": "#e8eaed", [profileData]
"500": "#b7b7b7", );
"800": "#919191",
}, console.log({
}, memoizedWeekStartsOn,
typography: { profileData: profileData?.firstDayOfWeek,
fontFamily: "PlusJakartaSans_500Medium", });
sm: {fontFamily: "Manrope_600SemiBold", fontSize: 15},
xl: { const isSameDate = useCallback((date1: Date, date2: Date) => {
fontFamily: "PlusJakartaSans_500Medium", return (
fontSize: 16, date1.getDate() === date2.getDate() &&
}, date1.getMonth() === date2.getMonth() &&
moreLabel: {}, date1.getFullYear() === date2.getFullYear()
xs: {fontSize: 10}, );
}, }, []);
}}
dayHeaderStyle={dateStyle} const dayHeaderColor = useMemo(() => {
dayHeaderHighlightColor={"white"} return isSameDate(todaysDate, selectedDate) ? "white" : "#4d4d4d";
showAdjacentMonths }, [selectedDate, mode]);
hourStyle={styles.hourStyle}
ampm const dateStyle = useMemo(() => {
// renderCustomDateForMonth={renderCustomDateForMonth} if (mode === "week") return undefined;
/> return isSameDate(todaysDate, selectedDate) && mode === "day"
); ? styles.dayHeader
: styles.otherDayHeader;
}, [selectedDate, mode]);
const memoizedHeaderContentStyle = useMemo(() => {
if (mode === "day") {
return styles.dayModeHeader;
} else if (mode === "week") {
return styles.weekModeHeader;
} else if (mode === "month") {
return styles.monthModeHeader;
} else {
return {};
}
}, [mode]);
const { enrichedEvents, filteredEvents } = useMemo(() => {
const startTime = Date.now(); // Start timer
const startOffset = mode === "month" ? 40 : mode === "week" ? 10 : 1;
const endOffset = mode === "month" ? 40 : mode === "week" ? 10 : 1;
const filteredEvents =
events?.filter(
(event) =>
event.start &&
event.end &&
isWithinInterval(event.start, {
start: subDays(selectedDate, startOffset),
end: addDays(selectedDate, endOffset),
}) &&
isWithinInterval(event.end, {
start: subDays(selectedDate, startOffset),
end: addDays(selectedDate, endOffset),
})
) ?? [];
const enrichedEvents = filteredEvents.reduce((acc, event) => {
const dateKey = event.start.toISOString().split("T")[0];
acc[dateKey] = acc[dateKey] || [];
acc[dateKey].push({
...event,
overlapPosition: false,
overlapCount: 0,
});
acc[dateKey].sort((a, b) => compareAsc(a.start, b.start));
return acc;
}, {} as Record<string, CalendarEvent[]>);
const endTime = Date.now();
console.log(
"memoizedEvents computation time:",
endTime - startTime,
"ms"
);
return { enrichedEvents, filteredEvents };
}, [events, selectedDate, mode]);
const renderCustomDateForMonth = (date: Date) => {
const circleStyle = useMemo<ViewStyle>(
() => ({
width: 30,
height: 30,
justifyContent: "center",
alignItems: "center",
borderRadius: 15,
}),
[]
);
const defaultStyle = useMemo<ViewStyle>(
() => ({
...circleStyle,
}),
[circleStyle]
);
const currentDateStyle = useMemo<ViewStyle>(
() => ({
...circleStyle,
backgroundColor: "#4184f2",
}),
[circleStyle]
);
const renderDate = useCallback(
(date: Date) => {
const isCurrentDate = isSameDate(todaysDate, date);
const appliedStyle = isCurrentDate ? currentDateStyle : defaultStyle;
return (
<View style={{ alignItems: "center" }}>
<View style={appliedStyle}>
<Text style={{ color: isCurrentDate ? "white" : "black" }}>
{date.getDate()}
</Text>
</View>
</View>
);
},
[todaysDate, currentDateStyle, defaultStyle] // dependencies
);
return renderDate(date);
};
useEffect(() => {
setOffsetMinutes(getTotalMinutes());
}, [events, mode]);
if (isLoading) {
return (
<View style={styles.loadingContainer}>
<ActivityIndicator size="large" color="#0000ff" />
</View>
);
} }
// console.log(enrichedEvents, filteredEvents)
return (
<Calendar
bodyContainerStyle={styles.calHeader}
swipeEnabled
mode={mode}
enableEnrichedEvents={true}
sortedMonthView
// enrichedEventsByDate={enrichedEvents}
events={filteredEvents}
// eventCellStyle={memoizedEventCellStyle}
onPressEvent={handlePressEvent}
weekStartsOn={memoizedWeekStartsOn}
height={calendarHeight}
activeDate={todaysDate}
date={selectedDate}
onPressCell={handlePressCell}
headerContentStyle={memoizedHeaderContentStyle}
onSwipeEnd={handleSwipeEnd}
scrollOffsetMinutes={offsetMinutes}
theme={{
palette: {
nowIndicator: profileData?.eventColor || "#fd1575",
gray: {
"100": "#e8eaed",
"200": "#e8eaed",
"500": "#b7b7b7",
"800": "#919191",
},
},
typography: {
fontFamily: "PlusJakartaSans_500Medium",
sm: { fontFamily: "Manrope_600SemiBold", fontSize: 15 },
xl: {
fontFamily: "PlusJakartaSans_500Medium",
fontSize: 16,
},
moreLabel: {},
xs: { fontSize: 10 },
},
}}
dayHeaderStyle={dateStyle}
dayHeaderHighlightColor={"white"}
showAdjacentMonths
hourStyle={styles.hourStyle}
onPressDateHeader={handlePressDayHeader}
ampm
// renderCustomDateForMonth={renderCustomDateForMonth}
/>
);
}
); );
const styles = StyleSheet.create({ const styles = StyleSheet.create({
segmentslblStyle: { segmentslblStyle: {
fontSize: 12, fontSize: 12,
fontFamily: "Manrope_600SemiBold", fontFamily: "Manrope_600SemiBold",
}, },
calHeader: { calHeader: {
borderWidth: 0, borderWidth: 0,
}, },
dayModeHeader: { dayModeHeader: {
alignSelf: "flex-start", alignSelf: "flex-start",
justifyContent: "space-between", justifyContent: "space-between",
alignContent: "center", alignContent: "center",
width: 38, width: 38,
right: 42, right: 42,
height: 13, height: 13,
}, },
weekModeHeader: {}, weekModeHeader: {},
monthModeHeader: {}, monthModeHeader: {},
loadingContainer: { loadingContainer: {
flex: 1, flex: 1,
justifyContent: "center", justifyContent: "center",
alignItems: "center", alignItems: "center",
}, },
dayHeader: { dayHeader: {
backgroundColor: "#4184f2", backgroundColor: "#4184f2",
aspectRatio: 1, aspectRatio: 1,
borderRadius: 100, borderRadius: 100,
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
}, },
otherDayHeader: { otherDayHeader: {
backgroundColor: "transparent", backgroundColor: "transparent",
color: "#919191", color: "#919191",
aspectRatio: 1, aspectRatio: 1,
borderRadius: 100, borderRadius: 100,
alignItems: "center", alignItems: "center",
justifyContent: "center", justifyContent: "center",
}, },
hourStyle: { hourStyle: {
color: "#5f6368", color: "#5f6368",
fontSize: 12, fontSize: 12,
fontFamily: "Manrope_500Medium", fontFamily: "Manrope_500Medium",
}, },
}); });

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@ import { atom } from "jotai";
import { CalendarEvent } from "@/components/pages/calendar/interfaces"; import { CalendarEvent } from "@/components/pages/calendar/interfaces";
export const editVisibleAtom = atom<boolean>(false); export const editVisibleAtom = atom<boolean>(false);
export const isAllDayAtom = atom<boolean>(false);
export const eventForEditAtom = atom<CalendarEvent | undefined>(undefined); export const eventForEditAtom = atom<CalendarEvent | undefined>(undefined);
export const isFamilyViewAtom = atom<boolean>(false); export const isFamilyViewAtom = atom<boolean>(false);
export const modeAtom = atom<"week" | "month" | "day">("week"); export const modeAtom = atom<"week" | "month" | "day">("week");

View File

@ -1,4 +1,4 @@
import {AntDesign, Ionicons} from "@expo/vector-icons"; import {Ionicons} from "@expo/vector-icons";
import React, {useCallback, useState} from "react"; import React, {useCallback, useState} from "react";
import {Button, Checkbox, Text, View} from "react-native-ui-lib"; import {Button, Checkbox, Text, View} from "react-native-ui-lib";
import {ActivityIndicator, ScrollView, StyleSheet} from "react-native"; import {ActivityIndicator, ScrollView, StyleSheet} from "react-native";
@ -10,7 +10,6 @@ import AppleIcon from "@/assets/svgs/AppleIcon";
import GoogleIcon from "@/assets/svgs/GoogleIcon"; import GoogleIcon from "@/assets/svgs/GoogleIcon";
import OutlookIcon from "@/assets/svgs/OutlookIcon"; import OutlookIcon from "@/assets/svgs/OutlookIcon";
import ExpoLocalization from "expo-localization/src/ExpoLocalization"; import ExpoLocalization from "expo-localization/src/ExpoLocalization";
import {colorMap} from "@/constants/colorMap";
import {useSetAtom} from "jotai"; import {useSetAtom} from "jotai";
import {settingsPageIndex} from "../calendar/atoms"; import {settingsPageIndex} from "../calendar/atoms";
import CalendarSettingsDialog from "./calendar_components/CalendarSettingsDialog"; import CalendarSettingsDialog from "./calendar_components/CalendarSettingsDialog";
@ -53,13 +52,6 @@ const CalendarSettingsPage = () => {
setModalVisible(false); setModalVisible(false);
}; };
const [selectedColor, setSelectedColor] = useState<string>(
profileData?.eventColor ?? colorMap.pink
);
const [previousSelectedColor, setPreviousSelectedColor] = useState<string>(
profileData?.eventColor ?? colorMap.pink
);
const {mutateAsync: updateUserData} = useUpdateUserData(); const {mutateAsync: updateUserData} = useUpdateUserData();
const {mutateAsync: clearToken} = useClearTokens(); const {mutateAsync: clearToken} = useClearTokens();
@ -78,22 +70,6 @@ const CalendarSettingsPage = () => {
fetchAndSaveAppleEvents fetchAndSaveAppleEvents
} = useCalSync() } = useCalSync()
const debouncedUpdateUserData = useCallback(
debounce(async (color: string) => {
try {
await updateUserData({
newUserData: {
eventColor: color,
},
});
} catch (error) {
console.error("Failed to update color:", error);
setSelectedColor(previousSelectedColor);
}
}, 500),
[]
);
const debouncedUpdateFirstDayOfWeek = useCallback( const debouncedUpdateFirstDayOfWeek = useCallback(
debounce(async (firstDayOfWeek: string) => { debounce(async (firstDayOfWeek: string) => {
try { try {
@ -114,12 +90,6 @@ const CalendarSettingsPage = () => {
debouncedUpdateFirstDayOfWeek(firstDayOfWeek); debouncedUpdateFirstDayOfWeek(firstDayOfWeek);
}; };
const handleChangeColor = (color: string) => {
setPreviousSelectedColor(selectedColor);
setSelectedColor(color);
debouncedUpdateUserData(color);
};
return ( return (
<ScrollView> <ScrollView>
<TouchableOpacity onPress={() => setPageIndex(0)}> <TouchableOpacity onPress={() => setPageIndex(0)}>
@ -140,52 +110,6 @@ const CalendarSettingsPage = () => {
</TouchableOpacity> </TouchableOpacity>
<View marginH-30 marginB-30> <View marginH-30 marginB-30>
<Text style={styles.subTitle}>Calendar settings</Text> <Text style={styles.subTitle}>Calendar settings</Text>
<View style={styles.card}>
<Text style={styles.cardTitle} marginB-14>
Event Color Preference
</Text>
<View row spread>
<TouchableOpacity onPress={() => handleChangeColor(colorMap.pink)}>
<View style={styles.colorBox} backgroundColor={colorMap.pink}>
{selectedColor == colorMap.pink && (
<AntDesign name="check" size={30} color="white"/>
)}
</View>
</TouchableOpacity>
<TouchableOpacity
onPress={() => handleChangeColor(colorMap.orange)}
>
<View style={styles.colorBox} backgroundColor={colorMap.orange}>
{selectedColor == colorMap.orange && (
<AntDesign name="check" size={30} color="white"/>
)}
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => handleChangeColor(colorMap.green)}>
<View style={styles.colorBox} backgroundColor={colorMap.green}>
{selectedColor == colorMap.green && (
<AntDesign name="check" size={30} color="white"/>
)}
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => handleChangeColor(colorMap.teal)}>
<View style={styles.colorBox} backgroundColor={colorMap.teal}>
{selectedColor == colorMap.teal && (
<AntDesign name="check" size={30} color="white"/>
)}
</View>
</TouchableOpacity>
<TouchableOpacity
onPress={() => handleChangeColor(colorMap.purple)}
>
<View style={styles.colorBox} backgroundColor={colorMap.purple}>
{selectedColor == colorMap.purple && (
<AntDesign name="check" size={30} color="white"/>
)}
</View>
</TouchableOpacity>
</View>
</View>
<View style={styles.card}> <View style={styles.card}>
<Text style={styles.cardTitle}>Weekly Start Date</Text> <Text style={styles.cardTitle}>Weekly Start Date</Text>
<View row marginV-5 marginT-20> <View row marginV-5 marginT-20>

View File

@ -25,7 +25,7 @@ const DeleteProfileDialogs: React.FC<ConfirmationDialogProps> = ({
containerStyle={styles.dialog} containerStyle={styles.dialog}
> >
<View centerH> <View centerH>
<Feather name="alert-triangle" size={70} color="#FF5449" /> <Feather name="alert-triangle" size={70} color="#ff1637" />
</View> </View>
<Text center style={styles.title}> <Text center style={styles.title}>
Are you sure? Are you sure?
@ -101,7 +101,7 @@ const DeleteProfileDialogs: React.FC<ConfirmationDialogProps> = ({
// Empty stylesheet for future styles // Empty stylesheet for future styles
const styles = StyleSheet.create({ const styles = StyleSheet.create({
confirmBtn: { confirmBtn: {
backgroundColor: "#FF5449", backgroundColor: "#ff1637",
}, },
cancelBtn: { cancelBtn: {
backgroundColor: "white", backgroundColor: "white",

View File

@ -178,7 +178,7 @@ const MyGroup: React.FC<MyGroupProps> = ({onNewUserClick, setOnNewUserClick}) =>
<UserMenu <UserMenu
setShowQRCodeDialog={(val) => setShowQRCodeDialog(val)} setShowQRCodeDialog={(val) => setShowQRCodeDialog(val)}
showQRCodeDialog={showQRCodeDialog === member?.uid} showQRCodeDialog={showQRCodeDialog === member?.uid}
userId={member?.uid!} user={member}
/> />
</View> </View>
</Card> </Card>
@ -220,7 +220,7 @@ const MyGroup: React.FC<MyGroupProps> = ({onNewUserClick, setOnNewUserClick}) =>
<UserMenu <UserMenu
setShowQRCodeDialog={(val) => setShowQRCodeDialog(val)} setShowQRCodeDialog={(val) => setShowQRCodeDialog(val)}
showQRCodeDialog={showQRCodeDialog === member?.uid} showQRCodeDialog={showQRCodeDialog === member?.uid}
userId={member?.uid!} user={member}
/> />
</Card> </Card>
))} ))}
@ -259,7 +259,7 @@ const MyGroup: React.FC<MyGroupProps> = ({onNewUserClick, setOnNewUserClick}) =>
<UserMenu <UserMenu
setShowQRCodeDialog={(val) => setShowQRCodeDialog(val)} setShowQRCodeDialog={(val) => setShowQRCodeDialog(val)}
showQRCodeDialog={showQRCodeDialog === member?.uid} showQRCodeDialog={showQRCodeDialog === member?.uid}
userId={member?.uid!} user={member}
/> />
</Card> </Card>
))} ))}

View File

@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from "react"; import React, {useCallback, useEffect, useRef, useState} from "react";
import { StyleSheet, TouchableOpacity } from "react-native"; import { StyleSheet, TouchableOpacity } from "react-native";
import { ScrollView } from "react-native-gesture-handler"; import { ScrollView } from "react-native-gesture-handler";
import * as ImagePicker from "expo-image-picker"; import * as ImagePicker from "expo-image-picker";
@ -20,6 +20,7 @@ import { useUpdateUserData } from "@/hooks/firebase/useUpdateUserData";
import { useChangeProfilePicture } from "@/hooks/firebase/useChangeProfilePicture"; import { useChangeProfilePicture } from "@/hooks/firebase/useChangeProfilePicture";
import { colorMap } from "@/constants/colorMap"; import { colorMap } from "@/constants/colorMap";
import DeleteProfileDialogs from "../user_components/DeleteProfileDialogs"; import DeleteProfileDialogs from "../user_components/DeleteProfileDialogs";
import {AntDesign} from "@expo/vector-icons";
const MyProfile = () => { const MyProfile = () => {
const { user, profileData } = useAuthContext(); const { user, profileData } = useAuthContext();
@ -34,6 +35,13 @@ const MyProfile = () => {
string | ImagePicker.ImagePickerAsset | null string | ImagePicker.ImagePickerAsset | null
>(profileData?.pfp || null); >(profileData?.pfp || null);
const [selectedColor, setSelectedColor] = useState<string>(
profileData?.eventColor ?? colorMap.pink
);
const [previousSelectedColor, setPreviousSelectedColor] = useState<string>(
profileData?.eventColor ?? colorMap.pink
);
const [showDeleteDialog, setShowDeleteDialog] = useState<boolean>(false); const [showDeleteDialog, setShowDeleteDialog] = useState<boolean>(false);
const handleHideDeleteDialog = () => { const handleHideDeleteDialog = () => {
@ -102,6 +110,28 @@ const MyProfile = () => {
? profileImage.uri ? profileImage.uri
: profileImage; : profileImage;
const handleChangeColor = (color: string) => {
setPreviousSelectedColor(selectedColor);
setSelectedColor(color);
debouncedUpdateUserData(color);
};
const debouncedUpdateUserData = useCallback(
debounce(async (color: string) => {
try {
await updateUserData({
newUserData: {
eventColor: color,
},
});
} catch (error) {
console.error("Failed to update color:", error);
setSelectedColor(previousSelectedColor);
}
}, 500),
[]
);
return ( return (
<ScrollView style={{ paddingBottom: 20, flex: 1 }}> <ScrollView style={{ paddingBottom: 20, flex: 1 }}>
<View style={styles.card}> <View style={styles.card}>
@ -125,8 +155,8 @@ const MyProfile = () => {
}} }}
> >
<Text style={styles.pfpTxt}> <Text style={styles.pfpTxt}>
{user?.email?.at(0)} {profileData?.firstName?.at(0)}
{user?.email?.at(1)} {profileData?.lastName?.at(0)}
</Text> </Text>
</View> </View>
)} )}
@ -215,9 +245,55 @@ const MyProfile = () => {
</Picker> </Picker>
</View> </View>
</View> </View>
<View style={styles.card}>
<Text style={styles.cardTitle} marginB-14>
Color Preference
</Text>
<View row spread>
<TouchableOpacity onPress={() => handleChangeColor(colorMap.pink)}>
<View style={styles.colorBox} backgroundColor={colorMap.pink}>
{selectedColor == colorMap.pink && (
<AntDesign name="check" size={30} color="white"/>
)}
</View>
</TouchableOpacity>
<TouchableOpacity
onPress={() => handleChangeColor(colorMap.orange)}
>
<View style={styles.colorBox} backgroundColor={colorMap.orange}>
{selectedColor == colorMap.orange && (
<AntDesign name="check" size={30} color="white"/>
)}
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => handleChangeColor(colorMap.green)}>
<View style={styles.colorBox} backgroundColor={colorMap.green}>
{selectedColor == colorMap.green && (
<AntDesign name="check" size={30} color="white"/>
)}
</View>
</TouchableOpacity>
<TouchableOpacity onPress={() => handleChangeColor(colorMap.teal)}>
<View style={styles.colorBox} backgroundColor={colorMap.teal}>
{selectedColor == colorMap.teal && (
<AntDesign name="check" size={30} color="white"/>
)}
</View>
</TouchableOpacity>
<TouchableOpacity
onPress={() => handleChangeColor(colorMap.purple)}
>
<View style={styles.colorBox} backgroundColor={colorMap.purple}>
{selectedColor == colorMap.purple && (
<AntDesign name="check" size={30} color="white"/>
)}
</View>
</TouchableOpacity>
</View>
</View>
<Button <Button
size="large" size="large"
backgroundColor="#FF5449" backgroundColor="#ff1637"
label="Delete Profile" label="Delete Profile"
style={{ marginTop: 10 }} style={{ marginTop: 10 }}
labelStyle={{ fontFamily: "PlusJakartaSans_500Medium", fontSize: 15 }} labelStyle={{ fontFamily: "PlusJakartaSans_500Medium", fontSize: 15 }}
@ -229,7 +305,9 @@ const MyProfile = () => {
}} }}
visible={showDeleteDialog} visible={showDeleteDialog}
onDismiss={handleHideDeleteDialog} onDismiss={handleHideDeleteDialog}
onConfirm={() => {console.log('delete account here')}} onConfirm={() => {
console.log("delete account here");
}}
/> />
</ScrollView> </ScrollView>
); );
@ -246,6 +324,17 @@ const timeZoneItems = Object.keys(tz.zones)
)); ));
const styles = StyleSheet.create({ const styles = StyleSheet.create({
cardTitle: {
fontFamily: "Manrope_500Medium",
fontSize: 15,
},
colorBox: {
aspectRatio: 1,
justifyContent: "center",
alignItems: "center",
width: 51,
borderRadius: 12,
},
card: { card: {
marginVertical: 15, marginVertical: 15,
backgroundColor: "white", backgroundColor: "white",

View File

@ -1,51 +1,78 @@
import React from 'react'; import React from "react";
import {Button, Card, Dialog, Text, TouchableOpacity} from 'react-native-ui-lib'; import {
import QRCode from 'react-native-qrcode-svg'; Button,
import {PanningDirectionsEnum} from "react-native-ui-lib/src/components/panningViews/panningProvider"; Card,
Dialog,
Text,
TouchableOpacity,
} from "react-native-ui-lib";
import QRCode from "react-native-qrcode-svg";
import { PanningDirectionsEnum } from "react-native-ui-lib/src/components/panningViews/panningProvider";
import Ionicons from "@expo/vector-icons/Ionicons"; import Ionicons from "@expo/vector-icons/Ionicons";
import { useGetFamilyMembers } from "@/hooks/firebase/useGetFamilyMembers";
import { UserProfile } from "@/hooks/firebase/types/profileTypes";
import { StyleSheet } from "react-native";
import { ProfileType } from "@/contexts/AuthContext";
const UserMenu = ({ const UserMenu = ({
userId, user,
showQRCodeDialog, showQRCodeDialog,
setShowQRCodeDialog setShowQRCodeDialog,
}: { }: {
userId: string, user: UserProfile;
showQRCodeDialog: boolean, showQRCodeDialog: boolean;
setShowQRCodeDialog: (value: string | boolean) => void setShowQRCodeDialog: (value: string | boolean) => void;
}) => { }) => {
const handleShowQRCode = () => { const handleShowQRCode = () => {
setShowQRCodeDialog(userId); setShowQRCodeDialog(user.uid!);
}; };
return (
<>
<TouchableOpacity onPress={handleShowQRCode}>
<Ionicons name="qr-code-outline" size={24} color="black" />
</TouchableOpacity>
return ( <Dialog
<> visible={showQRCodeDialog}
<TouchableOpacity onDismiss={() => setShowQRCodeDialog(false)}
onPress={handleShowQRCode} panDirection={PanningDirectionsEnum.DOWN}
> >
<Ionicons name="qr-code-outline" size={24} color="black"/> <Card padding-20 center>
</TouchableOpacity> <Text
center
<Dialog marginT-15
visible={showQRCodeDialog} marginH-15
onDismiss={() => setShowQRCodeDialog(false)} marginB-25
panDirection={PanningDirectionsEnum.DOWN} style={{ fontSize: 18, fontFamily: "Manrope_500Medium" }}
> >
<Card padding-20 center> {user.userType !== ProfileType.FAMILY_DEVICE
<Text center marginB-10 style={{fontSize: 16, maxWidth: "80%"}}>Ask your family to download the app ? `Open Cally on ${user.firstName}'s device and scan the code to link it to your family group`
and then scan the : "Open Cally on the family device and scan the code to link it to your family group"}
QR Code to join the family group: </Text>
</Text> <QRCode value={user.uid!} size={150} />
<QRCode value={userId} size={150}/> <Button
<Button marginT-20
marginT-20 style={styles.button}
label="Close" label="Close"
onPress={() => setShowQRCodeDialog(false)} labelStyle={{
/> fontFamily: "PlusJakartaSans_500Medium",
</Card> fontSize: 15,
</Dialog> }}
</> onPress={() => setShowQRCodeDialog(false)}
); />
</Card>
</Dialog>
</>
);
}; };
const styles = StyleSheet.create({
button: {
backgroundColor: "#d9d9d9",
width: 117,
height: 47,
},
});
export default UserMenu; export default UserMenu;

View File

@ -25,6 +25,7 @@ import CalendarIcon from "@/assets/svgs/CalendarIcon";
import ClockOIcon from "@/assets/svgs/ClockOIcon"; import ClockOIcon from "@/assets/svgs/ClockOIcon";
import ProfileIcon from "@/assets/svgs/ProfileIcon"; import ProfileIcon from "@/assets/svgs/ProfileIcon";
import RepeatFreq from "./RepeatFreq"; import RepeatFreq from "./RepeatFreq";
import {useAuthContext} from "@/contexts/AuthContext";
interface IAddChoreDialog { interface IAddChoreDialog {
isVisible: boolean; isVisible: boolean;
@ -44,6 +45,7 @@ const defaultTodo = {
}; };
const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => { const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
const {user} = useAuthContext()
const {addToDo, updateToDo} = useToDosContext(); const {addToDo, updateToDo} = useToDosContext();
const [todo, setTodo] = useState<IToDo>( const [todo, setTodo] = useState<IToDo>(
addChoreDialogProps.selectedTodo ?? defaultTodo addChoreDialogProps.selectedTodo ?? defaultTodo
@ -57,6 +59,11 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
const titleRef = useRef<TextFieldRef>(null) const titleRef = useRef<TextFieldRef>(null)
const {data: members} = useGetFamilyMembers(); const {data: members} = useGetFamilyMembers();
let sortedMembers = members?.sort((a, b) => {
if (a.uid === user?.uid) return -1;
if (b.uid === user?.uid) return 1;
return 0;
})
const handleClose = () => { const handleClose = () => {
setTodo(defaultTodo); setTodo(defaultTodo);
@ -272,7 +279,7 @@ const AddChoreDialog = (addChoreDialogProps: IAddChoreDialog) => {
/> />
)} )}
> >
{members?.map((member) => ( {sortedMembers?.map((member) => (
<Picker.Item <Picker.Item
key={member.uid} key={member.uid}
label={member?.firstName + " " + member?.lastName} label={member?.firstName + " " + member?.lastName}

View File

@ -111,7 +111,7 @@ const ToDoItem = (props: {
height={0.7} height={0.7}
width={"100%"} width={"100%"}
style={{ style={{
backgroundColor: props.item.done ? "#b8b8b8" : "#e7e7e7", backgroundColor: "#e7e7e7",
}} }}
centerH centerH
/> />

View File

@ -9,7 +9,7 @@ import { useGetChildrenByParentId } from "@/hooks/firebase/useGetChildrenByParen
import { useGetFamilyMembers } from "@/hooks/firebase/useGetFamilyMembers"; import { useGetFamilyMembers } from "@/hooks/firebase/useGetFamilyMembers";
import { UserProfile } from "@/hooks/firebase/types/profileTypes"; import { UserProfile } from "@/hooks/firebase/types/profileTypes";
import { child } from "@react-native-firebase/storage"; import { child } from "@react-native-firebase/storage";
import CachedImage from 'expo-cached-image' import CachedImage from "expo-cached-image";
const HeaderTemplate = (props: { const HeaderTemplate = (props: {
message: string; message: string;
@ -71,7 +71,10 @@ const HeaderTemplate = (props: {
useEffect(() => { useEffect(() => {
if (members) { if (members) {
const childrenMembers = members.filter( const childrenMembers = members.filter(
(member) => member.userType === ProfileType.CHILD (member) =>
member.userType === ProfileType.CHILD ||
member.userType === ProfileType.CAREGIVER ||
member.userType === ProfileType.PARENT
); );
setChildren(childrenMembers); setChildren(childrenMembers);
} }
@ -81,10 +84,15 @@ const HeaderTemplate = (props: {
<View row centerV marginV-15 style={styles.bottomMarg}> <View row centerV marginV-15 style={styles.bottomMarg}>
{profileData?.pfp ? ( {profileData?.pfp ? (
<View> <View>
<CachedImage source={{ uri: profileData.pfp, }} style={styles.pfp} cacheKey={profileData.pfp}/> <CachedImage
source={{ uri: profileData.pfp }}
style={styles.pfp}
cacheKey={profileData.pfp}
/>
{isFamilyView && props.isCalendar && ( {isFamilyView && props.isCalendar && (
<View style={styles.childrenPfpArr} row> <View style={styles.childrenPfpArr} row>
{children?.slice(0, 3).map((child, index) => { {children?.slice(0, 3).map((child, index) => {
const bgColor: string = child.eventColor || colorMap.pink;
return child.pfp ? ( return child.pfp ? (
<Image <Image
source={{ uri: child.pfp }} source={{ uri: child.pfp }}
@ -92,7 +100,10 @@ const HeaderTemplate = (props: {
/> />
) : ( ) : (
<View <View
style={[styles.childrenPfp, { left: index * 19 }]} style={[
styles.childrenPfp,
{ left: index * 19, backgroundColor: bgColor },
]}
center center
> >
<Text style={{ color: "white" }}> <Text style={{ color: "white" }}>
@ -104,7 +115,15 @@ const HeaderTemplate = (props: {
})} })}
{children?.length > 3 && ( {children?.length > 3 && (
<View style={[styles.childrenPfp, { left: 3 * 19 }]} center> <View style={[styles.childrenPfp, { left: 3 * 19 }]} center>
<Text style={{ color: "white", fontFamily: "Manrope_600SemiBold", fontSize: 12 }}>+{children.length - 3}</Text> <Text
style={{
color: "white",
fontFamily: "Manrope_600SemiBold",
fontSize: 12,
}}
>
+{children.length - 3}
</Text>
</View> </View>
)} )}
</View> </View>
@ -113,8 +132,8 @@ const HeaderTemplate = (props: {
) : ( ) : (
<View style={styles.pfp} center> <View style={styles.pfp} center>
<Text style={styles.pfpTxt}> <Text style={styles.pfpTxt}>
{user?.email?.at(0)} {profileData?.firstName?.at(0)}
{user?.email?.at(1)} {profileData?.lastName?.at(0)}
</Text> </Text>
</View> </View>
)} )}

View File

@ -13,7 +13,7 @@ const PointsSlider = (props: {
value={props.points} value={props.points}
onValueChange={(value) => props.setPoints(value)} onValueChange={(value) => props.setPoints(value)}
minimumValue={0} minimumValue={0}
step={10} step={5}
thumbTintColor="white" thumbTintColor="white"
minimumTrackTintColor="#91d5ff" minimumTrackTintColor="#91d5ff"
thumbStyle={{borderWidth: 3, borderColor: '#91d5ff'}} thumbStyle={{borderWidth: 3, borderColor: '#91d5ff'}}
@ -21,7 +21,7 @@ const PointsSlider = (props: {
/> />
<View row spread> <View row spread>
<Text style={{fontSize: 13, color: '#858585'}}>0</Text> <Text style={{fontSize: 13, color: '#858585'}}>0</Text>
<Text style={{fontSize: 13, color: '#858585'}}>50</Text> <Text style={{fontSize: 13, color: '#858585', marginLeft: 15}}>50</Text>
<Text style={{fontSize: 13, color: '#858585'}}>100</Text> <Text style={{fontSize: 13, color: '#858585'}}>100</Text>
</View> </View>
</View> </View>

View File

@ -61,9 +61,8 @@ export const useCreateTodo = () => {
dates.push(newDate); dates.push(newDate);
}); });
// TODO: for the next 52 weeks
let index = 1; let index = 1;
for (let i = 0; i < 4; i++) { for (let i = 0; i < 52; i++) {
dates?.forEach((dateToAdd) => { dates?.forEach((dateToAdd) => {
index ++; index ++;
let newTodoDate = addWeeks(dateToAdd, i); let newTodoDate = addWeeks(dateToAdd, i);

View File

@ -73,7 +73,7 @@ export const useUpdateTodo = () => {
dates.push(newDate); dates.push(newDate);
}); });
let todosToAddCycles = 4; let todosToAddCycles = 52;
if (firstTodo?.repeatType === REPEAT_TYPE.EVERY_WEEK) { if (firstTodo?.repeatType === REPEAT_TYPE.EVERY_WEEK) {
todosToAddCycles = filteredTodos?.length / firstTodo?.repeatDays?.length; todosToAddCycles = filteredTodos?.length / firstTodo?.repeatDays?.length;
} }