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

71 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-03-15 23:24:08 +01:00
import { SafeAreaView } from "react-native-safe-area-context"
2024-04-04 11:01:49 +02:00
import { ActivityIndicator, Button, Text } from "react-native-paper"
2024-03-15 23:24:08 +01:00
2024-03-24 23:41:23 +01:00
import { HabitsHistory } from "@/presentation/react/components/HabitsHistory/HabitsHistory"
2024-03-16 00:36:44 +01:00
import { useHabitsTracker } from "@/presentation/react/contexts/HabitsTracker"
2024-04-04 11:01:49 +02:00
import { useAuthentication } from "@/presentation/react/contexts/Authentication"
2024-03-15 23:24:08 +01:00
const HabitsPage: React.FC = () => {
2024-04-04 11:01:49 +02:00
const { habitsTracker, retrieveHabitsTracker, habitsTrackerPresenter } =
useHabitsTracker()
const { user } = useAuthentication()
2024-03-15 23:24:08 +01:00
return (
2024-03-24 23:41:23 +01:00
<SafeAreaView
style={[
{
flex: 1,
alignItems: "center",
justifyContent:
2024-04-04 11:01:49 +02:00
retrieveHabitsTracker.state === "loading" ||
retrieveHabitsTracker.state === "error"
? "center"
: "flex-start",
2024-03-24 23:41:23 +01:00
},
]}
>
{retrieveHabitsTracker.state === "loading" ? (
<ActivityIndicator animating size="large" />
2024-04-04 11:01:49 +02:00
) : retrieveHabitsTracker.state === "error" ? (
<>
<Text variant="titleLarge">
2024-04-05 00:08:40 +02:00
Error: There was an issue while retrieving habits, please try again
later.
2024-04-04 11:01:49 +02:00
</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} />
)}
2024-03-15 23:24:08 +01:00
</SafeAreaView>
)
}
export default HabitsPage