Merge branch 'feat/habit-edit-page' into develop

This commit is contained in:
Théo LUDWIG 2024-04-05 15:38:35 +02:00
commit 2ab83dfc89
Signed by: theoludwig
GPG Key ID: ADFE5A563D718F3B
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
})
}
}