fix(ai): edit message should updated message
Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
+1
-1
@@ -54,7 +54,7 @@ export const WelcomeScreen = ({ onSend, centerInputOnEmpty }: WelcomeScreenProps
|
||||
const month = now.getMonth() + 1
|
||||
const year = now.getFullYear()
|
||||
|
||||
return `${AI_CHAT_SPECIAL_ID_PREFIX}${year}-${month}-${day}`
|
||||
return `${AI_CHAT_SPECIAL_ID_PREFIX.TIMELINE_SUMMARY}${year}-${month}-${day}`
|
||||
}, [])
|
||||
|
||||
const status = useChatStatus()
|
||||
|
||||
+1
-1
@@ -110,7 +110,7 @@ export const AIChatMessage: React.FC<AIChatMessageProps> = React.memo(
|
||||
<div className="text-text relative flex max-w-full flex-col gap-2">
|
||||
{/* Normal message display */}
|
||||
<div className="text-text">
|
||||
<div className="flex select-text flex-col gap-2 text-sm">
|
||||
<div className="flex cursor-text select-text flex-col gap-2 text-sm">
|
||||
<AIMessageParts message={message} isLastMessage={isLastMessage} />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
+22
-2
@@ -3,11 +3,13 @@ import { defaultLexicalTheme } from "@follow/components/ui/lexical-rich-editor/t
|
||||
import { cn } from "@follow/utils"
|
||||
import type { InitialConfigType } from "@lexical/react/LexicalComposer"
|
||||
import { LexicalComposer } from "@lexical/react/LexicalComposer"
|
||||
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext"
|
||||
import { ContentEditable } from "@lexical/react/LexicalContentEditable"
|
||||
import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary"
|
||||
import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin"
|
||||
import type { SerializedEditorState } from "lexical"
|
||||
import * as React from "react"
|
||||
import isEqual from "react-fast-compare"
|
||||
|
||||
import { FileAttachmentNode } from "../../editor"
|
||||
import { MentionNode } from "../../editor/plugins/mention/MentionNode"
|
||||
@@ -26,6 +28,7 @@ interface UserRichTextMessageProps {
|
||||
|
||||
export const UserRichTextMessage: React.FC<UserRichTextMessageProps> = React.memo(
|
||||
({ data, className }) => {
|
||||
const editorState = typeof data.state === "object" ? JSON.stringify(data.state) : data.state
|
||||
let initialConfig: InitialConfigType = null!
|
||||
if (!initialConfig) {
|
||||
initialConfig = {
|
||||
@@ -33,12 +36,12 @@ export const UserRichTextMessage: React.FC<UserRichTextMessageProps> = React.mem
|
||||
theme: defaultLexicalTheme,
|
||||
onError,
|
||||
editable: false,
|
||||
editorState: typeof data.state === "object" ? JSON.stringify(data.state) : data.state,
|
||||
editorState,
|
||||
nodes: [...LexicalRichEditorNodes, MentionNode, FileAttachmentNode],
|
||||
}
|
||||
}
|
||||
return (
|
||||
<div className={cn("text-text relative text-sm", className)}>
|
||||
<div className={cn("text-text relative cursor-text text-sm", className)}>
|
||||
<LexicalComposer initialConfig={initialConfig}>
|
||||
<RichTextPlugin
|
||||
contentEditable={
|
||||
@@ -47,8 +50,25 @@ export const UserRichTextMessage: React.FC<UserRichTextMessageProps> = React.mem
|
||||
ErrorBoundary={LexicalErrorBoundary}
|
||||
placeholder={null}
|
||||
/>
|
||||
<ListenableContentChangedPlugin state={editorState} />
|
||||
</LexicalComposer>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
const ListenableContentChangedPlugin = ({ state }: { state: string }) => {
|
||||
const [editor] = useLexicalComposerContext()
|
||||
React.useEffect(() => {
|
||||
const editorState = editor.getEditorState()
|
||||
editorState.read(() => {
|
||||
const text = editorState.toJSON()
|
||||
|
||||
if (isEqual(text, state)) {
|
||||
return
|
||||
}
|
||||
editor.setEditorState(editor.parseEditorState(state))
|
||||
})
|
||||
}, [editor, state])
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user