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/HabitsHistory/HabitsHistory.tsx

66 lines
1.7 KiB
TypeScript

import { FlatList } from "react-native"
import { List } from "react-native-paper"
import { useState } from "react"
import type { GoalFrequency } from "@/domain/entities/Goal"
import { GOAL_FREQUENCIES } from "@/domain/entities/Goal"
import type { HabitsTracker } from "@/domain/entities/HabitsTracker"
import { capitalize } from "@/presentation/presenters/utils/strings"
import { HabitHistory } from "./HabitHistory"
export interface HabitsHistoryProps {
habitsTracker: HabitsTracker
}
export const HabitsHistory: React.FC<HabitsHistoryProps> = (props) => {
const { habitsTracker } = props
const [accordionExpanded, setAccordionExpanded] = useState<{
[key in GoalFrequency]: boolean
}>({
daily: true,
weekly: true,
monthly: true,
})
return (
<List.Section
style={[
{
width: "92%",
},
]}
>
{GOAL_FREQUENCIES.map((frequency) => {
return (
<List.Accordion
expanded={accordionExpanded[frequency]}
onPress={() => {
setAccordionExpanded((old) => {
return {
...old,
[frequency]: !old[frequency],
}
})
}}
key={frequency}
title={capitalize(frequency)}
titleStyle={[
{
fontSize: 26,
},
]}
>
<FlatList
data={habitsTracker.habitsHistory[frequency]}
renderItem={({ item }) => {
return <HabitHistory habitHistory={item} />
}}
/>
</List.Accordion>
)
})}
</List.Section>
)
}