From 65ba2ff898897ea7a4fbebcc1a044ca7fa07e6f4 Mon Sep 17 00:00:00 2001 From: n4ze3m Date: Sun, 3 Nov 2024 23:38:41 +0530 Subject: [PATCH] feat: add save and send functionality for user message Adds a "Save" button to the edit message form in Playground, allowing users to save changes without immediately submitting them. This also introduces a new `isSend` flag to the `onEditFormSubmit` prop, enabling developers to control whether a message should be sent immediately or saved for later submission. This enhances flexibility and user control during the message editing process. --- src/components/Common/Markdown.tsx | 14 +----- .../Common/Playground/EditMessageForm.tsx | 50 +++++++++++++------ src/components/Common/Playground/Message.tsx | 2 +- .../Option/Playground/PlaygroundChat.tsx | 4 +- src/components/Option/Settings/tts-mode.tsx | 9 ++-- src/hooks/useMessageOption.tsx | 18 ++++--- 6 files changed, 53 insertions(+), 44 deletions(-) diff --git a/src/components/Common/Markdown.tsx b/src/components/Common/Markdown.tsx index 2934b64..c996acf 100644 --- a/src/components/Common/Markdown.tsx +++ b/src/components/Common/Markdown.tsx @@ -8,20 +8,8 @@ import rehypeKatex from "rehype-katex" import "property-information" import React from "react" import { CodeBlock } from "./CodeBlock" -export const preprocessLaTeX = (content: string) => { - // Replace block-level LaTeX delimiters \[ \] with $$ $$ +import { preprocessLaTeX } from "@/utils/latex" - const blockProcessedContent = content.replace( - /\\\[(.*?)\\\]/gs, - (_, equation) => `$$${equation}$$` - ) - // Replace inline LaTeX delimiters \( \) with $ $ - const inlineProcessedContent = blockProcessedContent.replace( - /\\\((.*?)\\\)/gs, - (_, equation) => `$${equation}$` - ) - return inlineProcessedContent -} function Markdown({ message, className = "prose break-words dark:prose-invert prose-p:leading-relaxed prose-pre:p-0 dark:prose-dark" diff --git a/src/components/Common/Playground/EditMessageForm.tsx b/src/components/Common/Playground/EditMessageForm.tsx index e818f24..f42b6d4 100644 --- a/src/components/Common/Playground/EditMessageForm.tsx +++ b/src/components/Common/Playground/EditMessageForm.tsx @@ -5,7 +5,7 @@ import useDynamicTextareaSize from "~/hooks/useDynamicTextareaSize" type Props = { value: string - onSumbit: (value: string) => void + onSumbit: (value: string, isSend: boolean) => void onClose: () => void isBot: boolean } @@ -31,7 +31,7 @@ export const EditMessageForm = (props: Props) => { onSubmit={form.onSubmit((data) => { if (isComposing) return props.onClose() - props.onSumbit(data.message) + props.onSumbit(data.message, true) })} className="flex flex-col gap-2">