diff --git a/package.json b/package.json index 3440f5e..e876ec5 100644 --- a/package.json +++ b/package.json @@ -95,6 +95,7 @@ "clsx": "^1.2.1", "date-fns": "^2.30.0", "lucide-react": "^0.263.0", + "nanoid": "^4.0.2", "peerjs": "^1.4.7", "react-markdown": "^8.0.7", "react-nice-avatar": "^1.4.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e51007c..8ae463b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -38,6 +38,9 @@ dependencies: lucide-react: specifier: ^0.263.0 version: 0.263.0(react@18.2.0) + nanoid: + specifier: ^4.0.2 + version: 4.0.2 peerjs: specifier: ^1.4.7 version: 1.4.7 @@ -5717,6 +5720,12 @@ packages: engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true + /nanoid@4.0.2: + resolution: {integrity: sha512-7ZtY5KTCNheRGfEFxnedV5zFiORN1+Y1N6zvPTnHQd8ENUvfaDBeuJDZb2bN/oXwXxu3qkTXDzy57W5vAmDTBw==} + engines: {node: ^14 || ^16 || >=18} + hasBin: true + dev: false + /natural-compare-lite@1.4.0: resolution: {integrity: sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==} dev: true diff --git a/src/components/MessageInput.tsx b/src/components/MessageInput.tsx index d8e9fc9..3c3141c 100644 --- a/src/components/MessageInput.tsx +++ b/src/components/MessageInput.tsx @@ -1,57 +1,52 @@ import { type FC, type ChangeEvent, type KeyboardEvent } from 'react' -import { useRemeshDomain, useRemeshQuery, useRemeshSend } from 'remesh-react' + import { Textarea } from '@/components/ui/Textarea' import { Markdown } from '@/components/ui/Markdown' import { cn } from '@/utils' -import MessageInputDomain from '@/domain/MessageInput' -import { MESSAGE_MAX_LENGTH } from '@/constants' export interface MessageInputProps { + value?: string className?: string maxLength?: number + preview?: boolean + onInput?: (value: string) => void + onEnter?: (value: string) => void } -const MessageInput: FC = ({ className }) => { - const send = useRemeshSend() - const messageInputDomain = useRemeshDomain(MessageInputDomain()) - - const message = useRemeshQuery(messageInputDomain.query.ValueQuery()) - const isPreview = useRemeshQuery(messageInputDomain.query.PreviewQuery()) - - const handleInput = (e: ChangeEvent) => { - send(messageInputDomain.command.InputCommand(e.target.value)) - } - - const handleKeyDown = (e: KeyboardEvent) => { +const MessageInput: FC = ({ value = '', className, maxLength = 500, onInput, onEnter, preview }) => { + const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Enter' && !(e.shiftKey || e.ctrlKey || e.altKey || e.metaKey)) { e.preventDefault() - send(messageInputDomain.command.EnterCommand()) + onEnter?.(value) } } + const handleInput = (e: ChangeEvent) => { + onInput?.(e.target.value) + } return (
- {isPreview ? ( - {message} + {preview ? ( + {value} ) : ( // Hack: Auto-Growing Textarea