From 1f6424906d7dda9db631c0cf0b329475b565c645 Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Mon, 15 Apr 2024 17:46:16 -0700 Subject: [PATCH] Get it working --- frontend/src/components/Chat.tsx | 7 +++--- frontend/src/components/MessageEditor.tsx | 6 +++--- frontend/src/components/StringEditor.tsx | 13 +----------- frontend/src/hooks/useChatMessages.ts | 26 +++++++++++------------ frontend/src/hooks/useMessageEditing.ts | 24 ++++++++++++++++++--- 5 files changed, 42 insertions(+), 34 deletions(-) diff --git a/frontend/src/components/Chat.tsx b/frontend/src/components/Chat.tsx index 46a09da0..576bdce4 100644 --- a/frontend/src/components/Chat.tsx +++ b/frontend/src/components/Chat.tsx @@ -63,14 +63,15 @@ function CommitEdits(props: { export function Chat(props: ChatProps) { const { chatId } = useParams(); - const { messages, next } = useChatMessages( + const { messages, next, refreshMessages } = useChatMessages( chatId ?? null, props.stream, props.stopStream, ); const { currentChat, assistantConfig, isLoading } = useThreadAndAssistant(); const { editing, recordEdits, commitEdits, abandonEdits } = useMessageEditing( - currentChat?.thread_id, + chatId, + refreshMessages, ); const prevMessages = usePrevious(messages); @@ -94,7 +95,7 @@ export function Chat(props: ChatProps) { editing[msg.id] ? ( abandonEdits(msg)} /> diff --git a/frontend/src/components/MessageEditor.tsx b/frontend/src/components/MessageEditor.tsx index 847f689a..6cffb285 100644 --- a/frontend/src/components/MessageEditor.tsx +++ b/frontend/src/components/MessageEditor.tsx @@ -8,7 +8,7 @@ import { PlusCircleIcon, TrashIcon, } from "@heroicons/react/24/outline"; -import { AutosizeTextarea } from "./StringEditor"; +import { StringEditor } from "./StringEditor"; import { JsonEditor } from "./JsonEditor"; // TODO adapt (and use) or remove @@ -99,7 +99,7 @@ function Function(props: { )} >
- { @@ -184,7 +184,7 @@ export function MessageContentEditor(props: { return null; } return ( - props.onUpdate({ ...props.message, diff --git a/frontend/src/components/StringEditor.tsx b/frontend/src/components/StringEditor.tsx index ee0b0b89..92f0319d 100644 --- a/frontend/src/components/StringEditor.tsx +++ b/frontend/src/components/StringEditor.tsx @@ -1,20 +1,14 @@ -import { Ref } from "react"; import { cn } from "../utils/cn"; const COMMON_CLS = cn( "text-sm col-[1] row-[1] m-0 resize-none overflow-hidden whitespace-pre-wrap break-words bg-transparent px-2 py-1 rounded shadow-none", ); -export function AutosizeTextarea(props: { - id?: string; - inputRef?: Ref; +export function StringEditor(props: { value?: string | null | undefined; placeholder?: string; className?: string; onChange?: (e: string) => void; - onFocus?: () => void; - onBlur?: () => void; - onKeyDown?: (e: React.KeyboardEvent) => void; autoFocus?: boolean; readOnly?: boolean; cursorPointer?: boolean; @@ -29,8 +23,6 @@ export function AutosizeTextarea(props: { } >