mirror of
https://github.com/QuivrHQ/quivr.git
synced 2024-12-16 18:52:12 +03:00
6383918f7b
# Description Please include a summary of the changes and the related issue. Please also include relevant motivation and context. ## Checklist before requesting a review Please delete options that are not relevant. - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented hard-to-understand areas - [ ] I have ideally added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged ## Screenshots (if appropriate):
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { createContext, useContext, useState } from "react";
|
|
|
|
interface BrainCreationContextProps {
|
|
isBrainCreationModalOpened: boolean;
|
|
setIsBrainCreationModalOpened: React.Dispatch<React.SetStateAction<boolean>>;
|
|
creating: boolean;
|
|
setCreating: React.Dispatch<React.SetStateAction<boolean>>;
|
|
}
|
|
|
|
export const BrainCreationContext = createContext<
|
|
BrainCreationContextProps | undefined
|
|
>(undefined);
|
|
|
|
export const BrainCreationProvider = ({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode;
|
|
}): JSX.Element => {
|
|
const [isBrainCreationModalOpened, setIsBrainCreationModalOpened] =
|
|
useState<boolean>(false);
|
|
const [creating, setCreating] = useState<boolean>(false);
|
|
|
|
return (
|
|
<BrainCreationContext.Provider
|
|
value={{
|
|
isBrainCreationModalOpened,
|
|
setIsBrainCreationModalOpened,
|
|
creating,
|
|
setCreating,
|
|
}}
|
|
>
|
|
{children}
|
|
</BrainCreationContext.Provider>
|
|
);
|
|
};
|
|
|
|
export const useBrainCreationContext = (): BrainCreationContextProps => {
|
|
const context = useContext(BrainCreationContext);
|
|
if (!context) {
|
|
throw new Error(
|
|
"useBrainCreationContext must be used within a BrainCreationProvider"
|
|
);
|
|
}
|
|
|
|
return context;
|
|
};
|