diff --git a/application/api/user/routes.py b/application/api/user/routes.py index 6eb57cc0..961e375b 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -1791,4 +1791,4 @@ class TextToSpeech(Resource): 200, ) except Exception as err: - return make_response(jsonify({"success": False, "error": str(err)}), 400) + return make_response(jsonify({"success": False, "error": str(err)}), 400) \ No newline at end of file diff --git a/frontend/src/conversation/Conversation.tsx b/frontend/src/conversation/Conversation.tsx index 41bc8d2f..1c3a296f 100644 --- a/frontend/src/conversation/Conversation.tsx +++ b/frontend/src/conversation/Conversation.tsx @@ -15,7 +15,6 @@ import { useDarkTheme, useMediaQuery } from '../hooks'; import { ShareConversationModal } from '../modals/ShareConversationModal'; import { selectConversationId } from '../preferences/preferenceSlice'; import { AppDispatch } from '../store'; -import conversationService from '../api/services/conversationService'; import ConversationBubble from './ConversationBubble'; import { handleSendFeedback } from './conversationHandlers'; import { FEEDBACK, Query } from './conversationModels'; @@ -111,8 +110,22 @@ export default function Conversation() { const handleFeedback = (query: Query, feedback: FEEDBACK, index: number) => { const prevFeedback = query.feedback; dispatch(updateQuery({ index, query: { feedback } })); - handleSendFeedback(query.prompt, query.response!, feedback,conversationId as string,index).catch(() => - dispatch(updateQuery({ index, query: { feedback: prevFeedback } })), + handleSendFeedback( + query.prompt, + query.response!, + feedback, + conversationId as string, + index, + ).catch(() => + handleSendFeedback( + query.prompt, + query.response!, + feedback, + conversationId as string, + index, + ).catch(() => + dispatch(updateQuery({ index, query: { feedback: prevFeedback } })), + ), ); }; diff --git a/frontend/src/conversation/ConversationBubble.tsx b/frontend/src/conversation/ConversationBubble.tsx index 03a3ab08..2d6fca1a 100644 --- a/frontend/src/conversation/ConversationBubble.tsx +++ b/frontend/src/conversation/ConversationBubble.tsx @@ -448,10 +448,14 @@ const ConversationBubble = forwardRef< : 'fill-none stroke-gray-4000' }`} onClick={() => { - if (feedback === undefined) { + if (feedback === undefined || feedback === null) { handleFeedback?.('LIKE'); setIsLikeClicked(true); setIsDislikeClicked(false); + } else if (feedback === 'LIKE') { + handleFeedback?.(null); + setIsLikeClicked(false); + setIsDislikeClicked(false); } }} onMouseEnter={() => setIsLikeHovered(true)} @@ -484,10 +488,14 @@ const ConversationBubble = forwardRef< : 'fill-none stroke-gray-4000' }`} onClick={() => { - if (feedback === undefined) { + if (feedback === undefined || feedback === null) { handleFeedback?.('DISLIKE'); setIsDislikeClicked(true); setIsLikeClicked(false); + } else if (feedback === 'DISLIKE') { + handleFeedback?.(null); + setIsLikeClicked(false); + setIsDislikeClicked(false); } }} onMouseEnter={() => setIsDislikeHovered(true)} diff --git a/frontend/src/conversation/conversationHandlers.ts b/frontend/src/conversation/conversationHandlers.ts index ea8ad6ea..1abdb74d 100644 --- a/frontend/src/conversation/conversationHandlers.ts +++ b/frontend/src/conversation/conversationHandlers.ts @@ -202,16 +202,16 @@ export function handleSendFeedback( prompt: string, response: string, feedback: FEEDBACK, - conversation_id:string, - prompt_index:number + conversation_id: string, + prompt_index: number, ) { return conversationService .feedback({ question: prompt, answer: response, feedback: feedback, - conversation_id:conversation_id, - question_index:prompt_index + conversation_id: conversation_id, + question_index: prompt_index, }) .then((response) => { if (response.ok) { diff --git a/frontend/src/conversation/conversationModels.ts b/frontend/src/conversation/conversationModels.ts index cd286852..a499deec 100644 --- a/frontend/src/conversation/conversationModels.ts +++ b/frontend/src/conversation/conversationModels.ts @@ -1,6 +1,6 @@ export type MESSAGE_TYPE = 'QUESTION' | 'ANSWER' | 'ERROR'; export type Status = 'idle' | 'loading' | 'failed'; -export type FEEDBACK = 'LIKE' | 'DISLIKE'; +export type FEEDBACK = 'LIKE' | 'DISLIKE' | null; export interface Message { text: string;