1+ import { DateContext } from "@/components/date/context"
12import { useHabitContext } from "@/components/habit/context"
23import { formatDate } from "@/lib/dates"
34import { cn } from "@/lib/utils"
45import { type Completion } from "@/proto/models/v1/models_pb"
5- import type React from "react"
6+ import React from "react"
67
78import { HabitDatePicker } from "./date-picker"
89
@@ -27,7 +28,7 @@ interface CellProps {
2728}
2829
2930const Cell : React . FC < CellProps > = ( { date, background, completion, selected, interactive } ) => {
30- const { setDate } = useHabitContext ( )
31+ const { setSelectedDate } = useHabitContext ( )
3132
3233 let progress = 0
3334 if ( completion !== undefined ) {
@@ -44,7 +45,7 @@ const Cell: React.FC<CellProps> = ({ date, background, completion, selected, int
4445 style = { {
4546 opacity : progress === 0 ? 1 : progress ,
4647 } }
47- onClick = { interactive ? ( ) => setDate ( date ) : undefined }
48+ onClick = { interactive ? ( ) => setSelectedDate ( date ) : undefined }
4849 >
4950 { interactive && selected && < div className = "h-2 w-2 rounded-xs bg-secondary" /> }
5051 </ div >
@@ -56,9 +57,10 @@ interface P {
5657}
5758
5859export const HabitChart : React . FC < P > = ( { interactive } ) => {
59- const { habit, color, date } = useHabitContext ( )
60+ const today = React . useContext ( DateContext )
61+ const { habit, color, selectedDate } = useHabitContext ( )
6062 const now = new Date ( )
61- const selectedDateStr = formatDate ( date )
63+ const selectedDateStr = formatDate ( selectedDate ?? today )
6264
6365 return (
6466 < div className = "flex flex-col gap-2" >
0 commit comments