Skip to content

Commit 821e987

Browse files
committed
feat: remove edit message feature
1 parent 3005a25 commit 821e987

File tree

2 files changed

+11
-65
lines changed

2 files changed

+11
-65
lines changed

src/components/Chat/Chat.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface Props {
2121
export const Chat = memo(({ stopConversationRef }: Props) => {
2222
const {
2323
state: { selectedConversation, conversations },
24-
dispatch: homeDispatch,
24+
dispatch,
2525
} = useContext(ReactStreamChatContext)
2626

2727
const [currentMessage, setCurrentMessage] = useState<Message>()
@@ -52,12 +52,12 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
5252
messages: [...selectedConversation.messages, message],
5353
}
5454
}
55-
homeDispatch({
55+
dispatch({
5656
field: 'selectedConversation',
5757
value: updatedConversation,
5858
})
59-
homeDispatch({ field: 'loading', value: true })
60-
homeDispatch({ field: 'messageIsStreaming', value: true })
59+
dispatch({ field: 'loading', value: true })
60+
dispatch({ field: 'messageIsStreaming', value: true })
6161
if (updatedConversation.messages.length === 1) {
6262
const { content } = message
6363
const customName =
@@ -67,7 +67,7 @@ export const Chat = memo(({ stopConversationRef }: Props) => {
6767
name: customName,
6868
}
6969
}
70-
homeDispatch({ field: 'loading', value: false })
70+
dispatch({ field: 'loading', value: false })
7171
const interval = 500 // 500ms
7272
const encoder = new TextEncoder()
7373

@@ -176,7 +176,7 @@ QuickSort is an efficient, in-place sorting algorithm that, in practice, outperf
176176
...updatedConversation,
177177
messages: updatedMessages,
178178
}
179-
homeDispatch({
179+
dispatch({
180180
field: 'selectedConversation',
181181
value: updatedConversation,
182182
})
@@ -196,7 +196,7 @@ QuickSort is an efficient, in-place sorting algorithm that, in practice, outperf
196196
...updatedConversation,
197197
messages: updatedMessages,
198198
}
199-
homeDispatch({
199+
dispatch({
200200
field: 'selectedConversation',
201201
value: updatedConversation,
202202
})
@@ -214,9 +214,9 @@ QuickSort is an efficient, in-place sorting algorithm that, in practice, outperf
214214
if (updatedConversations.length === 0) {
215215
updatedConversations.push(updatedConversation)
216216
}
217-
homeDispatch({ field: 'conversations', value: updatedConversations })
217+
dispatch({ field: 'conversations', value: updatedConversations })
218218
saveConversations(updatedConversations)
219-
homeDispatch({ field: 'messageIsStreaming', value: false })
219+
dispatch({ field: 'messageIsStreaming', value: false })
220220
}
221221
},
222222
[conversations, selectedConversation, stopConversationRef],

src/components/Chat/ChatMessage.tsx

+2-56
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { IconCheck, IconCopy, IconRobot, IconUser } from '@tabler/icons-react'
2-
import { FC, memo, useContext, useEffect, useRef, useState } from 'react'
3-
import { updateConversation } from '@/utils/app/conversation'
2+
import { FC, memo, useContext, useState } from 'react'
43
import { Message } from '@/types/chat'
54
import { ReactStreamChatContext } from '@/components/ReactStreamChat/context'
65
import { CodeBlock } from '../Markdown/CodeBlock'
@@ -16,59 +15,10 @@ export interface Props {
1615

1716
export const ChatMessage: FC<Props> = memo(({ message, messageIndex }) => {
1817
const {
19-
state: { selectedConversation, conversations, messageIsStreaming },
20-
dispatch: homeDispatch,
18+
state: { selectedConversation, messageIsStreaming },
2119
} = useContext(ReactStreamChatContext)
2220

23-
const [isTyping, setIsTyping] = useState<boolean>(false)
24-
const [messageContent, setMessageContent] = useState(message.content)
2521
const [messagedCopied, setMessageCopied] = useState(false)
26-
27-
const textareaRef = useRef<HTMLTextAreaElement>(null)
28-
29-
const handleInputChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
30-
setMessageContent(event.target.value)
31-
if (textareaRef.current) {
32-
textareaRef.current.style.height = 'inherit'
33-
textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`
34-
}
35-
}
36-
37-
const handleDeleteMessage = () => {
38-
if (!selectedConversation) return
39-
40-
const { messages } = selectedConversation
41-
const findIndex = messages.findIndex((elm) => elm === message)
42-
43-
if (findIndex < 0) return
44-
45-
if (
46-
findIndex < messages.length - 1 &&
47-
messages[findIndex + 1].role === 'assistant'
48-
) {
49-
messages.splice(findIndex, 2)
50-
} else {
51-
messages.splice(findIndex, 1)
52-
}
53-
const updatedConversation = {
54-
...selectedConversation,
55-
messages,
56-
}
57-
58-
const { single, all } = updateConversation(
59-
updatedConversation,
60-
conversations,
61-
)
62-
homeDispatch({ field: 'selectedConversation', value: single })
63-
homeDispatch({ field: 'conversations', value: all })
64-
}
65-
66-
const handlePressEnter = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
67-
if (e.key === 'Enter' && !isTyping && !e.shiftKey) {
68-
e.preventDefault()
69-
}
70-
}
71-
7222
const copyOnClick = () => {
7323
if (!navigator.clipboard) return
7424

@@ -80,10 +30,6 @@ export const ChatMessage: FC<Props> = memo(({ message, messageIndex }) => {
8030
})
8131
}
8232

83-
useEffect(() => {
84-
setMessageContent(message.content)
85-
}, [message.content])
86-
8733
return (
8834
<div
8935
className={`group md:px-4 ${

0 commit comments

Comments
 (0)