diff --git a/src/components/ContentGenerator/QuestionAnswerChat.tsx b/src/components/ContentGenerator/QuestionAnswerChat.tsx index 699658127..c4825d957 100644 --- a/src/components/ContentGenerator/QuestionAnswerChat.tsx +++ b/src/components/ContentGenerator/QuestionAnswerChat.tsx @@ -6,14 +6,15 @@ import { } from '../../queries/user-ai-session'; import type { AllowedFormat } from './ContentGenerator'; import { - Loader2Icon, RefreshCcwIcon, - RotateCwIcon, - SendIcon + Loader2Icon, + RefreshCcwIcon, + SendIcon, Trash2 } from 'lucide-react'; import { useEffect, useRef, useState } from 'react'; import { cn } from '../../lib/classname'; import { flushSync } from 'react-dom'; import { CheckIcon } from '../ReactIcons/CheckIcon'; +import { Tooltip } from '../Tooltip'; export type QuestionAnswerChatMessage = | { role: 'user'; answer: string } @@ -127,6 +128,30 @@ export function QuestionAnswerChat(props: QuestionAnswerChatProps) { setStatus('answering'); }; + const handleEditMessage = (messageIndex: number) => { + // Remove the assistant question and user answer pair + // Since user messages are at odd indices, we want to remove both + // the assistant message (at messageIndex - 1) and the user message (at messageIndex) + const assistantMessageIndex = messageIndex - 1; + const newMessages = questionAnswerChatMessages.slice( + 0, + assistantMessageIndex, + ); + setQuestionAnswerChatMessages(newMessages); + + // Calculate which question should be active + // Since we removed both assistant and user messages, the question index + // is simply assistantMessageIndex / 2 + const questionIndex = Math.floor(assistantMessageIndex / 2); + setActiveMessageIndex(questionIndex); + setStatus('answering'); + + setMessage(''); + setTimeout(() => { + inputRef.current?.focus(); + }, 0); + }; + useEffect(() => { scrollToBottom(); }, [defaultQuestions, type]); @@ -152,7 +177,7 @@ export function QuestionAnswerChat(props: QuestionAnswerChatProps) {
Preferences saved
+Preferences saved
You can now start generating {format}
@@ -170,18 +195,6 @@ export function QuestionAnswerChat(props: QuestionAnswerChatProps) { {!isLoadingAiQuestionSuggestions && status === 'answering' && ( <> - {canReset && type === 'create' && ( -