1
1
mirror of https://github.com/theoludwig/p61-project.git synced 2024-07-17 07:00:12 +02:00
p61-project/presentation/react/components/HabitsMainPage/HabitsMainPage.tsx

46 lines
1.1 KiB
TypeScript
Raw Normal View History

import { useMemo, useState } from "react"
import { Agenda } from "react-native-calendars"
2024-03-24 23:41:23 +01:00
import type { HabitsTracker } from "@/domain/entities/HabitsTracker"
import { getISODate } from "@/utils/dates"
import { HabitsList } from "./HabitsList"
2024-03-24 23:41:23 +01:00
export interface HabitsMainPageProps {
habitsTracker: HabitsTracker
2024-03-24 23:41:23 +01:00
}
export const HabitsMainPage: React.FC<HabitsMainPageProps> = (props) => {
const { habitsTracker } = props
const today = useMemo(() => {
return new Date()
}, [])
const todayISO = getISODate(today)
const [selectedDate, setSelectedDate] = useState<Date>(today)
const selectedISODate = getISODate(selectedDate)
2024-03-24 23:41:23 +01:00
return (
<Agenda
firstDay={1}
showClosingKnob
showOnlySelectedDayItems
onDayPress={(date) => {
setSelectedDate(new Date(date.dateString))
}}
markedDates={{
[todayISO]: { marked: true },
}}
selected={selectedISODate}
renderList={() => {
return (
<HabitsList
habitsTracker={habitsTracker}
selectedDate={selectedDate}
/>
)
}}
/>
2024-03-24 23:41:23 +01:00
)
}