diff --git a/src/components/ContentGenerator/QuestionAnswerChat.tsx b/src/components/ContentGenerator/QuestionAnswerChat.tsx
index 14c8d4aec..badcb7d27 100644
--- a/src/components/ContentGenerator/QuestionAnswerChat.tsx
+++ b/src/components/ContentGenerator/QuestionAnswerChat.tsx
@@ -5,7 +5,12 @@ import {
type AIQuestionSuggestionsResponse,
} from '../../queries/user-ai-session';
import type { AllowedFormat } from './ContentGenerator';
-import { Loader2Icon, RotateCwIcon, SendIcon } from 'lucide-react';
+import {
+ Loader2Icon,
+ RefreshCcwIcon,
+ RotateCwIcon,
+ SendIcon,
+} from 'lucide-react';
import { useEffect, useRef, useState } from 'react';
import { cn } from '../../lib/classname';
import { flushSync } from 'react-dom';
@@ -28,6 +33,7 @@ type QuestionAnswerChatProps = {
) => void;
onGenerateNow: () => void;
defaultQuestions?: AIQuestionSuggestionsResponse['questions'];
+ type?: 'create' | 'update';
};
export function QuestionAnswerChat(props: QuestionAnswerChatProps) {
@@ -38,6 +44,7 @@ export function QuestionAnswerChat(props: QuestionAnswerChatProps) {
questionAnswerChatMessages,
setQuestionAnswerChatMessages,
onGenerateNow,
+ type = 'create',
} = props;
const [activeMessageIndex, setActiveMessageIndex] = useState(
@@ -117,7 +124,7 @@ export function QuestionAnswerChat(props: QuestionAnswerChatProps) {
useEffect(() => {
scrollToBottom();
- }, [defaultQuestions]);
+ }, [defaultQuestions, type]);
return (
<>
@@ -145,7 +152,7 @@ export function QuestionAnswerChat(props: QuestionAnswerChatProps) {
{!isLoadingAiQuestionSuggestions && status === 'answering' && (
<>
- {canReset && (
+ {canReset && type === 'create' && (
+ {!activeMessage && type === 'update' && (
+
+
+
+ )}
+
{activeMessage && (
@@ -212,13 +235,7 @@ export function QuestionAnswerChat(props: QuestionAnswerChatProps) {
- {
- e.preventDefault();
- handleAnswerSelect(message);
- }}
- >
+
setMessage(e.target.value)}
diff --git a/src/components/GenerateGuide/UpdatePreferences.tsx b/src/components/GenerateGuide/UpdatePreferences.tsx
index d0b38c760..8869edcd7 100644
--- a/src/components/GenerateGuide/UpdatePreferences.tsx
+++ b/src/components/GenerateGuide/UpdatePreferences.tsx
@@ -1,4 +1,4 @@
-import { useState } from 'react';
+import { useMemo, useState } from 'react';
import type { AIQuestionSuggestionsResponse } from '../../queries/user-ai-session';
import type { AllowedFormat } from '../ContentGenerator/ContentGenerator';
import {
@@ -21,7 +21,7 @@ type UpdatePreferencesProps = {
export function UpdatePreferences(props: UpdatePreferencesProps) {
const {
onClose,
- questionAndAnswers,
+ questionAndAnswers: defaultQuestionAndAnswers,
term,
format,
onUpdatePreferences,
@@ -30,15 +30,22 @@ export function UpdatePreferences(props: UpdatePreferencesProps) {
const [questionAnswerChatMessages, setQuestionAnswerChatMessages] = useState<
QuestionAnswerChatMessage[]
- >(questionAndAnswers || []);
+ >(defaultQuestionAndAnswers || []);
- const defaultQuestions = questionAndAnswers
+ const defaultQuestions = defaultQuestionAndAnswers
?.filter((message) => message.role === 'assistant')
.map((message) => ({
question: message.question,
possibleAnswers: message.possibleAnswers,
}));
+ const hasChangedQuestionAndAnswers = useMemo(() => {
+ return (
+ JSON.stringify(questionAnswerChatMessages) !==
+ JSON.stringify(defaultQuestionAndAnswers)
+ );
+ }, [questionAnswerChatMessages, defaultQuestionAndAnswers]);
+
return (
{
onUpdatePreferences(questionAnswerChatMessages);
}}
+ type="update"
/>
-
+ {hasChangedQuestionAndAnswers && (
+
+ )}
);
}