2024-04-05 15:31:41 +02:00
|
|
|
import { Redirect, useLocalSearchParams } from "expo-router"
|
2024-03-24 23:41:23 +01:00
|
|
|
import { Text } from "react-native-paper"
|
|
|
|
import { SafeAreaView } from "react-native-safe-area-context"
|
|
|
|
|
2024-04-05 15:31:41 +02:00
|
|
|
import { useHabitsTracker } from "@/presentation/react/contexts/HabitsTracker"
|
2024-04-11 12:31:45 +02:00
|
|
|
import { HabitEditForm } from "@/presentation/react/components/HabitEditForm/HabitEditForm"
|
|
|
|
import { useAuthentication } from "@/presentation/react/contexts/Authentication"
|
2024-04-05 15:31:41 +02:00
|
|
|
|
2024-03-24 23:41:23 +01:00
|
|
|
const HabitPage: React.FC = () => {
|
|
|
|
const { habitId } = useLocalSearchParams()
|
2024-04-05 15:31:41 +02:00
|
|
|
const { habitsTracker } = useHabitsTracker()
|
2024-04-11 12:31:45 +02:00
|
|
|
const { user } = useAuthentication()
|
|
|
|
|
|
|
|
if (user === null) {
|
|
|
|
return null
|
|
|
|
}
|
2024-03-24 23:41:23 +01:00
|
|
|
|
2024-04-05 15:31:41 +02:00
|
|
|
const habitHistory = habitsTracker.getHabitHistoryById(habitId as string)
|
|
|
|
if (habitHistory == null) {
|
|
|
|
return <Redirect href="/application/habits/" />
|
|
|
|
}
|
2024-04-08 23:21:36 +02:00
|
|
|
|
2024-03-24 23:41:23 +01:00
|
|
|
return (
|
|
|
|
<SafeAreaView
|
|
|
|
style={[
|
|
|
|
{
|
|
|
|
flex: 1,
|
|
|
|
alignItems: "center",
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
>
|
2024-04-05 15:31:41 +02:00
|
|
|
<Text>
|
|
|
|
Habit Page {habitId} {habitHistory.habit.name}
|
|
|
|
</Text>
|
2024-04-11 12:31:45 +02:00
|
|
|
<HabitEditForm user={user} habit={habitHistory.habit} />
|
2024-03-24 23:41:23 +01:00
|
|
|
</SafeAreaView>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default HabitPage
|