1
1
mirror of https://github.com/theoludwig/p61-project.git synced 2024-07-17 07:00:12 +02:00

feat: started work on the edit page. added methods to habittracker

This commit is contained in:
Maxime Rumpler 2024-04-05 15:31:41 +02:00
parent e367c09b34
commit fa9431b788
2 changed files with 25 additions and 2 deletions

View File

@ -1,10 +1,17 @@
import { useLocalSearchParams } from "expo-router"
import { Redirect, useLocalSearchParams } from "expo-router"
import { Text } from "react-native-paper"
import { SafeAreaView } from "react-native-safe-area-context"
import { useHabitsTracker } from "@/presentation/react/contexts/HabitsTracker"
const HabitPage: React.FC = () => {
const { habitId } = useLocalSearchParams()
const { habitsTracker } = useHabitsTracker()
const habitHistory = habitsTracker.getHabitHistoryById(habitId as string)
if (habitHistory == null) {
return <Redirect href="/application/habits/" />
}
return (
<SafeAreaView
style={[
@ -14,7 +21,9 @@ const HabitPage: React.FC = () => {
},
]}
>
<Text>Habit Page {habitId}</Text>
<Text>
Habit Page {habitId} {habitHistory.habit.name}
</Text>
</SafeAreaView>
)
}

View File

@ -34,4 +34,18 @@ export class HabitsTracker implements HabitsTrackerData {
}),
)
}
public getAllHabitsHistory(): HabitHistory[] {
return [
...this.habitsHistory.daily,
...this.habitsHistory.weekly,
...this.habitsHistory.monthly,
]
}
public getHabitHistoryById(id: Habit["id"]): HabitHistory | undefined {
return this.getAllHabitsHistory().find((habitHistory) => {
return habitHistory.habit.id === id
})
}
}