mirror of
https://github.com/urosran/cally.git
synced 2025-07-16 18:16:17 +00:00
Merge branch 'dev'
# Conflicts: # components/pages/calendar/EventCalendar.tsx # components/pages/settings/user_settings_views/MyProfile.tsx
This commit is contained in:
@ -1,55 +1,57 @@
|
|||||||
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, ScrollView, StyleSheet, View, ViewStyle} from "react-native";
|
import { ActivityIndicator, ScrollView, 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";
|
||||||
import {useCalSync} from "@/hooks/useCalSync";
|
import {useCalSync} from "@/hooks/useCalSync";
|
||||||
import {useSyncEvents} from "@/hooks/useSyncOnScroll";
|
import {useSyncEvents} from "@/hooks/useSyncOnScroll";
|
||||||
|
|
||||||
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 {isSyncing} = useSyncEvents()
|
const {isSyncing} = useSyncEvents()
|
||||||
const [offsetMinutes, setOffsetMinutes] = useState(getTotalMinutes());
|
const [offsetMinutes, setOffsetMinutes] = useState(getTotalMinutes());
|
||||||
useCalSync()
|
useCalSync()
|
||||||
|
|
||||||
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");
|
||||||
@ -59,172 +61,185 @@ export const EventCalendar: React.FC<EventCalendarProps> = React.memo(
|
|||||||
[setEditVisible, setEventForEdit, mode]
|
[setEditVisible, setEventForEdit, mode]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handlePressCell = useCallback(
|
const handlePressCell = useCallback(
|
||||||
(date: Date) => {
|
(date: Date) => {
|
||||||
if (mode === "day" || mode === "week") {
|
if (mode === "day" || mode === "week") {
|
||||||
setSelectedNewEndDate(date);
|
setSelectedNewEndDate(date);
|
||||||
} else {
|
} else {
|
||||||
setMode("day");
|
setMode("day");
|
||||||
setSelectedDate(date);
|
setSelectedDate(date);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[mode, setSelectedNewEndDate, setSelectedDate]
|
[mode, setSelectedNewEndDate, setSelectedDate]
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSwipeEnd = useCallback(
|
const handlePressDayHeader = useCallback(
|
||||||
(date: Date) => {
|
(date: Date) => {
|
||||||
setSelectedDate(date);
|
setIsAllDay(true);
|
||||||
},
|
console.log(isAllDay);
|
||||||
[setSelectedDate]
|
setSelectedNewEndDate(date);
|
||||||
);
|
setEditVisible(true);
|
||||||
|
},
|
||||||
|
[setSelectedNewEndDate]
|
||||||
|
);
|
||||||
|
|
||||||
const memoizedEventCellStyle = useCallback(
|
const handleSwipeEnd = useCallback(
|
||||||
(event: CalendarEvent) => ({backgroundColor: event.eventColor, fontSize: 14}),
|
(date: Date) => {
|
||||||
[]
|
setSelectedDate(date);
|
||||||
);
|
},
|
||||||
|
[setSelectedDate]
|
||||||
|
);
|
||||||
|
|
||||||
const memoizedWeekStartsOn = useMemo(
|
const memoizedEventCellStyle = useCallback(
|
||||||
() => (profileData?.firstDayOfWeek === "Mondays" ? 1 : 0),
|
(event: CalendarEvent) => ({ backgroundColor: event.eventColor , fontSize: 14}),
|
||||||
[profileData]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
// console.log({memoizedWeekStartsOn, profileData: profileData?.firstDayOfWeek})
|
const memoizedWeekStartsOn = useMemo(
|
||||||
|
() => (profileData?.firstDayOfWeek === "Mondays" ? 1 : 0),
|
||||||
|
[profileData]
|
||||||
|
);
|
||||||
|
|
||||||
const isSameDate = useCallback((date1: Date, date2: Date) => {
|
// console.log({memoizedWeekStartsOn, profileData: profileData?.firstDayOfWeek,
|
||||||
return (
|
});
|
||||||
date1.getDate() === date2.getDate() &&
|
|
||||||
date1.getMonth() === date2.getMonth() &&
|
|
||||||
date1.getFullYear() === date2.getFullYear()
|
|
||||||
);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const dayHeaderColor = useMemo(() => {
|
const isSameDate = useCallback((date1: Date, date2: Date) => {
|
||||||
return isSameDate(todaysDate, selectedDate) ? "white" : "#4d4d4d";
|
return (
|
||||||
}, [selectedDate, mode]);
|
date1.getDate() === date2.getDate() &&
|
||||||
|
date1.getMonth() === date2.getMonth() &&
|
||||||
|
date1.getFullYear() === date2.getFullYear()
|
||||||
|
);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const dateStyle = useMemo(() => {
|
const dayHeaderColor = useMemo(() => {
|
||||||
if (mode === "week") return undefined;
|
return isSameDate(todaysDate, selectedDate) ? "white" : "#4d4d4d";
|
||||||
return isSameDate(todaysDate, selectedDate) && mode === "day"
|
}, [selectedDate, mode]);
|
||||||
? styles.dayHeader
|
|
||||||
: styles.otherDayHeader;
|
|
||||||
}, [selectedDate, mode]);
|
|
||||||
|
|
||||||
const memoizedHeaderContentStyle = useMemo(() => {
|
const dateStyle = useMemo(() => {
|
||||||
if (mode === "day") {
|
if (mode === "week") return undefined;
|
||||||
return styles.dayModeHeader;
|
return isSameDate(todaysDate, selectedDate) && mode === "day"
|
||||||
} else if (mode === "week") {
|
? styles.dayHeader
|
||||||
return styles.weekModeHeader;
|
: styles.otherDayHeader;
|
||||||
} else if (mode === "month") {
|
}, [selectedDate, mode]);
|
||||||
return styles.monthModeHeader;
|
|
||||||
} else {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
}, [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 { enrichedEvents, filteredEvents } = useMemo(() => {
|
||||||
const startTime = Date.now(); // Start timer
|
const startTime = Date.now(); // Start timer
|
||||||
|
|
||||||
const startOffset = mode === "month" ? 40 : mode === "week" ? 10 : 1;
|
const startOffset = mode === "month" ? 40 : mode === "week" ? 10 : 1;
|
||||||
const endOffset = mode === "month" ? 40 : mode === "week" ? 10 : 1;
|
const endOffset = mode === "month" ? 40 : mode === "week" ? 10 : 1;
|
||||||
|
|
||||||
const filteredEvents = events?.filter(event =>
|
const filteredEvents =
|
||||||
event.start && event.end &&
|
events?.filter(
|
||||||
isWithinInterval(event.start, {
|
(event) =>
|
||||||
start: subDays(selectedDate, startOffset),
|
event.start &&
|
||||||
end: addDays(selectedDate, endOffset)
|
event.end &&
|
||||||
}) &&
|
isWithinInterval(event.start, {
|
||||||
isWithinInterval(event.end, {
|
start: subDays(selectedDate, startOffset),
|
||||||
start: subDays(selectedDate, startOffset),
|
end: addDays(selectedDate, endOffset),
|
||||||
end: addDays(selectedDate, endOffset)
|
}) &&
|
||||||
})
|
isWithinInterval(event.end, {
|
||||||
) ?? [];
|
start: subDays(selectedDate, startOffset),
|
||||||
|
end: addDays(selectedDate, endOffset),
|
||||||
|
})
|
||||||
|
) ?? [];
|
||||||
|
|
||||||
const enrichedEvents = filteredEvents.reduce((acc, event) => {
|
const enrichedEvents = filteredEvents.reduce((acc, event) => {
|
||||||
const dateKey = event.start.toISOString().split('T')[0];
|
const dateKey = event.start.toISOString().split("T")[0];
|
||||||
acc[dateKey] = acc[dateKey] || [];
|
acc[dateKey] = acc[dateKey] || [];
|
||||||
acc[dateKey].push({
|
acc[dateKey].push({
|
||||||
...event,
|
...event,
|
||||||
overlapPosition: false,
|
overlapPosition: false,
|
||||||
overlapCount: 0
|
overlapCount: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
acc[dateKey].sort((a, b) => compareAsc(a.start, b.start));
|
acc[dateKey].sort((a, b) => compareAsc(a.start, b.start));
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, {} as Record<string, CalendarEvent[]>);
|
}, {} as Record<string, CalendarEvent[]>);
|
||||||
|
|
||||||
const endTime = Date.now();
|
const endTime = Date.now();
|
||||||
// console.log("memoizedEvents computation time:", endTime - startTime, "ms");
|
// console.log("memoizedEvents computation time:", endTime - startTime, "ms");
|
||||||
|
|
||||||
return {enrichedEvents, filteredEvents};
|
return { enrichedEvents, filteredEvents };
|
||||||
}, [events, selectedDate, mode]);
|
}, [events, selectedDate, mode]);
|
||||||
|
|
||||||
const renderCustomDateForMonth = (date: Date) => {
|
const renderCustomDateForMonth = (date: Date) => {
|
||||||
const circleStyle = useMemo<ViewStyle>(
|
const circleStyle = useMemo<ViewStyle>(
|
||||||
() => ({
|
() => ({
|
||||||
width: 30,
|
width: 30,
|
||||||
height: 30,
|
height: 30,
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
borderRadius: 15,
|
borderRadius: 15,
|
||||||
}),
|
}),
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const defaultStyle = useMemo<ViewStyle>(
|
const defaultStyle = useMemo<ViewStyle>(
|
||||||
() => ({
|
() => ({
|
||||||
...circleStyle,
|
...circleStyle,
|
||||||
}),
|
}),
|
||||||
[circleStyle]
|
[circleStyle]
|
||||||
);
|
);
|
||||||
|
|
||||||
const currentDateStyle = useMemo<ViewStyle>(
|
const currentDateStyle = useMemo<ViewStyle>(
|
||||||
() => ({
|
() => ({
|
||||||
...circleStyle,
|
...circleStyle,
|
||||||
backgroundColor: "#4184f2",
|
backgroundColor: "#4184f2",
|
||||||
}),
|
}),
|
||||||
[circleStyle]
|
[circleStyle]
|
||||||
);
|
);
|
||||||
|
|
||||||
const renderDate = useCallback(
|
const renderDate = useCallback(
|
||||||
(date: Date) => {
|
(date: Date) => {
|
||||||
const isCurrentDate = isSameDate(todaysDate, date);
|
const isCurrentDate = isSameDate(todaysDate, date);
|
||||||
const appliedStyle = isCurrentDate ? currentDateStyle : defaultStyle;
|
const appliedStyle = isCurrentDate ? currentDateStyle : defaultStyle;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={{alignItems: "center"}}>
|
<View style={{ alignItems: "center" }}>
|
||||||
<View style={appliedStyle}>
|
<View style={appliedStyle}>
|
||||||
<Text style={{color: isCurrentDate ? "white" : "black"}}>
|
<Text style={{ color: isCurrentDate ? "white" : "black" }}>
|
||||||
{date.getDate()}
|
{date.getDate()}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
[todaysDate, currentDateStyle, defaultStyle] // dependencies
|
[todaysDate, currentDateStyle, defaultStyle] // dependencies
|
||||||
);
|
);
|
||||||
|
|
||||||
return renderDate(date);
|
return renderDate(date);
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setOffsetMinutes(getTotalMinutes());
|
setOffsetMinutes(getTotalMinutes());
|
||||||
}, [events, mode]);
|
}, [events, mode]);
|
||||||
|
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<View style={styles.loadingContainer}>
|
<View style={styles.loadingContainer}>
|
||||||
{isSyncing && <Text>Syncing...</Text>}
|
{isSyncing && <Text>Syncing...</Text>}
|
||||||
<ActivityIndicator size="large" color="#0000ff"/>
|
<ActivityIndicator size="large" color="#0000ff"/>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// console.log(enrichedEvents, filteredEvents)
|
// console.log(enrichedEvents, filteredEvents)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{isSyncing && (
|
{isSyncing && (
|
||||||
<View style={styles.loadingContainer}>
|
<View style={styles.loadingContainer}>
|
||||||
{isSyncing && <Text>Syncing...</Text>}
|
{isSyncing && <Text>Syncing...</Text>}
|
||||||
@ -277,7 +292,7 @@ export const EventCalendar: React.FC<EventCalendarProps> = React.memo(
|
|||||||
overflow:"hidden",
|
overflow:"hidden",
|
||||||
} : {}}
|
} : {}}
|
||||||
hourStyle={styles.hourStyle}
|
hourStyle={styles.hourStyle}
|
||||||
ampm
|
onPressDateHeader={handlePressDayHeader} ampm
|
||||||
// renderCustomDateForMonth={renderCustomDateForMonth}
|
// renderCustomDateForMonth={renderCustomDateForMonth}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -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");
|
||||||
|
@ -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>
|
||||||
|
@ -27,7 +27,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?
|
||||||
@ -103,7 +103,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",
|
||||||
|
@ -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";
|
||||||
import {useDeleteUser} from "@/hooks/firebase/useDeleteUser";
|
import {useDeleteUser} from "@/hooks/firebase/useDeleteUser";
|
||||||
|
|
||||||
const MyProfile = () => {
|
const MyProfile = () => {
|
||||||
@ -35,6 +36,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 = () => {
|
||||||
@ -104,6 +112,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}>
|
||||||
@ -217,9 +247,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 }}
|
||||||
@ -248,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",
|
||||||
|
@ -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}
|
||||||
|
@ -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
|
||||||
/>
|
/>
|
||||||
|
@ -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>
|
||||||
|
@ -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);
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user