-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
60 lines (51 loc) · 1.51 KB
/
App.js
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
import React, { useState, useEffect } from "react";
import { View } from "react-native";
import * as Font from "expo-font";
import Navigator from "./Navigation";
import { ApolloClient } from "apollo-client";
import { ApolloProvider } from "@apollo/react-hooks";
import { HttpLink } from "apollo-link-http";
import { concat } from "apollo-link";
import { setContext } from 'apollo-link-context';
import { InMemoryCache } from "apollo-cache-inmemory";
import AsyncStorage from "@react-native-community/async-storage";
const cache = new InMemoryCache();
const httpLink = new HttpLink({
uri: "https://hospital-management-jessam.herokuapp.com/graphql",
});
const authMiddleware = setContext(async (req, { headers }) => {
let user = await AsyncStorage.getItem('user');
user = JSON.parse(user);
return {
headers: {
Authorization: user.token
}
}
})
const client = new ApolloClient({
cache,
link: concat(authMiddleware, httpLink),
});
const App = () => {
const [loaded, setLoaded] = useState({ fontLoaded: false });
useEffect(() => {
const loadFont = async () => {
await Font.loadAsync({
"raleway-regular": require("./assets/fonts/Raleway-Regular.ttf"),
"bold-raleway": require("./assets/fonts/Raleway-Bold.ttf"),
}).then(() => {
setLoaded({ fontLoaded: true });
});
};
loadFont();
}, []);
if (!loaded.fontLoaded) {
return <View />;
}
return (
<ApolloProvider client={client}>
<Navigator />
</ApolloProvider>
);
};
export default App;