-
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.
ref #9
- Loading branch information
Showing
10 changed files
with
172 additions
and
139 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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
"orgid", | ||
"prebuild", | ||
"tanstack", | ||
"utahid", | ||
"venv", | ||
"VITE" | ||
], | ||
|
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.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
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,39 @@ | ||
import { useFirebaseApp } from '@ugrc/utah-design-system'; | ||
import { connectFunctionsEmulator, Functions, getFunctions } from 'firebase/functions'; | ||
import { createContext, type ReactNode, useContext } from 'react'; | ||
|
||
type FunctionsContextValue = { | ||
functions: Functions; | ||
}; | ||
|
||
type FunctionsProviderProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
const FunctionsContext = createContext<FunctionsContextValue | null>(null); | ||
|
||
export const FirebaseFunctionsProvider = (props: FunctionsProviderProps) => { | ||
const app = useFirebaseApp(); | ||
const sdk = getFunctions(app); | ||
|
||
if (import.meta.env.DEV) { | ||
console.log('Connecting to Firebase Functions emulator'); | ||
connectFunctionsEmulator(sdk, 'localhost', 5001); | ||
} | ||
|
||
if (!app) { | ||
throw new Error('You cannot use the FirebaseFunctionsProvider outside of a <FirebaseAppProvider />'); | ||
} | ||
|
||
return <FunctionsContext.Provider value={{ functions: sdk }} {...props} />; | ||
}; | ||
|
||
export const useFirebaseFunctions = () => { | ||
const value = useContext(FunctionsContext); | ||
|
||
if (value === null) { | ||
throw new Error('useFirebaseFunctions must be used within a FirebaseFunctionsProvider'); | ||
} | ||
|
||
return value; | ||
}; |
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,39 @@ | ||
import { useFirebaseApp } from '@ugrc/utah-design-system'; | ||
import { connectFirestoreEmulator, Firestore, getFirestore } from 'firebase/firestore'; | ||
import { createContext, type ReactNode, useContext } from 'react'; | ||
|
||
type StoreContextValue = { | ||
firestore: Firestore; | ||
}; | ||
|
||
type FirestoreProviderProps = { | ||
children: ReactNode; | ||
}; | ||
|
||
const FirestoreContext = createContext<StoreContextValue | null>(null); | ||
|
||
export const FirestoreProvider = (props: FirestoreProviderProps) => { | ||
const app = useFirebaseApp(); | ||
const sdk = getFirestore(app); | ||
|
||
if (import.meta.env.DEV) { | ||
console.log('Connecting to Firestore emulator'); | ||
connectFirestoreEmulator(sdk, 'localhost', 8080); | ||
} | ||
|
||
if (!app) { | ||
throw new Error('You cannot use the FirestoreProvider outside of a <FirebaseAppProvider />'); | ||
} | ||
|
||
return <FirestoreContext.Provider value={{ firestore: sdk }} {...props} />; | ||
}; | ||
|
||
export const useFirestore = () => { | ||
const value = useContext(FirestoreContext); | ||
|
||
if (value === null) { | ||
throw new Error('useFirestore must be used within a FirestoreProvider'); | ||
} | ||
|
||
return value; | ||
}; |
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