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:
parent
e367c09b34
commit
fa9431b788
@ -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>
|
||||
)
|
||||
}
|
||||
|
@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user