forked from Panchalparth471/SAP-HACKATHON
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
113 lines (100 loc) · 4.13 KB
/
App.js
File metadata and controls
113 lines (100 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import React, { useState, useEffect } from "react";
import { NavigationContainer } from "@react-navigation/native";
import { createStackNavigator } from "@react-navigation/stack";
import AsyncStorage from "@react-native-async-storage/async-storage";
import { ActivityIndicator, View, Alert } from "react-native";
import Constants from "expo-constants";
import AddScheuleScreen from "./screens/AddScheduleScreen";
import * as Notifications from "expo-notifications";
// Import Screens
import HomeScreen from "./screens/HomeScreen";
import PrescriptionScreen from "./screens/PrescriptionScreen";
import ProfileScreen from "./screens/ProfileScreen";
import ChatBotScreen from "./screens/ChatBotScreen";
import Scan from "./screens/Scan";
import LoginScreen from "./screens/LoginScreen";
import SignupScreen from "./screens/SignupScreen";
import ForgotPasswordScreen from "./screens/ForgotPasswordScreen";
import ResetPasswordScreen from "./screens/ResetPasswordScreen";
import SearchDoctor from "./screens/SearchDoctor";
import UploadScreen from "./screens/UploadScreen";
// Import Fonts
import { useFonts, Poppins_400Regular, Poppins_700Bold } from "@expo-google-fonts/poppins";
const Stack = createStackNavigator();
export default function App() {
const [initialRoute, setInitialRoute] = useState(null);
const [isCheckingAuth, setIsCheckingAuth] = useState(true);
const [fontsLoaded] = useFonts({
Poppins_400Regular,
Poppins_700Bold,
});
// Check user session (auth)
useEffect(() => {
const checkUserSession = async () => {
try {
const storedToken = await AsyncStorage.getItem("auth_token");
if (storedToken) {
setInitialRoute("Home");
} else {
setInitialRoute("signup");
}
} catch (error) {
console.error("Error checking user session:", error);
} finally {
setIsCheckingAuth(false);
}
};
checkUserSession();
}, []);
// Register for push notifications
useEffect(() => {
async function registerForPushNotificationsAsync() {
if (!Constants.isDevice) {
Alert.alert("Push notifications only work on a physical device");
return;
}
const { status: existingStatus } = await Notifications.getPermissionsAsync();
let finalStatus = existingStatus;
if (existingStatus !== "granted") {
const { status } = await Notifications.requestPermissionsAsync();
finalStatus = status;
}
if (finalStatus !== "granted") {
Alert.alert("Failed to get push token for push notifications!");
return;
}
const tokenData = await Notifications.getExpoPushTokenAsync();
const expoPushToken = tokenData.data;
console.log("Expo Push Token:", expoPushToken);
// Optionally, store the token in AsyncStorage or send it to your backend
await AsyncStorage.setItem("expo_push_token", expoPushToken);
console.log(expoPushToken)
}
registerForPushNotificationsAsync();
}, []);
if (!fontsLoaded || isCheckingAuth) {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<ActivityIndicator size="large" color="#0E64D2" />
</View>
);
}
return (
<NavigationContainer>
<Stack.Navigator initialRouteName={initialRoute} screenOptions={{ headerShown: false }}>
<Stack.Screen name="Home" component={HomeScreen} />
<Stack.Screen name="Profile" component={ProfileScreen} />
<Stack.Screen name="addMedicine" component={AddScheuleScreen}/>
<Stack.Screen name="prescriptionDetails" component={PrescriptionScreen} />
<Stack.Screen name="search" component={SearchDoctor} />
<Stack.Screen name="chatBot" component={ChatBotScreen} />
<Stack.Screen name="uploadReports" component={UploadScreen}/>
<Stack.Screen name="scan" component={Scan} />
<Stack.Screen name="login" component={LoginScreen} />
<Stack.Screen name="signup" component={SignupScreen} />
<Stack.Screen name="forgot" component={ForgotPasswordScreen} />
<Stack.Screen name="reset" component={ResetPasswordScreen} />
</Stack.Navigator>
</NavigationContainer>
);
}