This repository has been archived on 2024-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
p61-project/presentation/react-native/components/HabitsMainPage/HabitsList.tsx

119 lines
3.3 KiB
TypeScript
Raw Normal View History

2024-04-11 23:03:45 +02:00
import LottieView from "lottie-react-native"
import { useRef, useState } from "react"
import { Dimensions, ScrollView, View } from "react-native"
2024-04-09 23:53:55 +02:00
import { Divider, List } from "react-native-paper"
import type { GoalFrequency } from "@/domain/entities/Goal"
import type { HabitsTracker } from "@/domain/entities/HabitsTracker"
import { capitalize } from "@/utils/strings"
2024-05-02 23:48:47 +02:00
import confettiJSON from "../../../assets/confetti.json"
import { HabitCard } from "./HabitCard"
export interface HabitsListProps {
habitsTracker: HabitsTracker
selectedDate: Date
2024-04-09 23:53:55 +02:00
frequenciesFiltered: GoalFrequency[]
}
export const HabitsList: React.FC<HabitsListProps> = (props) => {
2024-04-09 23:53:55 +02:00
const { habitsTracker, selectedDate, frequenciesFiltered } = props
const [accordionExpanded, setAccordionExpanded] = useState<{
[key in GoalFrequency]: boolean
}>({
daily: true,
weekly: true,
monthly: true,
})
2024-04-11 23:03:45 +02:00
const confettiRef = useRef<LottieView | null>(null)
return (
2024-04-11 23:03:45 +02:00
<>
<View
pointerEvents="none"
style={{
width: "100%",
height: "100%",
position: "absolute",
zIndex: 100,
justifyContent: "center",
alignItems: "center",
}}
>
<LottieView
ref={confettiRef}
source={confettiJSON}
autoPlay={false}
loop={false}
style={[
{
position: "absolute",
top: 0,
left: 0,
right: 0,
bottom: 0,
},
]}
resizeMode="cover"
/>
</View>
<ScrollView
showsVerticalScrollIndicator={false}
style={{
paddingHorizontal: 20,
width: Dimensions.get("window").width,
backgroundColor: "white",
}}
>
<Divider />
<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,
},
]}
>
2024-04-12 15:20:08 +02:00
{habitsTracker.habitsHistory[frequency]
.filter((habitItem) => {
return (
(habitItem.habit.endDate != null &&
habitItem.habit.endDate >= selectedDate) ||
2024-04-12 15:20:08 +02:00
habitItem.habit.endDate == null
)
})
.map((item) => {
return (
<HabitCard
habitHistory={item}
selectedDate={selectedDate}
key={item.habit.id + selectedDate.toISOString()}
confettiRef={confettiRef}
/>
)
})}
2024-04-11 23:03:45 +02:00
</List.Accordion>
)
})}
</List.Section>
</ScrollView>
</>
)
}