2024-03-24 23:41:23 +01:00
|
|
|
import { FlatList } from "react-native"
|
|
|
|
import { List } from "react-native-paper"
|
2024-03-25 13:05:15 +01:00
|
|
|
import { useState } from "react"
|
2024-03-24 23:41:23 +01:00
|
|
|
|
2024-03-25 13:05:15 +01:00
|
|
|
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"
|
2024-03-24 23:41:23 +01:00
|
|
|
import { HabitHistory } from "./HabitHistory"
|
|
|
|
|
|
|
|
export interface HabitsHistoryProps {
|
2024-03-25 13:05:15 +01:00
|
|
|
habitsTracker: HabitsTracker
|
2024-03-24 23:41:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const HabitsHistory: React.FC<HabitsHistoryProps> = (props) => {
|
2024-03-25 13:05:15 +01:00
|
|
|
const { habitsTracker } = props
|
|
|
|
|
|
|
|
const [accordionExpanded, setAccordionExpanded] = useState<{
|
|
|
|
[key in GoalFrequency]: boolean
|
|
|
|
}>({
|
|
|
|
daily: true,
|
|
|
|
weekly: true,
|
|
|
|
monthly: true,
|
|
|
|
})
|
2024-03-24 23:41:23 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<List.Section
|
|
|
|
style={[
|
|
|
|
{
|
2024-03-25 13:05:15 +01:00
|
|
|
width: "92%",
|
2024-03-24 23:41:23 +01:00
|
|
|
},
|
|
|
|
]}
|
|
|
|
>
|
2024-03-25 13:05:15 +01:00
|
|
|
{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>
|
|
|
|
)
|
|
|
|
})}
|
2024-03-24 23:41:23 +01:00
|
|
|
</List.Section>
|
|
|
|
)
|
|
|
|
}
|