fix: retrieve habits error case
This commit is contained in:
parent
7543a4f820
commit
eea32ec256
@ -1,11 +1,15 @@
|
|||||||
import { SafeAreaView } from "react-native-safe-area-context"
|
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 { HabitsHistory } from "@/presentation/react/components/HabitsHistory/HabitsHistory"
|
||||||
import { useHabitsTracker } from "@/presentation/react/contexts/HabitsTracker"
|
import { useHabitsTracker } from "@/presentation/react/contexts/HabitsTracker"
|
||||||
|
import { useAuthentication } from "@/presentation/react/contexts/Authentication"
|
||||||
|
|
||||||
const HabitsPage: React.FC = () => {
|
const HabitsPage: React.FC = () => {
|
||||||
const { habitsTracker, retrieveHabitsTracker } = useHabitsTracker()
|
const { habitsTracker, retrieveHabitsTracker, habitsTrackerPresenter } =
|
||||||
|
useHabitsTracker()
|
||||||
|
|
||||||
|
const { user } = useAuthentication()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SafeAreaView
|
<SafeAreaView
|
||||||
@ -14,12 +18,47 @@ const HabitsPage: React.FC = () => {
|
|||||||
flex: 1,
|
flex: 1,
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
justifyContent:
|
justifyContent:
|
||||||
retrieveHabitsTracker.state === "loading" ? "center" : "flex-start",
|
retrieveHabitsTracker.state === "loading" ||
|
||||||
|
retrieveHabitsTracker.state === "error"
|
||||||
|
? "center"
|
||||||
|
: "flex-start",
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
>
|
>
|
||||||
{retrieveHabitsTracker.state === "loading" ? (
|
{retrieveHabitsTracker.state === "loading" ? (
|
||||||
<ActivityIndicator animating size="large" />
|
<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} />
|
<HabitsHistory habitsTracker={habitsTracker} />
|
||||||
)}
|
)}
|
||||||
|
Reference in New Issue
Block a user