Elffuss BraidHub

kikocis/continue public

bdbad06b302d · 2.7 KiBRawPermalink
1import { CheckIcon, XMarkIcon } from "@heroicons/react/24/outline";
2import { ApplyState } from "core";
3import { useContext } from "react";
4import { IdeMessengerContext } from "../context/IdeMessenger";
5import { getMetaKeyLabel } from "../util";
6import { ToolTip } from "./gui/Tooltip";
7
8export interface AcceptRejectAllButtonsProps {
9 applyStates: ApplyState[];
10 onAcceptOrReject?: (outcome: AcceptOrRejectOutcome) => void;
11}
12
13export type AcceptOrRejectOutcome = "acceptDiff" | "rejectDiff";
14
15export default function AcceptRejectAllButtons({
16 applyStates,
17 onAcceptOrReject,
18}: AcceptRejectAllButtonsProps) {
19 const pendingApplyStates = applyStates.filter(
20 (state) => state.status === "done",
21 );
22 const ideMessenger = useContext(IdeMessengerContext);
23
24 async function handleAcceptOrReject(status: AcceptOrRejectOutcome) {
25 for (const { filepath = "", streamId } of pendingApplyStates) {
26 ideMessenger.post(status, {
27 filepath,
28 streamId,
29 });
30 }
31
32 if (onAcceptOrReject) {
33 onAcceptOrReject(status);
34 }
35 }
36
37 const rejectShortcut = `${getMetaKeyLabel()}⇧⌫`;
38 const acceptShortcut = `${getMetaKeyLabel()}⇧⏎`;
39
40 return (
41 <div
42 className="flex flex-row items-center justify-evenly gap-3 px-3"
43 data-testid="accept-reject-all-buttons"
44 >
45 <button
46 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"
47 onClick={() => handleAcceptOrReject("rejectDiff")}
48 data-testid="edit-reject-button"
49 data-tooltip-id="reject-shortcut"
50 data-tooltip-content={`Reject All (${rejectShortcut})`}
51 >
52 <div className="flex flex-row items-center gap-1">
53 <XMarkIcon className="text-error h-4 w-4" />
54 <span>Reject</span>
55 <span className="xs:inline-block hidden">All</span>
56 </div>
57 </button>
58 <ToolTip id="reject-shortcut" />
59
60 <button
61 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"
62 onClick={() => handleAcceptOrReject("acceptDiff")}
63 data-testid="edit-accept-button"
64 data-tooltip-id="accept-shortcut"
65 data-tooltip-content={`Accept All (${acceptShortcut})`}
66 >
67 <div className="flex flex-row items-center gap-1">
68 <CheckIcon className="text-success h-4 w-4" />
69 <span>Accept</span>
70 <span className="xs:inline-block hidden">All</span>
71 </div>
72 </button>
73 <ToolTip id="accept-shortcut" />
74 </div>
75 );
76}