-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create profile integration with API
- Loading branch information
Showing
8 changed files
with
195 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
import axios from 'axios' | ||
|
||
const bloodLineApi = axios.create({ | ||
baseURL: 'http://192.168.1.7:4561/api', | ||
baseURL: 'http://192.168.1.5:4561/api', | ||
headers: { | ||
"Content-Type": "application/json", | ||
"Access-Control-Allow-Headers": "Authorization", | ||
"Accept": "*/*", | ||
} | ||
}) | ||
|
||
export default bloodLineApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { createContext, useCallback, useContext, useEffect, useState } from "react"; | ||
import AsyncStorage from "@react-native-async-storage/async-storage"; | ||
import * as SplashScreen from 'expo-splash-screen'; | ||
import { AuthContext } from "../AuthContext"; | ||
|
||
SplashScreen.preventAutoHideAsync(); | ||
|
||
const DataContext = createContext(); | ||
const storeData = async (key, data) => { | ||
try { | ||
await AsyncStorage.setItem(key, JSON.stringify(data)); | ||
} catch (err) { | ||
console.log(err); | ||
} | ||
}; | ||
|
||
|
||
const DataContextProvider = ({ children }) => { | ||
|
||
const { isAuth } = useContext(AuthContext) | ||
|
||
const [appIsReady, setAppIsReady] = useState(false) | ||
const [profile, setProfile] = useState({}); | ||
|
||
useEffect(() => { | ||
const firstLoad = async () => { | ||
try { | ||
setAppIsReady(false) | ||
const profile = await AsyncStorage.getItem("@profile"); | ||
setProfile(JSON.parse(profile)); | ||
} catch (err) { | ||
console.log(err); | ||
} finally { | ||
setAppIsReady(true); | ||
if (!isAuth) { | ||
setProfile({}) | ||
} | ||
} | ||
}; | ||
|
||
firstLoad(); | ||
}, [isAuth]); | ||
|
||
const onLayoutRootView = useCallback(async () => { | ||
if (appIsReady) { | ||
await SplashScreen.hideAsync(); | ||
} | ||
}, [appIsReady]); | ||
|
||
|
||
const storeProfile = (resData) => { | ||
storeData("@profile", resData.data); | ||
setProfile(resData.data); | ||
}; | ||
|
||
|
||
if (!appIsReady) { | ||
return null | ||
} | ||
|
||
return ( | ||
<DataContext.Provider | ||
onLayout={onLayoutRootView} | ||
value={{ profile, storeProfile }} | ||
> | ||
{children} | ||
</DataContext.Provider> | ||
); | ||
}; | ||
|
||
export { DataContext, DataContextProvider }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.