reroute after duplicate message

This commit is contained in:
Nate Kelley 2025-04-16 23:54:54 -06:00
parent ba16fcac4a
commit 95805195e0
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
1 changed files with 30 additions and 7 deletions

View File

@ -8,30 +8,53 @@ import {
useGetChatMessage, useGetChatMessage,
useUpdateChatMessageFeedback useUpdateChatMessageFeedback
} from '@/api/buster_rest/chats'; } from '@/api/buster_rest/chats';
import { useBusterNotifications } from '@/context/BusterNotifications';
import { useMemoizedFn } from '@/hooks';
import { timeout } from '@/lib';
import { useAppLayoutContextSelector } from '@/context/BusterAppLayout';
import { BusterRoutes } from '@/routes';
import { useGetInitialChatFile } from '../../ChatContext/useGetInitialChatFile';
export const ChatMessageOptions: React.FC<{ export const ChatMessageOptions: React.FC<{
messageId: string; messageId: string;
chatId: string; chatId: string;
}> = React.memo(({ messageId, chatId }) => { }> = React.memo(({ messageId, chatId }) => {
const onChangePage = useAppLayoutContextSelector((x) => x.onChangePage);
const { mutateAsync: duplicateChat, isPending: isCopying } = useDuplicateChat(); const { mutateAsync: duplicateChat, isPending: isCopying } = useDuplicateChat();
const { mutateAsync: updateChatMessageFeedback } = useUpdateChatMessageFeedback(); const { mutateAsync: updateChatMessageFeedback } = useUpdateChatMessageFeedback();
const { data: feedback } = useGetChatMessage(messageId, { const { data: feedback } = useGetChatMessage(messageId, {
select: ({ feedback }) => feedback select: ({ feedback }) => feedback
}); });
const { openConfirmModal } = useBusterNotifications();
const warnBeforeDuplicate = useMemoizedFn(() => {
openConfirmModal({
title: 'Duplicate chat',
content:
'You are about to duplicate this chat from this message. This will create a new chat with the same messages. Do you want to continue?',
onOk: async () => {
const res = await duplicateChat({
id: chatId,
message_id: messageId
});
await timeout(100);
await onChangePage({
route: BusterRoutes.APP_CHAT_ID,
chatId: res.id
});
}
});
});
return ( return (
<div className="flex items-center gap-1"> <div className="flex items-center gap-1">
<AppTooltip title="Duplicate message"> <AppTooltip title="Duplicate chat from this message">
<Button <Button
variant="ghost" variant="ghost"
prefix={<Copy />} prefix={<Copy />}
loading={isCopying} loading={isCopying}
onClick={() => onClick={warnBeforeDuplicate}
duplicateChat({
id: chatId,
message_id: messageId
})
}
/> />
</AppTooltip> </AppTooltip>
<AppTooltip title="Report message"> <AppTooltip title="Report message">