-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shared context for assistant selector
Allow for selection of assistant from assistant panel
- Loading branch information
1 parent
a787422
commit b150481
Showing
8 changed files
with
88 additions
and
50 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { CannedChatbot } from '@app/types/CannedChatbot'; | ||
import * as React from 'react'; | ||
|
||
interface AppDataContextType { | ||
flyoutMenuSelectedChatbot?: CannedChatbot; | ||
updateFlyoutMenuSelectedChatbot: (newChatbot: CannedChatbot) => void; | ||
} | ||
|
||
const AppDataContext = React.createContext<AppDataContextType | undefined>(undefined); | ||
|
||
export const AppDataProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { | ||
const [flyoutMenuSelectedChatbot, setFlyoutMenuSelectedChatbot] = React.useState<CannedChatbot>(); | ||
|
||
const updateFlyoutMenuSelectedChatbot = (newChatbot: CannedChatbot) => | ||
setFlyoutMenuSelectedChatbot((prev) => ({ ...prev, ...newChatbot })); | ||
|
||
return ( | ||
<AppDataContext.Provider value={{ flyoutMenuSelectedChatbot, updateFlyoutMenuSelectedChatbot }}> | ||
{children} | ||
</AppDataContext.Provider> | ||
); | ||
}; | ||
|
||
export const useAppData = () => { | ||
const context = React.useContext(AppDataContext); | ||
if (!context) { | ||
throw new Error('useAppData must be used within a AppDataProvider'); | ||
} | ||
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
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
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