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

54 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-04-09 23:53:55 +02:00
import { useState } from "react"
import { Agenda } from "react-native-calendars"
2024-03-24 23:41:23 +01:00
2024-04-09 23:53:55 +02:00
import { GOAL_FREQUENCIES } from "@/domain/entities/Goal"
import type { HabitsTracker } from "@/domain/entities/HabitsTracker"
2024-05-02 01:08:27 +02:00
import { getISODate, getNowDateUTC } from "@/utils/dates"
2024-04-09 23:53:55 +02:00
import { HabitsEmpty } from "./HabitsEmpty"
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
2024-05-02 01:08:27 +02:00
const today = getNowDateUTC()
const todayISO = getISODate(today)
const [selectedDate, setSelectedDate] = useState<Date>(today)
2024-04-09 23:53:55 +02:00
const selectedDateISO = getISODate(selectedDate)
const frequenciesFiltered = GOAL_FREQUENCIES.filter((frequency) => {
return habitsTracker.habitsHistory[frequency].length > 0
})
if (frequenciesFiltered.length <= 0) {
return <HabitsEmpty />
}
2024-03-24 23:41:23 +01:00
return (
<Agenda
firstDay={1}
showClosingKnob
onDayPress={(date) => {
setSelectedDate(new Date(date.dateString))
}}
markedDates={{
2024-04-09 23:53:55 +02:00
[todayISO]: { marked: true, today: true },
}}
2024-04-09 23:53:55 +02:00
maxDate={todayISO}
selected={selectedDateISO}
renderList={() => {
return (
<HabitsList
habitsTracker={habitsTracker}
selectedDate={selectedDate}
/>
)
}}
/>
2024-03-24 23:41:23 +01:00
)
}