This repository has been archived on 2024-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
p61-project/app/application/habits/index.tsx

72 lines
2.0 KiB
TypeScript

import { SafeAreaView } from "react-native-safe-area-context"
import { ActivityIndicator, Button, Text } from "react-native-paper"
import { HabitsMainPage } from "@/presentation/react-native/components/HabitsMainPage/HabitsMainPage"
import { useHabitsTracker } from "@/presentation/react/contexts/HabitsTracker"
import { useAuthentication } from "@/presentation/react/contexts/Authentication"
const HabitsPage: React.FC = () => {
const { habitsTracker, retrieveHabitsTracker, habitsTrackerPresenter } =
useHabitsTracker()
const { user } = useAuthentication()
return (
<SafeAreaView
style={[
{
flex: 1,
backgroundColor: "white",
alignItems: "center",
justifyContent:
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
later.
</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>
</>
) : (
<HabitsMainPage habitsTracker={habitsTracker} />
)}
</SafeAreaView>
)
}
export default HabitsPage