import React, { PropsWithChildren, useContext } from 'react'; import type { SuggestionDataItem } from 'react-mentions'; import { useShallowObject } from 'tailchat-shared'; /** * Input Actions */ export interface ChatInputActionContextProps { message: string; setMessage: (msg: string) => void; sendMsg: (message: string) => void; appendMsg: (message: string) => void; } export const ChatInputActionContext = React.createContext( {} as ChatInputActionContextProps ); ChatInputActionContext.displayName = 'ChatInputActionContext'; export function useChatInputActionContext() { return useContext(ChatInputActionContext); } /** * Input Mentions */ interface ChatInputMentionsContextProps extends PropsWithChildren { users?: SuggestionDataItem[]; panels?: SuggestionDataItem[]; placeholder?: string; disabled?: boolean; } const ChatInputMentionsContext = React.createContext(null); ChatInputMentionsContext.displayName = 'ChatInputMentionsContext'; export const ChatInputMentionsContextProvider: React.FC = React.memo((props) => { return ( {props.children} ); }); ChatInputMentionsContextProvider.displayName = 'ChatInputMentionsContextProvider'; export function useChatInputMentionsContext(): ChatInputMentionsContextProps { const context = useContext(ChatInputMentionsContext); return { users: context?.users ?? [], panels: context?.panels ?? [], placeholder: context?.placeholder, disabled: context?.disabled, }; }