import type { FC } from 'react' import { memo, useCallback, useEffect, useState } from 'react' import Avatar from '@/app/components/base/avatar' import { useAppContext } from '@/context/app-context' import { MentionInput } from './mention-input' import cn from '@/utils/classnames' type CommentInputProps = { position: { x: number; y: number } onSubmit: (content: string, mentionedUserIds: string[]) => void onCancel: () => void } export const CommentInput: FC = memo(({ position, onSubmit, onCancel }) => { const [content, setContent] = useState('') const { userProfile } = useAppContext() useEffect(() => { const handleGlobalKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') { e.preventDefault() e.stopPropagation() onCancel() } } document.addEventListener('keydown', handleGlobalKeyDown, true) return () => { document.removeEventListener('keydown', handleGlobalKeyDown, true) } }, [onCancel]) const handleMentionSubmit = useCallback((content: string, mentionedUserIds: string[]) => { onSubmit(content, mentionedUserIds) setContent('') }, [onSubmit]) return (
) }) CommentInput.displayName = 'CommentInput'