2024-03-24 23:41:23 +01:00
|
|
|
import FontAwesome6 from "@expo/vector-icons/FontAwesome6"
|
|
|
|
import { useRouter } from "expo-router"
|
2024-04-08 23:21:36 +02:00
|
|
|
import { View } from "react-native"
|
2024-04-11 12:32:09 +02:00
|
|
|
import { List, Text, Checkbox } from "react-native-paper"
|
|
|
|
import { useState } from "react"
|
2024-03-24 23:41:23 +01:00
|
|
|
|
2024-04-08 23:21:36 +02:00
|
|
|
import type { GoalProgress } from "@/domain/entities/Goal"
|
|
|
|
import type { Habit } from "@/domain/entities/Habit"
|
|
|
|
import { getColorRGBAFromHex } from "@/utils/colors"
|
2024-03-24 23:41:23 +01:00
|
|
|
|
2024-04-05 13:50:51 +02:00
|
|
|
export interface HabitCardProps {
|
2024-04-08 23:21:36 +02:00
|
|
|
habit: Habit
|
|
|
|
goalProgress: GoalProgress
|
2024-03-24 23:41:23 +01:00
|
|
|
}
|
|
|
|
|
2024-04-05 13:50:51 +02:00
|
|
|
export const HabitCard: React.FC<HabitCardProps> = (props) => {
|
2024-04-08 23:21:36 +02:00
|
|
|
const { habit, goalProgress } = props
|
2024-03-24 23:41:23 +01:00
|
|
|
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
|
|
const habitColor = getColorRGBAFromHex({
|
|
|
|
hexColor: habit.color,
|
|
|
|
opacity: 0.4,
|
|
|
|
})
|
|
|
|
|
2024-04-11 12:32:09 +02:00
|
|
|
const [checked, setChecked] = useState(goalProgress.isCompleted())
|
|
|
|
|
2024-03-24 23:41:23 +01:00
|
|
|
return (
|
|
|
|
<List.Item
|
|
|
|
onPress={() => {
|
|
|
|
router.push({
|
|
|
|
pathname: "/application/habits/[habitId]/",
|
|
|
|
params: {
|
|
|
|
habitId: habit.id,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
title={habit.name}
|
|
|
|
style={[
|
|
|
|
{
|
|
|
|
paddingVertical: 20,
|
|
|
|
paddingHorizontal: 10,
|
|
|
|
marginVertical: 10,
|
|
|
|
borderRadius: 10,
|
|
|
|
backgroundColor: habitColor,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
contentStyle={[
|
|
|
|
{
|
|
|
|
paddingLeft: 12,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
titleStyle={[
|
|
|
|
{
|
|
|
|
fontSize: 18,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
left={() => {
|
|
|
|
return (
|
|
|
|
<FontAwesome6
|
|
|
|
size={24}
|
|
|
|
name={habit.icon}
|
|
|
|
style={[
|
|
|
|
{
|
|
|
|
width: 30,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}}
|
2024-04-08 23:21:36 +02:00
|
|
|
right={() => {
|
|
|
|
if (goalProgress.isNumeric()) {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Text>
|
|
|
|
{goalProgress.progress.toLocaleString()} /{" "}
|
|
|
|
{goalProgress.goal.target.value.toLocaleString()}{" "}
|
|
|
|
{goalProgress.goal.target.unit}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View>
|
2024-04-11 12:32:09 +02:00
|
|
|
<Checkbox
|
|
|
|
status={checked ? "checked" : "unchecked"}
|
|
|
|
onPress={() => {
|
|
|
|
setChecked(!checked)
|
|
|
|
}}
|
|
|
|
/>
|
2024-04-08 23:21:36 +02:00
|
|
|
</View>
|
|
|
|
)
|
|
|
|
}}
|
2024-03-24 23:41:23 +01:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|