quivr/frontend/lib/components/AddBrainModal/brainCreation-provider.tsx
Antoine Dewez 6383918f7b
feat(frontend): new brain creation modal (#2192)
# 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):
2024-02-14 16:37:33 -08:00

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;
};