mirror of
https://github.com/urosran/cally.git
synced 2025-11-27 00:44:54 +00:00
Fix day circle rendering
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
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 } 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 {
|
||||||
@ -12,7 +12,7 @@ import {
|
|||||||
} 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 { act } from "react-test-renderer";
|
import {Text} from "react-native-ui-lib";
|
||||||
|
|
||||||
interface EventCalendarProps {
|
interface EventCalendarProps {
|
||||||
calendarHeight: number;
|
calendarHeight: number;
|
||||||
@ -30,7 +30,6 @@ export const EventCalendar: React.FC<EventCalendarProps> = React.memo(
|
|||||||
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 [activeDate, setActiveDate] = useState<Date>(new Date());
|
|
||||||
const [mode, setMode] = useAtom(modeAtom);
|
const [mode, setMode] = useAtom(modeAtom);
|
||||||
|
|
||||||
const setEditVisible = useSetAtom(editVisibleAtom);
|
const setEditVisible = useSetAtom(editVisibleAtom);
|
||||||
@ -40,6 +39,8 @@ export const EventCalendar: React.FC<EventCalendarProps> = React.memo(
|
|||||||
const [isRendering, setIsRendering] = useState(true);
|
const [isRendering, setIsRendering] = useState(true);
|
||||||
const [offsetMinutes, setOffsetMinutes] = useState(getTotalMinutes());
|
const [offsetMinutes, setOffsetMinutes] = useState(getTotalMinutes());
|
||||||
|
|
||||||
|
const todaysDate = new Date()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (events && mode) {
|
if (events && mode) {
|
||||||
setIsRendering(true);
|
setIsRendering(true);
|
||||||
@ -93,32 +94,23 @@ export const EventCalendar: React.FC<EventCalendarProps> = React.memo(
|
|||||||
[profileData]
|
[profileData]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
const isSameDate = useCallback((date1: Date, date2: Date) => {
|
||||||
setActiveDate(new Date());
|
return (
|
||||||
|
date1.getDate() === date2.getDate() &&
|
||||||
const interval = setInterval(() => setActiveDate(new Date()), 60000);
|
date1.getMonth() === date2.getMonth() &&
|
||||||
return () => clearInterval(interval);
|
date1.getFullYear() === date2.getFullYear()
|
||||||
|
);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const dayHeaderColor = useMemo(() => {
|
const dayHeaderColor = useMemo(() => {
|
||||||
const isSameDate =
|
return isSameDate(todaysDate, selectedDate) && mode === "day" ? "white" : "#4d4d4d";
|
||||||
activeDate.getDate() === selectedDate.getDate() &&
|
}, [selectedDate, mode]);
|
||||||
activeDate.getMonth() === selectedDate.getMonth() &&
|
|
||||||
activeDate.getFullYear() === selectedDate.getFullYear();
|
|
||||||
|
|
||||||
return isSameDate && mode === "day" ? "white" : "#4d4d4d";
|
|
||||||
}, [selectedDate, mode, activeDate]);
|
|
||||||
|
|
||||||
const dateStyle = useMemo(() => {
|
const dateStyle = useMemo(() => {
|
||||||
const isSameDate =
|
return isSameDate(todaysDate, selectedDate) && mode === "day"
|
||||||
activeDate.getDate() === selectedDate.getDate() &&
|
|
||||||
activeDate.getMonth() === selectedDate.getMonth() &&
|
|
||||||
activeDate.getFullYear() === selectedDate.getFullYear();
|
|
||||||
|
|
||||||
return isSameDate && mode === "day"
|
|
||||||
? styles.dayHeader
|
? styles.dayHeader
|
||||||
: styles.otherDayHeader;
|
: styles.otherDayHeader;
|
||||||
}, [selectedDate, mode, activeDate]);
|
}, [selectedDate, mode]);
|
||||||
|
|
||||||
const memoizedHeaderContentStyle = useMemo(() => {
|
const memoizedHeaderContentStyle = useMemo(() => {
|
||||||
if (mode === "day") {
|
if (mode === "day") {
|
||||||
@ -134,6 +126,55 @@ export const EventCalendar: React.FC<EventCalendarProps> = React.memo(
|
|||||||
|
|
||||||
const memoizedEvents = useMemo(() => events ?? [], [events]);
|
const memoizedEvents = useMemo(() => events ?? [], [events]);
|
||||||
|
|
||||||
|
const renderCustomDateForMonth = (date: Date) => {
|
||||||
|
const circleStyle = useMemo<ViewStyle>(
|
||||||
|
() => ({
|
||||||
|
position: "absolute",
|
||||||
|
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(() => {
|
useEffect(() => {
|
||||||
setOffsetMinutes(getTotalMinutes());
|
setOffsetMinutes(getTotalMinutes());
|
||||||
}, [events, mode]);
|
}, [events, mode]);
|
||||||
@ -157,7 +198,7 @@ export const EventCalendar: React.FC<EventCalendarProps> = React.memo(
|
|||||||
onPressEvent={handlePressEvent}
|
onPressEvent={handlePressEvent}
|
||||||
weekStartsOn={memoizedWeekStartsOn}
|
weekStartsOn={memoizedWeekStartsOn}
|
||||||
height={calendarHeight}
|
height={calendarHeight}
|
||||||
activeDate={activeDate}
|
activeDate={todaysDate}
|
||||||
date={selectedDate}
|
date={selectedDate}
|
||||||
onPressCell={handlePressCell}
|
onPressCell={handlePressCell}
|
||||||
headerContentStyle={memoizedHeaderContentStyle}
|
headerContentStyle={memoizedHeaderContentStyle}
|
||||||
@ -165,6 +206,8 @@ export const EventCalendar: React.FC<EventCalendarProps> = React.memo(
|
|||||||
scrollOffsetMinutes={offsetMinutes}
|
scrollOffsetMinutes={offsetMinutes}
|
||||||
dayHeaderStyle={dateStyle}
|
dayHeaderStyle={dateStyle}
|
||||||
dayHeaderHighlightColor={dayHeaderColor}
|
dayHeaderHighlightColor={dayHeaderColor}
|
||||||
|
renderCustomDateForMonth={renderCustomDateForMonth}
|
||||||
|
showAdjacentMonths
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,6 +118,7 @@
|
|||||||
<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>
|
||||||
|
|||||||
Reference in New Issue
Block a user