/
githubmirror
/
Open-Assistant
Обзор
Документация
Войти
/
githubmirror
/
Open-Assistant
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
website/src/components/Chat/ChatContext.tsx
33 строки
1 KB
notmd
Chat config and plugin UI/UX rework (#3050)
07 май 2023, 18:57
Не верифицирован
07 май 2023, 18:57
220bc11
Код
Авторство
О чём код?
import { useDisclosure } from "@chakra-ui/react"; import { createContext, ReactNode, useContext, useMemo } from "react"; export type ChatStateContext = { isConfigDrawerOpen: boolean; }; export type ChatActionContext = { openConfigDrawer: () => void; closeConfigDrawer: () => void; }; const chatStateContext = createContext<ChatStateContext>({} as ChatStateContext); const chatActionContext = createContext<ChatActionContext>({} as ChatActionContext); export const useChatState = () => useContext(chatStateContext); export const useChatActions = () => useContext(chatActionContext); export const ChatProvider = ({ children }: { children: ReactNode }) => { const { isOpen, onOpen, onClose } = useDisclosure(); const state: ChatStateContext = useMemo(() => ({ isConfigDrawerOpen: isOpen }), [isOpen]); const action: ChatActionContext = useMemo( () => ({ openConfigDrawer: onOpen, closeConfigDrawer: onClose }), [onClose, onOpen] ); return ( <chatStateContext.Provider value={state}> <chatActionContext.Provider value={action}>{children}</chatActionContext.Provider> </chatStateContext.Provider> ); };