2024-04-08 23:21:36 +02:00
|
|
|
import { useState } from "react"
|
|
|
|
import { Dimensions, ScrollView } from "react-native"
|
2024-04-09 23:53:55 +02:00
|
|
|
import { Divider, List } from "react-native-paper"
|
2024-04-08 23:21:36 +02:00
|
|
|
|
|
|
|
import type { GoalFrequency } from "@/domain/entities/Goal"
|
|
|
|
import type { HabitsTracker } from "@/domain/entities/HabitsTracker"
|
|
|
|
import { capitalize } from "@/utils/strings"
|
|
|
|
import { HabitCard } from "./HabitCard"
|
|
|
|
|
|
|
|
export interface HabitsListProps {
|
|
|
|
habitsTracker: HabitsTracker
|
|
|
|
selectedDate: Date
|
2024-04-09 23:53:55 +02:00
|
|
|
frequenciesFiltered: GoalFrequency[]
|
2024-04-08 23:21:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const HabitsList: React.FC<HabitsListProps> = (props) => {
|
2024-04-09 23:53:55 +02:00
|
|
|
const { habitsTracker, selectedDate, frequenciesFiltered } = props
|
2024-04-08 23:21:36 +02:00
|
|
|
|
|
|
|
const [accordionExpanded, setAccordionExpanded] = useState<{
|
|
|
|
[key in GoalFrequency]: boolean
|
|
|
|
}>({
|
|
|
|
daily: true,
|
|
|
|
weekly: true,
|
|
|
|
monthly: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ScrollView
|
|
|
|
showsVerticalScrollIndicator={false}
|
|
|
|
style={{
|
|
|
|
paddingHorizontal: 20,
|
|
|
|
width: Dimensions.get("window").width,
|
2024-04-09 23:53:55 +02:00
|
|
|
backgroundColor: "white",
|
2024-04-08 23:21:36 +02:00
|
|
|
}}
|
|
|
|
>
|
2024-04-09 23:53:55 +02:00
|
|
|
<Divider />
|
2024-04-08 23:21:36 +02:00
|
|
|
<List.Section>
|
|
|
|
{frequenciesFiltered.map((frequency) => {
|
|
|
|
return (
|
|
|
|
<List.Accordion
|
|
|
|
expanded={accordionExpanded[frequency]}
|
|
|
|
onPress={() => {
|
|
|
|
setAccordionExpanded((old) => {
|
|
|
|
return {
|
|
|
|
...old,
|
|
|
|
[frequency]: !old[frequency],
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
key={frequency}
|
|
|
|
title={capitalize(frequency)}
|
|
|
|
titleStyle={[
|
|
|
|
{
|
|
|
|
fontSize: 26,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
{habitsTracker.habitsHistory[frequency].map((item) => {
|
|
|
|
const goalProgress = item.getGoalProgressByDate(selectedDate)
|
|
|
|
return (
|
|
|
|
<HabitCard
|
|
|
|
habit={item.habit}
|
|
|
|
goalProgress={goalProgress}
|
|
|
|
key={item.habit.id}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</List.Accordion>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</List.Section>
|
|
|
|
</ScrollView>
|
|
|
|
)
|
|
|
|
}
|