1- import { forwardRef , useEffect , useImperativeHandle , useRef } from "react" ;
1+ import { forwardRef , useImperativeHandle , useRef } from "react" ;
22import useToggle from "../../hooks/useToggle" ;
33import {
4- StyledCalendarDay ,
54 StyledCalendarDays ,
65 StyledCalendarDaysFrame ,
76 StyledCalendarLayout ,
@@ -10,6 +9,8 @@ import useSystemSettings from "../../stores/systemSettingsStore";
109import { BorderedAppContentHandles } from "../../components/BorderedApp/BorderedApp" ;
1110import CalendarNavigation from "./CalendarNavigation/CalendarNavigation" ;
1211import { useCalendar } from "./hooks/useCalendar" ;
12+ import CalendarSidebar from "./CalendarSidebar/CalendarSidebar" ;
13+ import CalendarDay from "./CalendarDay/CalendarDay" ;
1314
1415type CalendarHandles = BorderedAppContentHandles < HTMLDivElement > ;
1516
@@ -19,74 +20,40 @@ const Calendar = forwardRef<CalendarHandles, CalendarProps>((_props, ref) => {
1920 const sidebarToggle = useToggle ( ) ;
2021 const calendarRef = useRef < HTMLDivElement > ( null ) ;
2122 const calendar = useCalendar ( ) ;
22- const [ mainColor , accentColor , fontColor ] = useSystemSettings ( ( s ) => [
23- s . mainColor ,
24- s . accentColor ,
25- s . fontColor ,
26- ] ) ;
23+ const [ accentColor ] = useSystemSettings ( ( s ) => [ s . accentColor ] ) ;
2724
2825 useImperativeHandle ( ref , ( ) => ( {
29- onParentKeyDown ( ) { } ,
3026 element : calendarRef . current ,
3127 } ) ) ;
3228
33- useEffect ( ( ) => {
34- console . log ( "sidebar toggle" , sidebarToggle . state ) ;
35- } , [ sidebarToggle . state ] ) ;
36-
37- useEffect ( ( ) => {
38- if ( ! calendarRef . current ) return ;
39- const el = calendarRef . current ;
40-
41- function onResize ( entries : ResizeObserverEntry [ ] ) {
42- const entry = entries [ 0 ] ;
43- if ( ! entry ) return ;
44-
45- const width = entry . contentRect . width ;
46-
47- const wide = width >= 600 ;
48- sidebarToggle . setState ( wide ) ;
49- }
50-
51- const observer = new ResizeObserver ( onResize ) ;
52-
53- observer . observe ( el ) ;
54-
55- return ( ) => {
56- if ( el ) observer . unobserve ( el ) ;
57- observer . disconnect ( ) ;
58- } ;
59- } ) ;
60-
6129 return (
6230 < StyledCalendarLayout
6331 ref = { calendarRef }
6432 sidebarOpen = { sidebarToggle . state }
6533 className = "calendar"
6634 >
6735 < CalendarNavigation
68- month = { calendar . month }
69- year = { calendar . year }
36+ month = { calendar . cursor . getMonth ( ) }
37+ year = { calendar . cursor . getFullYear ( ) }
7038 onClickNextMonth = { calendar . nextMonth }
7139 onClickNextYear = { calendar . nextYear }
7240 onClickPrevMonth = { calendar . prevMonth }
7341 onClickPrevYear = { calendar . prevYear }
7442 />
43+ < CalendarSidebar date = { calendar . cursor } />
7544 < StyledCalendarDaysFrame frameColor = { accentColor } >
7645 < StyledCalendarDays
7746 borderColor = { accentColor }
7847 className = "calendar__days"
7948 >
80- { calendar . days . map ( ( { date, day, isToday, isThisMonth } ) => (
81- < StyledCalendarDay
82- backgroundColor = { mainColor }
83- color = { fontColor }
84- currentMonth = { isThisMonth }
85- >
86- < span > { day } </ span >
87- < span > { date } </ span >
88- { isToday && < span > TODAY</ span > }
89- </ StyledCalendarDay >
49+ { calendar . days . map ( ( day ) => (
50+ < CalendarDay
51+ date = { day . date }
52+ isThisMonth = { day . isThisMonth }
53+ isToday = { day . isToday }
54+ onClick = { ( ) => calendar . setCursor ( day . date ) }
55+ key = { day . date . toISOString ( ) }
56+ />
9057 ) ) }
9158 </ StyledCalendarDays >
9259 </ StyledCalendarDaysFrame >
0 commit comments