From 78c44e13b03a54d96a297d699399e232a2b1f6dc Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Sat, 16 Mar 2024 00:30:41 +0530 Subject: [PATCH] Add edit functionality to PlaygroundMessage component --- .../Common/Playground/EditMessageForm.tsx | 62 ++++++++++++ src/components/Common/Playground/Message.tsx | 20 +++- .../Option/Playground/PlaygroundChat.tsx | 11 ++- src/components/Sidepanel/Chat/body.tsx | 1 + src/hooks/useMessageOption.tsx | 98 +++++++++++++++++-- src/libs/db.ts | 16 +++ 6 files changed, 197 insertions(+), 11 deletions(-) create mode 100644 src/components/Common/Playground/EditMessageForm.tsx diff --git a/src/components/Common/Playground/EditMessageForm.tsx b/src/components/Common/Playground/EditMessageForm.tsx new file mode 100644 index 0000000..260a3cd --- /dev/null +++ b/src/components/Common/Playground/EditMessageForm.tsx @@ -0,0 +1,62 @@ +import { useForm } from "@mantine/form" +import React from "react" +import useDynamicTextareaSize from "~hooks/useDynamicTextareaSize" + +type Props = { + value: string + onSumbit: (value: string) => void + onClose: () => void + isBot: boolean +} + +export const EditMessageForm = (props: Props) => { + const [isComposing, setIsComposing] = React.useState(false) + const textareaRef = React.useRef(null) + + const form = useForm({ + initialValues: { + message: props.value + } + }) + useDynamicTextareaSize(textareaRef, form.values.message, 300) + + React.useEffect(() => { + form.setFieldValue("message", props.value) + }, [props.value]) + + return ( +
{ + if (isComposing) return + props.onClose() + props.onSumbit(data.message) + })} + className="flex flex-col gap-2"> +