|
@ -15,46 +15,50 @@ import AuthNavigator from "./app/navigation/AuthNavigator"; |
|
|
import { AuthContext } from "./app/auth/context"; |
|
|
import { AuthContext } from "./app/auth/context"; |
|
|
import authStorage from "./app/auth/storage"; |
|
|
import authStorage from "./app/auth/storage"; |
|
|
import MapDataProvider from "./app/context/MapDataContext"; |
|
|
import MapDataProvider from "./app/context/MapDataContext"; |
|
|
import {getLocation} from "./app/hooks/useLocation"; |
|
|
|
|
|
|
|
|
import { getLocation } from "./app/hooks/useLocation"; |
|
|
import { useFiltering } from "./app/hooks/useFiltering"; |
|
|
import { useFiltering } from "./app/hooks/useFiltering"; |
|
|
|
|
|
import NoInternetConnectionScreen from "./app/screens/NoInternetConnectionScreen"; |
|
|
|
|
|
import NetInfo, { useNetInfo } from "@react-native-community/netinfo"; |
|
|
|
|
|
|
|
|
export default function App() { |
|
|
export default function App() { |
|
|
const [user, setUser] = useState(); |
|
|
const [user, setUser] = useState(); |
|
|
const [isReady, setIsReady] = useState(); |
|
|
const [isReady, setIsReady] = useState(); |
|
|
|
|
|
|
|
|
|
|
|
const netInfo = useNetInfo(); |
|
|
|
|
|
|
|
|
const restoreUser = async () => { |
|
|
const restoreUser = async () => { |
|
|
const user = await authStorage.getUser(); |
|
|
const user = await authStorage.getUser(); |
|
|
global.location ={"lat":-10.0173780726763, |
|
|
|
|
|
"long": -67.8170775249999} // await getLocation();
|
|
|
|
|
|
|
|
|
global.location = { lat: -23.623, long: -46.5637 }; // await getLocation();
|
|
|
if (user) setUser(user); |
|
|
if (user) setUser(user); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
if (!isReady) |
|
|
|
|
|
|
|
|
if (!isReady && netInfo.isInternetReachable) { |
|
|
return ( |
|
|
return ( |
|
|
<AppLoading startAsync={restoreUser} onFinish={() => setIsReady(true)} /> |
|
|
<AppLoading startAsync={restoreUser} onFinish={() => setIsReady(true)} /> |
|
|
); |
|
|
); |
|
|
|
|
|
} else if (netInfo.isInternetReachable) { |
|
|
|
|
|
global.userDataBase = openDatabase(); |
|
|
|
|
|
initDatabase(global.userDataBase); |
|
|
|
|
|
global.formsSockets = useFiltering(global.location); |
|
|
|
|
|
|
|
|
global.userDataBase = openDatabase(); |
|
|
|
|
|
initDatabase(global.userDataBase); |
|
|
|
|
|
global.formsSockets = useFiltering(global.location); |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
<AuthContext.Provider |
|
|
|
|
|
value={{ |
|
|
|
|
|
user, |
|
|
|
|
|
setUser, |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
<CurrentLocationProvider> |
|
|
|
|
|
<EventLocationProvider> |
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
|
<AuthContext.Provider |
|
|
|
|
|
value={{ |
|
|
|
|
|
user, |
|
|
|
|
|
setUser, |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
<CurrentLocationProvider> |
|
|
|
|
|
<EventLocationProvider> |
|
|
<MapDataProvider> |
|
|
<MapDataProvider> |
|
|
<NavigationContainer theme={navigationTheme}> |
|
|
<NavigationContainer theme={navigationTheme}> |
|
|
{user ? <AppNavigator /> : <AuthNavigator />} |
|
|
{user ? <AppNavigator /> : <AuthNavigator />} |
|
|
<FlashMessage position="top" /> |
|
|
<FlashMessage position="top" /> |
|
|
</NavigationContainer> |
|
|
</NavigationContainer> |
|
|
</MapDataProvider> |
|
|
</MapDataProvider> |
|
|
</EventLocationProvider> |
|
|
|
|
|
</CurrentLocationProvider> |
|
|
|
|
|
</AuthContext.Provider> |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
</EventLocationProvider> |
|
|
|
|
|
</CurrentLocationProvider> |
|
|
|
|
|
</AuthContext.Provider> |
|
|
|
|
|
); |
|
|
|
|
|
} else return <NoInternetConnectionScreen />; |
|
|
} |
|
|
} |