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

fix: retrieve habits error case

This commit is contained in:
Xc165543337 2024-04-04 11:01:49 +02:00
parent 7543a4f820
commit eea32ec256

View File

@ -1,11 +1,15 @@
import { SafeAreaView } from "react-native-safe-area-context"
import { ActivityIndicator } from "react-native-paper"
import { ActivityIndicator, Button, Text } from "react-native-paper"
import { HabitsHistory } from "@/presentation/react/components/HabitsHistory/HabitsHistory"
import { useHabitsTracker } from "@/presentation/react/contexts/HabitsTracker"
import { useAuthentication } from "@/presentation/react/contexts/Authentication"
const HabitsPage: React.FC = () => {
const { habitsTracker, retrieveHabitsTracker } = useHabitsTracker()
const { habitsTracker, retrieveHabitsTracker, habitsTrackerPresenter } =
useHabitsTracker()
const { user } = useAuthentication()
return (
<SafeAreaView
@ -14,12 +18,47 @@ const HabitsPage: React.FC = () => {
flex: 1,
alignItems: "center",
justifyContent:
retrieveHabitsTracker.state === "loading" ? "center" : "flex-start",
retrieveHabitsTracker.state === "loading" ||
retrieveHabitsTracker.state === "error"
? "center"
: "flex-start",
},
]}
>
{retrieveHabitsTracker.state === "loading" ? (
<ActivityIndicator animating size="large" />
) : retrieveHabitsTracker.state === "error" ? (
<>
<Text variant="titleLarge">
Error: There was an issue while retrieving habits, please try again.
</Text>
<Button
mode="contained"
style={{
marginTop: 16,
width: 150,
height: 40,
}}
onPress={async () => {
if (user === null) {
return
}
await habitsTrackerPresenter.retrieveHabitsTracker({
userId: user.id,
})
}}
>
<Text
style={{
color: "white",
fontWeight: "bold",
fontSize: 16,
}}
>
Retry
</Text>
</Button>
</>
) : (
<HabitsHistory habitsTracker={habitsTracker} />
)}