2024-04-09 23:53:55 +02:00
|
|
|
import { useState } from "react"
|
2024-04-08 23:21:36 +02:00
|
|
|
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"
|
2024-03-25 13:05:15 +01:00
|
|
|
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"
|
2024-04-08 23:21:36 +02:00
|
|
|
import { HabitsList } from "./HabitsList"
|
2024-03-24 23:41:23 +01:00
|
|
|
|
2024-04-05 13:50:51 +02:00
|
|
|
export interface HabitsMainPageProps {
|
2024-03-25 13:05:15 +01:00
|
|
|
habitsTracker: HabitsTracker
|
2024-03-24 23:41:23 +01:00
|
|
|
}
|
|
|
|
|
2024-04-05 13:50:51 +02:00
|
|
|
export const HabitsMainPage: React.FC<HabitsMainPageProps> = (props) => {
|
2024-03-25 13:05:15 +01:00
|
|
|
const { habitsTracker } = props
|
|
|
|
|
2024-05-02 01:08:27 +02:00
|
|
|
const today = getNowDateUTC()
|
2024-04-08 23:21:36 +02:00
|
|
|
const todayISO = getISODate(today)
|
2024-04-04 11:21:56 +02:00
|
|
|
|
2024-04-08 23:21:36 +02:00
|
|
|
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-04-04 11:21:56 +02:00
|
|
|
|
2024-03-24 23:41:23 +01:00
|
|
|
return (
|
2024-04-08 23:21:36 +02:00
|
|
|
<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-08 23:21:36 +02:00
|
|
|
}}
|
2024-04-09 23:53:55 +02:00
|
|
|
maxDate={todayISO}
|
|
|
|
selected={selectedDateISO}
|
2024-04-08 23:21:36 +02:00
|
|
|
renderList={() => {
|
|
|
|
return (
|
|
|
|
<HabitsList
|
|
|
|
habitsTracker={habitsTracker}
|
|
|
|
selectedDate={selectedDate}
|
|
|
|
/>
|
|
|
|
)
|
2024-04-05 13:50:51 +02:00
|
|
|
}}
|
2024-04-08 23:21:36 +02:00
|
|
|
/>
|
2024-03-24 23:41:23 +01:00
|
|
|
)
|
|
|
|
}
|