mirror of
https://github.com/theoludwig/p61-project.git
synced 2024-07-17 07:00:12 +02:00
Merge branch 'feat/habit-edit-page' into develop
This commit is contained in:
commit
2ab83dfc89
@ -1,10 +1,17 @@
|
|||||||
import { useLocalSearchParams } from "expo-router"
|
import { Redirect, useLocalSearchParams } from "expo-router"
|
||||||
import { Text } from "react-native-paper"
|
import { Text } from "react-native-paper"
|
||||||
import { SafeAreaView } from "react-native-safe-area-context"
|
import { SafeAreaView } from "react-native-safe-area-context"
|
||||||
|
|
||||||
|
import { useHabitsTracker } from "@/presentation/react/contexts/HabitsTracker"
|
||||||
|
|
||||||
const HabitPage: React.FC = () => {
|
const HabitPage: React.FC = () => {
|
||||||
const { habitId } = useLocalSearchParams()
|
const { habitId } = useLocalSearchParams()
|
||||||
|
const { habitsTracker } = useHabitsTracker()
|
||||||
|
|
||||||
|
const habitHistory = habitsTracker.getHabitHistoryById(habitId as string)
|
||||||
|
if (habitHistory == null) {
|
||||||
|
return <Redirect href="/application/habits/" />
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<SafeAreaView
|
<SafeAreaView
|
||||||
style={[
|
style={[
|
||||||
@ -14,7 +21,9 @@ const HabitPage: React.FC = () => {
|
|||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
<Text>Habit Page {habitId}</Text>
|
<Text>
|
||||||
|
Habit Page {habitId} {habitHistory.habit.name}
|
||||||
|
</Text>
|
||||||
</SafeAreaView>
|
</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