Elffuss BraidHub

kikocis/continue public

35c0ed0a3308 · 3.2 KiBRawPermalink
1import { CheckIcon, XMarkIcon } from "@heroicons/react/24/outline";
2import { ApplyState } from "core";
3import { useContext } from "react";
4import { IdeMessengerContext } from "../context/IdeMessenger";
5import { useAppDispatch, useAppSelector } from "../redux/hooks";
6import { selectCurrentToolCallApplyState } from "../redux/selectors/selectCurrentToolCall";
7import { cancelToolCall } from "../redux/slices/sessionSlice";
8import { getMetaKeyLabel } from "../util";
9import { ToolTip } from "./gui/Tooltip";
10
11export interface AcceptRejectAllButtonsProps {
12 applyStates: ApplyState[];
13 onAcceptOrReject?: (outcome: AcceptOrRejectOutcome) => void;
14}
15
16export type AcceptOrRejectOutcome = "acceptDiff" | "rejectDiff";
17
18export default function AcceptRejectAllButtons({
19 applyStates,
20 onAcceptOrReject,
21}: AcceptRejectAllButtonsProps) {
22 const pendingApplyStates = applyStates.filter(
23 (state) => state.status === "done",
24 );
25 const ideMessenger = useContext(IdeMessengerContext);
26 const currentToolCallApplyState = useAppSelector(
27 selectCurrentToolCallApplyState,
28 );
29 const dispatch = useAppDispatch();
30 async function handleAcceptOrReject(status: AcceptOrRejectOutcome) {
31 if (
32 status === "rejectDiff" &&
33 currentToolCallApplyState?.status === "done"
34 ) {
35 dispatch(
36 cancelToolCall({
37 toolCallId: currentToolCallApplyState.toolCallId!,
38 }),
39 );
40 }
41 for (const { filepath = "", streamId } of pendingApplyStates) {
42 ideMessenger.post(status, {
43 filepath,
44 streamId,
45 });
46 }
47
48 if (onAcceptOrReject) {
49 onAcceptOrReject(status);
50 }
51 }
52
53 const rejectShortcut = `${getMetaKeyLabel()}⇧⌫`;
54 const acceptShortcut = `${getMetaKeyLabel()}⇧⏎`;
55
56 return (
57 <div
58 className="flex flex-row items-center justify-evenly gap-3 px-3"
59 data-testid="accept-reject-all-buttons"
60 >
61 <button
62 className="text-foreground flex cursor-pointer flex-row flex-wrap justify-center gap-1 border-none bg-transparent p-0 text-xs opacity-80 hover:opacity-100 hover:brightness-125"
63 onClick={() => handleAcceptOrReject("rejectDiff")}
64 data-testid="edit-reject-button"
65 data-tooltip-id="reject-shortcut"
66 data-tooltip-content={`Reject All (${rejectShortcut})`}
67 >
68 <div className="flex flex-row items-center gap-1">
69 <XMarkIcon className="text-error h-4 w-4" />
70 <span className="hidden sm:inline">Reject</span>
71 </div>
72 </button>
73 <ToolTip id="reject-shortcut" />
74
75 <button
76 className="text-foreground flex cursor-pointer flex-row flex-wrap justify-center gap-1 border-none bg-transparent p-0 text-xs opacity-80 hover:opacity-100 hover:brightness-125"
77 onClick={() => handleAcceptOrReject("acceptDiff")}
78 data-testid="edit-accept-button"
79 data-tooltip-id="accept-shortcut"
80 data-tooltip-content={`Accept All (${acceptShortcut})`}
81 >
82 <div className="flex flex-row items-center gap-1">
83 <CheckIcon className="text-success h-4 w-4" />
84 <span className="hidden sm:inline">Accept</span>
85 </div>
86 </button>
87 <ToolTip id="accept-shortcut" />
88 </div>
89 );
90}