@@ -15,7 +15,7 @@ import {
1515 subDays ,
1616} from "@hypr/utils" ;
1717
18- import { CalendarDaysIcon , CalendarIcon , ChevronLeftIcon , ChevronRightIcon , FileTextIcon , Pen } from "lucide-react" ;
18+ import { Calendar , CalendarDays , ChevronLeft , ChevronRight , FileText , Pen } from "lucide-react" ;
1919import { useState } from "react" ;
2020
2121import * as persisted from "../../../store/tinybase/persisted" ;
@@ -34,7 +34,7 @@ export const TabItemCalendar: TabItem = (
3434) => {
3535 return (
3636 < TabItemBase
37- icon = { < CalendarIcon className = "w-4 h-4" /> }
37+ icon = { < Calendar size = { 16 } /> }
3838 title = { "Calendar" }
3939 active = { tab . active }
4040 handleCloseThis = { ( ) => handleCloseThis ( tab ) }
@@ -54,14 +54,8 @@ export function TabContentCalendar({ tab }: { tab: Tab }) {
5454
5555 const { openCurrent } = useTabs ( ) ;
5656
57- // Fetch all calendars
5857 const calendarIds = persisted . UI . useRowIds ( "calendars" , persisted . STORE_ID ) ;
59- const calendars = calendarIds . map ( ( id ) => ( {
60- id,
61- ...persisted . UI . useRow ( "calendars" , id , persisted . STORE_ID ) ,
62- } ) ) ;
6358
64- // Initialize selectedCalendars with all calendar IDs by default
6559 const [ selectedCalendars , setSelectedCalendars ] = useState < Set < string > > ( ( ) => new Set ( calendarIds ) ) ;
6660
6761 const toggleCalendar = ( calendarId : string ) => {
@@ -105,26 +99,19 @@ export function TabContentCalendar({ tab }: { tab: Tab }) {
10599 < aside className = "w-64 border-r border-neutral-200 bg-white flex flex-col" >
106100 < div className = "p-2 border-b border-neutral-200 flex items-center gap-2" >
107101 < Button size = "icon" variant = { sidebarOpen ? "default" : "ghost" } onClick = { ( ) => setSidebarOpen ( false ) } >
108- < CalendarDaysIcon size = { 16 } />
102+ < CalendarDays size = { 16 } />
109103 </ Button >
110104 My Calendars
111105 </ div >
112106 < div className = "flex-1 overflow-y-auto p-4" >
113107 < div className = "space-y-3" >
114- { calendars . map ( ( calendar ) => (
115- < div key = { calendar . id } className = "flex items-center space-x-2" >
116- < Checkbox
117- id = { `calendar-${ calendar . id } ` }
118- checked = { selectedCalendars . has ( calendar . id ) }
119- onCheckedChange = { ( ) => toggleCalendar ( calendar . id ) }
120- />
121- < label
122- htmlFor = { `calendar-${ calendar . id } ` }
123- className = "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer"
124- >
125- { calendar . name }
126- </ label >
127- </ div >
108+ { calendarIds . map ( ( id ) => (
109+ < CalendarCheckboxRow
110+ key = { id }
111+ id = { id }
112+ checked = { selectedCalendars . has ( id ) }
113+ onToggle = { ( ) => toggleCalendar ( id ) }
114+ />
128115 ) ) }
129116 </ div >
130117 </ div >
@@ -136,7 +123,7 @@ export function TabContentCalendar({ tab }: { tab: Tab }) {
136123 < div className = "p-2 flex items-center relative" >
137124 { ! sidebarOpen && (
138125 < Button size = "icon" variant = "ghost" onClick = { ( ) => setSidebarOpen ( true ) } >
139- < CalendarDaysIcon size = { 16 } />
126+ < CalendarDays size = { 16 } />
140127 </ Button >
141128 ) }
142129 < div className = "text-xl font-semibold absolute left-1/2 transform -translate-x-1/2" > { monthLabel } </ div >
@@ -146,7 +133,7 @@ export function TabContentCalendar({ tab }: { tab: Tab }) {
146133 size = "icon"
147134 onClick = { handlePreviousMonth }
148135 >
149- < ChevronLeftIcon size = { 16 } />
136+ < ChevronLeft size = { 16 } />
150137 </ Button >
151138
152139 < Button
@@ -162,7 +149,7 @@ export function TabContentCalendar({ tab }: { tab: Tab }) {
162149 size = "icon"
163150 onClick = { handleNextMonth }
164151 >
165- < ChevronRightIcon size = { 16 } />
152+ < ChevronRight size = { 16 } />
166153 </ Button >
167154 </ ButtonGroup >
168155 </ div >
@@ -202,6 +189,23 @@ export function TabContentCalendar({ tab }: { tab: Tab }) {
202189 ) ;
203190}
204191
192+ function CalendarCheckboxRow (
193+ { id, checked, onToggle } : { id : string ; checked : boolean ; onToggle : ( ) => void } ,
194+ ) {
195+ const calendar = persisted . UI . useRow ( "calendars" , id , persisted . STORE_ID ) ;
196+ return (
197+ < div className = "flex items-center space-x-2" >
198+ < Checkbox id = { `calendar-${ id } ` } checked = { checked } onCheckedChange = { onToggle } />
199+ < label
200+ htmlFor = { `calendar-${ id } ` }
201+ className = "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer"
202+ >
203+ { calendar ?. name ?? "Untitled" }
204+ </ label >
205+ </ div >
206+ ) ;
207+ }
208+
205209function TabContentCalendarDay ( {
206210 day,
207211 isCurrentMonth,
@@ -222,10 +226,11 @@ function TabContentCalendarDay({
222226 persisted . STORE_ID ,
223227 ) ;
224228
225- // Filter events by selected calendars
229+ const store = persisted . UI . useStore ( persisted . STORE_ID ) ;
230+
226231 const eventIds = allEventIds . filter ( ( eventId ) => {
227- const event = persisted . UI . useRow ( "events" , eventId , persisted . STORE_ID ) ;
228- return event . calendar_id && selectedCalendars . has ( event . calendar_id ) ;
232+ const event = store ?. getRow ( "events" , eventId ) ;
233+ return event ? .calendar_id && selectedCalendars . has ( event . calendar_id as string ) ;
229234 } ) ;
230235
231236 const sessionIds = persisted . UI . useSliceRowIds (
@@ -346,6 +351,10 @@ function TabContentCalendarDayEvents({ eventId }: { eventId: string }) {
346351 const start = new Date ( event . started_at ) ;
347352 const end = new Date ( event . ended_at ) ;
348353
354+ if ( isNaN ( start . getTime ( ) ) || isNaN ( end . getTime ( ) ) ) {
355+ return "" ;
356+ }
357+
349358 if ( isSameDay ( start , end ) ) {
350359 return `${ format ( start , "MMM d" ) } , ${ format ( start , "h:mm a" ) } - ${ format ( end , "h:mm a" ) } ` ;
351360 }
@@ -356,7 +365,7 @@ function TabContentCalendarDayEvents({ eventId }: { eventId: string }) {
356365 < Popover open = { open } onOpenChange = { setOpen } >
357366 < PopoverTrigger asChild >
358367 < div className = "flex items-center space-x-1 px-0.5 py-0.5 cursor-pointer rounded hover:bg-neutral-200 transition-colors h-5" >
359- < CalendarIcon className = "w-2.5 h-2.5 text-neutral-500 flex-shrink-0" />
368+ < Calendar size = { 12 } className = "text-neutral-500 flex-shrink-0" />
360369 < div className = "flex-1 text-xs text-neutral-800 truncate" >
361370 { event . title }
362371 </ div >
@@ -377,7 +386,7 @@ function TabContentCalendarDayEvents({ eventId }: { eventId: string }) {
377386 className = "flex items-center gap-2 px-2 py-1 bg-neutral-50 border border-neutral-200 rounded-md cursor-pointer hover:bg-neutral-100 transition-colors"
378387 onClick = { handleClick }
379388 >
380- < FileTextIcon className = "size-3 text-neutral-600 flex-shrink-0" />
389+ < FileText size = { 12 } className = "text-neutral-600 flex-shrink-0" />
381390 < div className = "text-xs font-medium text-neutral-800 truncate" >
382391 { linkedSession ?. title || "Untitled Note" }
383392 </ div >
@@ -412,15 +421,21 @@ function TabContentCalendarDaySessions({ sessionId }: { sessionId: string }) {
412421 } ;
413422
414423 const formatSessionTime = ( ) => {
415- const created = new Date ( session . created_at || "" ) ;
424+ if ( ! session . created_at ) {
425+ return "Created: —" ;
426+ }
427+ const created = new Date ( session . created_at ) ;
428+ if ( isNaN ( created . getTime ( ) ) ) {
429+ return "Created: —" ;
430+ }
416431 return `Created: ${ format ( created , "MMM d, h:mm a" ) } ` ;
417432 } ;
418433
419434 return (
420435 < Popover open = { open } onOpenChange = { setOpen } >
421436 < PopoverTrigger asChild >
422437 < div className = "flex items-center space-x-1 px-0.5 py-0.5 cursor-pointer rounded hover:bg-neutral-200 transition-colors h-5" >
423- < FileTextIcon className = "w-2.5 h-2.5 text-neutral-500 flex-shrink-0" />
438+ < FileText size = { 12 } className = "text-neutral-500 flex-shrink-0" />
424439 < div className = "flex-1 text-xs text-neutral-800 truncate" >
425440 { event && session . event_id ? event . title : session . title || "Untitled" }
426441 </ div >
@@ -439,7 +454,7 @@ function TabContentCalendarDaySessions({ sessionId }: { sessionId: string }) {
439454 className = "flex items-center gap-2 px-2 py-1 bg-neutral-50 border border-neutral-200 rounded-md cursor-pointer hover:bg-neutral-100 transition-colors"
440455 onClick = { handleClick }
441456 >
442- < FileTextIcon className = "size-3 text-neutral-600 flex-shrink-0" />
457+ < FileText size = { 12 } className = "text-neutral-600 flex-shrink-0" />
443458 < div className = "text-xs font-medium text-neutral-800 truncate" >
444459 { event && session . event_id ? event . title : session . title || "Untitled" }
445460 </ div >
0 commit comments