mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-30 00:53:14 +00:00
wires up the feedback event handler with redux storie
This commit is contained in:
@@ -8,10 +8,12 @@ import {
|
||||
fetchAnswer,
|
||||
selectQueries,
|
||||
selectStatus,
|
||||
updateQuery,
|
||||
} from './conversationSlice';
|
||||
import Send from './../assets/send.svg';
|
||||
import Spinner from './../assets/spinner.svg';
|
||||
import { Query } from './conversationModels';
|
||||
import { FEEDBACK, Query } from './conversationModels';
|
||||
import { sendFeedback } from './conversationApi';
|
||||
|
||||
export default function Conversation() {
|
||||
const queries = useSelector(selectQueries);
|
||||
@@ -22,7 +24,7 @@ export default function Conversation() {
|
||||
|
||||
useEffect(
|
||||
() => endMessageRef?.current?.scrollIntoView({ behavior: 'smooth' }),
|
||||
[queries],
|
||||
[queries.length, queries[queries.length - 1]],
|
||||
);
|
||||
|
||||
const handleQuestion = (question: string) => {
|
||||
@@ -30,6 +32,14 @@ export default function Conversation() {
|
||||
dispatch(fetchAnswer({ question }));
|
||||
};
|
||||
|
||||
const handleFeedback = (query: Query, feedback: FEEDBACK, index: number) => {
|
||||
const prevFeedback = query.feedback;
|
||||
dispatch(updateQuery({ index, query: { feedback } }));
|
||||
sendFeedback(query.prompt, query.response!, feedback).catch(() =>
|
||||
dispatch(updateQuery({ index, query: { feedback: prevFeedback } })),
|
||||
);
|
||||
};
|
||||
|
||||
const prepResponseView = (query: Query, index: number) => {
|
||||
let responseView;
|
||||
if (query.error) {
|
||||
@@ -51,6 +61,9 @@ export default function Conversation() {
|
||||
message={query.response}
|
||||
type={'ANSWER'}
|
||||
feedback={query.feedback}
|
||||
handleFeedback={(feedback: FEEDBACK) =>
|
||||
handleFeedback(query, feedback, index)
|
||||
}
|
||||
></ConversationBubble>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user