Elffuss BraidHub

kikocis/continue public

e8f6b7fe8bda · 3.1 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 (currentToolCallApplyState?.status === "done") {
32 dispatch(
33 cancelToolCall({
34 toolCallId: currentToolCallApplyState.toolCallId!,
35 }),
36 );
37 }
38 for (const { filepath = "", streamId } of pendingApplyStates) {
39 ideMessenger.post(status, {
40 filepath,
41 streamId,
42 });
43 }
44
45 if (onAcceptOrReject) {
46 onAcceptOrReject(status);
47 }
48 }
49
50 const rejectShortcut = `${getMetaKeyLabel()}⇧⌫`;
51 const acceptShortcut = `${getMetaKeyLabel()}⇧⏎`;
52
53 return (
54 <div
55 className="flex flex-row items-center justify-evenly gap-3 px-3"
56 data-testid="accept-reject-all-buttons"
57 >
58 <button
59 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"
60 onClick={() => handleAcceptOrReject("rejectDiff")}
61 data-testid="edit-reject-button"
62 data-tooltip-id="reject-shortcut"
63 data-tooltip-content={`Reject All (${rejectShortcut})`}
64 >
65 <div className="flex flex-row items-center gap-1">
66 <XMarkIcon className="text-error h-4 w-4" />
67 <span className="hidden sm:inline">Reject</span>
68 </div>
69 </button>
70 <ToolTip id="reject-shortcut" />
71
72 <button
73 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"
74 onClick={() => handleAcceptOrReject("acceptDiff")}
75 data-testid="edit-accept-button"
76 data-tooltip-id="accept-shortcut"
77 data-tooltip-content={`Accept All (${acceptShortcut})`}
78 >
79 <div className="flex flex-row items-center gap-1">
80 <CheckIcon className="text-success h-4 w-4" />
81 <span className="hidden sm:inline">Accept</span>
82 </div>
83 </button>
84 <ToolTip id="accept-shortcut" />
85 </div>
86 );
87}