-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[🐴] Integrate global event bus (#3904)
* Conditionally run global event bus * Add current convo id context, bundle providers
- Loading branch information
1 parent
37f22ca
commit 165fdb7
Showing
6 changed files
with
112 additions
and
31 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
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,38 @@ | ||
import React from 'react' | ||
|
||
const CurrentConvoIdContext = React.createContext<{ | ||
currentConvoId: string | undefined | ||
setCurrentConvoId: (convoId: string | undefined) => void | ||
}>({ | ||
currentConvoId: undefined, | ||
setCurrentConvoId: () => {}, | ||
}) | ||
|
||
export function useCurrentConvoId() { | ||
const ctx = React.useContext(CurrentConvoIdContext) | ||
if (!ctx) { | ||
throw new Error( | ||
'useCurrentConvoId must be used within a CurrentConvoIdProvider', | ||
) | ||
} | ||
return ctx | ||
} | ||
|
||
export function CurrentConvoIdProvider({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
const [currentConvoId, setCurrentConvoId] = React.useState< | ||
string | undefined | ||
>() | ||
const ctx = React.useMemo( | ||
() => ({currentConvoId, setCurrentConvoId}), | ||
[currentConvoId], | ||
) | ||
return ( | ||
<CurrentConvoIdContext.Provider value={ctx}> | ||
{children} | ||
</CurrentConvoIdContext.Provider> | ||
) | ||
} |
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