| 1 | import { |
| 2 | HandThumbDownIcon, |
| 3 | HandThumbUpIcon, |
| 4 | } from "@heroicons/react/24/outline"; |
| 5 | import { ChatHistoryItem } from "core"; |
| 6 | import { useContext, useState } from "react"; |
| 7 | import { IdeMessengerContext } from "../context/IdeMessenger"; |
| 8 | import { useAppSelector } from "../redux/hooks"; |
| 9 | import HeaderButtonWithToolTip from "./gui/HeaderButtonWithToolTip"; |
| 10 | |
| 11 | export interface FeedbackButtonsProps { |
| 12 | item: ChatHistoryItem; |
| 13 | } |
| 14 | |
| 15 | export function FeedbackButtons({ item }: FeedbackButtonsProps) { |
| 16 | const [feedback, setFeedback] = useState<boolean | undefined>(undefined); |
| 17 | const ideMessenger = useContext(IdeMessengerContext); |
| 18 | const sessionId = useAppSelector((store) => store.session.id); |
| 19 | |
| 20 | const sendFeedback = (feedback: boolean) => { |
| 21 | setFeedback(feedback); |
| 22 | if (item.promptLogs?.length) { |
| 23 | for (const promptLog of item.promptLogs) { |
| 24 | ideMessenger.post("devdata/log", { |
| 25 | name: "chatFeedback", |
| 26 | data: { |
| 27 | ...promptLog, |
| 28 | feedback, |
| 29 | sessionId, |
| 30 | }, |
| 31 | }); |
| 32 | } |
| 33 | } |
| 34 | }; |
| 35 | |
| 36 | return ( |
| 37 | <> |
| 38 | <HeaderButtonWithToolTip |
| 39 | text="Helpful" |
| 40 | tabIndex={-1} |
| 41 | onClick={() => sendFeedback(true)} |
| 42 | > |
| 43 | <HandThumbUpIcon |
| 44 | className={`mx-0.5 h-3.5 w-3.5 ${feedback === true ? "text-success" : "text-description-muted"}`} |
| 45 | /> |
| 46 | </HeaderButtonWithToolTip> |
| 47 | <HeaderButtonWithToolTip |
| 48 | text="Unhelpful" |
| 49 | tabIndex={-1} |
| 50 | onClick={() => sendFeedback(false)} |
| 51 | > |
| 52 | <HandThumbDownIcon |
| 53 | className={`h-3.5 w-3.5 ${feedback === false ? "text-error" : "text-description-muted"}`} |
| 54 | /> |
| 55 | </HeaderButtonWithToolTip> |
| 56 | </> |
| 57 | ); |
| 58 | } |