-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cefb51e
commit 640851d
Showing
7 changed files
with
74 additions
and
59 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import * as React from 'react'; | ||
import { SafeAreaView } from 'react-native-safe-area-context'; | ||
import Router from './navigation/Router'; | ||
import UserContext from './contexts/userContext'; | ||
import CareWalletProvider from './contexts/CareWalletContext'; | ||
|
||
export default function App() { | ||
return ( | ||
<UserContext> | ||
<CareWalletProvider> | ||
<SafeAreaView className="flex-1"> | ||
<Router /> | ||
</SafeAreaView> | ||
</UserContext> | ||
</CareWalletProvider> | ||
); | ||
} |
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,53 @@ | ||
import React, { createContext, useContext, useEffect, useState } from 'react'; | ||
import { getAuth, onAuthStateChanged } from 'firebase/auth'; | ||
import { Group, User } from './types'; | ||
|
||
type CareWalletContextData = { | ||
user: User; | ||
group: Group; | ||
}; | ||
|
||
const CareWalletContext = createContext({} as CareWalletContextData); | ||
|
||
export default function CareWalletProvider({ children }: { children: any }) { | ||
const [user, setUser] = useState({} as User); | ||
const [group, setGroup] = useState({} as Group); | ||
const auth = getAuth(); | ||
|
||
useEffect(() => { | ||
onAuthStateChanged(auth, (user) => { | ||
const signedInUser: User = { | ||
userID: user?.uid ?? '', | ||
userEmail: user?.email ?? '' | ||
}; | ||
setUser(signedInUser); | ||
}); | ||
setGroup({ | ||
groupID: 'TEMP - REPLACE WITH ACTUAL', | ||
role: 'TEMP - REPLACE WITH ACTUAL' | ||
}); | ||
}, []); | ||
|
||
const CareWalletContextStore: CareWalletContextData = { | ||
user: user, | ||
group: group | ||
}; | ||
|
||
return ( | ||
<CareWalletContext.Provider value={CareWalletContextStore}> | ||
{children} | ||
</CareWalletContext.Provider> | ||
); | ||
} | ||
|
||
export const useCareWalletContext = (): CareWalletContextData => { | ||
const context = useContext(CareWalletContext); | ||
|
||
if (!context) { | ||
throw new Error( | ||
'useCareWalletContext must be used within a CareWalletContextProvider' | ||
); | ||
} | ||
|
||
return context; | ||
}; |
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,9 @@ | ||
export interface User { | ||
userID: string; | ||
userEmail: string; | ||
} | ||
|
||
export interface Group { | ||
groupID: string; | ||
role: string; // TODO: update to enum | ||
} |
This file was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.