mirror of https://github.com/buster-so/buster.git
Replace message flow is fixed
This commit is contained in:
parent
a560486659
commit
0648f2929a
|
@ -105,18 +105,14 @@ export const useBusterNewChat = () => {
|
||||||
(messageId) => messageId === messageId
|
(messageId) => messageId === messageId
|
||||||
);
|
);
|
||||||
|
|
||||||
if (messageIndex && messageIndex !== -1) {
|
if (messageIndex !== -1 && typeof messageIndex === 'number') {
|
||||||
console.log('oldMessageIds', currentChat?.message_ids);
|
|
||||||
const updatedMessageIds = currentChat?.message_ids.slice(0, messageIndex + 1);
|
const updatedMessageIds = currentChat?.message_ids.slice(0, messageIndex + 1);
|
||||||
console.log('stripping message ids', updatedMessageIds);
|
|
||||||
onUpdateChat({
|
onUpdateChat({
|
||||||
id: chatId,
|
id: chatId,
|
||||||
message_ids: updatedMessageIds
|
message_ids: updatedMessageIds
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
|
||||||
|
|
||||||
await busterSocket.emitAndOnce({
|
await busterSocket.emitAndOnce({
|
||||||
emitEvent: {
|
emitEvent: {
|
||||||
route: '/chats/post',
|
route: '/chats/post',
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import type { BusterChatMessageRequest } from '@/api/asset_interfaces';
|
import type { BusterChatMessageRequest } from '@/api/asset_interfaces';
|
||||||
import React, { useState, useRef } from 'react';
|
import React, { useState, useRef, useEffect } from 'react';
|
||||||
import { Paragraph } from '@/components/ui/typography';
|
import { Paragraph } from '@/components/ui/typography';
|
||||||
import { MessageContainer } from './MessageContainer';
|
import { MessageContainer } from './MessageContainer';
|
||||||
import { Tooltip } from '@/components/ui/tooltip';
|
import { Tooltip } from '@/components/ui/tooltip';
|
||||||
|
@ -9,7 +9,7 @@ import { cn } from '@/lib/classMerge';
|
||||||
import { PenWriting, Copy } from '@/components/ui/icons';
|
import { PenWriting, Copy } from '@/components/ui/icons';
|
||||||
import { Button } from '@/components/ui/buttons';
|
import { Button } from '@/components/ui/buttons';
|
||||||
import { useBusterNotifications } from '@/context/BusterNotifications';
|
import { useBusterNotifications } from '@/context/BusterNotifications';
|
||||||
import { useMemoizedFn } from '@/hooks';
|
import { useMemoizedFn, useMount } from '@/hooks';
|
||||||
import { InputTextArea } from '@/components/ui/inputs/InputTextArea';
|
import { InputTextArea } from '@/components/ui/inputs/InputTextArea';
|
||||||
import { useBusterNewChatContextSelector } from '@/context/Chats';
|
import { useBusterNewChatContextSelector } from '@/context/Chats';
|
||||||
|
|
||||||
|
@ -128,9 +128,10 @@ const EditMessage: React.FC<{
|
||||||
chatId: string;
|
chatId: string;
|
||||||
}> = React.memo(({ requestMessage, onSetIsEditing, messageId, chatId }) => {
|
}> = React.memo(({ requestMessage, onSetIsEditing, messageId, chatId }) => {
|
||||||
const [prompt, setPrompt] = useState(requestMessage.request);
|
const [prompt, setPrompt] = useState(requestMessage.request);
|
||||||
|
const textAreaRef = useRef<HTMLTextAreaElement>(null);
|
||||||
const onReplaceMessageInChat = useBusterNewChatContextSelector((x) => x.onReplaceMessageInChat);
|
const onReplaceMessageInChat = useBusterNewChatContextSelector((x) => x.onReplaceMessageInChat);
|
||||||
|
|
||||||
const onSave = useMemoizedFn((text: string) => {
|
const onSave = useMemoizedFn(() => {
|
||||||
onReplaceMessageInChat({
|
onReplaceMessageInChat({
|
||||||
chatId,
|
chatId,
|
||||||
messageId,
|
messageId,
|
||||||
|
@ -139,18 +140,30 @@ const EditMessage: React.FC<{
|
||||||
onSetIsEditing(false);
|
onSetIsEditing(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useMount(() => {
|
||||||
|
// Using requestAnimationFrame to ensure the DOM is ready
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (textAreaRef.current) {
|
||||||
|
textAreaRef.current.focus();
|
||||||
|
textAreaRef.current.select();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="-mt-1 flex flex-col space-y-2">
|
<div className="-mt-1 flex flex-col space-y-2">
|
||||||
<InputTextArea
|
<InputTextArea
|
||||||
|
ref={textAreaRef}
|
||||||
autoResize={{ minRows: 3, maxRows: 10 }}
|
autoResize={{ minRows: 3, maxRows: 10 }}
|
||||||
value={prompt}
|
value={prompt}
|
||||||
|
onPressEnter={onSave}
|
||||||
onChange={(e) => setPrompt(e.target.value)}
|
onChange={(e) => setPrompt(e.target.value)}
|
||||||
/>
|
/>
|
||||||
<div className="flex justify-end space-x-2">
|
<div className="flex justify-end space-x-2">
|
||||||
<Button variant={'ghost'} onClick={() => onSetIsEditing(false)}>
|
<Button variant={'ghost'} onClick={() => onSetIsEditing(false)}>
|
||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant={'black'} onClick={() => onSave(prompt)}>
|
<Button variant={'black'} onClick={onSave}>
|
||||||
Submit
|
Submit
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue