import LottieView from "lottie-react-native" import { useRef, useState } from "react" import { Dimensions, ScrollView, View } from "react-native" import { Divider, List, Text } from "react-native-paper" import { GOAL_FREQUENCIES, type GoalFrequency } from "@/domain/entities/Goal" import type { HabitHistory } from "@/domain/entities/HabitHistory" import type { HabitsTracker } from "@/domain/entities/HabitsTracker" import { capitalize } from "@/utils/strings" import confettiJSON from "../../../assets/confetti.json" import { HabitCard } from "./HabitCard" export interface HabitsListProps { habitsTracker: HabitsTracker selectedDate: Date } export const HabitsList: React.FC = (props) => { const { habitsTracker, selectedDate } = props const [accordionExpanded, setAccordionExpanded] = useState<{ [key in GoalFrequency]: boolean }>({ daily: true, weekly: true, monthly: true, }) const confettiRef = useRef(null) const habitsHistoriesByFrequency: Record = { daily: habitsTracker.getHabitsHistoriesByDate({ selectedDate, frequency: "daily", }), weekly: habitsTracker.getHabitsHistoriesByDate({ selectedDate, frequency: "weekly", }), monthly: habitsTracker.getHabitsHistoriesByDate({ selectedDate, frequency: "monthly", }), } const frequenciesFiltered = GOAL_FREQUENCIES.filter((frequency) => { return habitsHistoriesByFrequency[frequency].length > 0 }) return ( <> {selectedDate.toLocaleDateString("en-US", { weekday: "long", year: "numeric", month: "long", day: "numeric", })} {frequenciesFiltered.length > 0 ? ( {frequenciesFiltered.map((frequency) => { return ( { setAccordionExpanded((old) => { return { ...old, [frequency]: !old[frequency], } }) }} key={frequency} title={capitalize(frequency)} titleStyle={[ { fontSize: 26, }, ]} > {habitsHistoriesByFrequency[frequency].map((item) => { return ( ) })} ) })} ) : ( No habits for this date )} ) }