Elffuss BraidHub

kikocis/continue public

a36aa2a5e5e6 · 3.0 KiBRawPermalink
1import { useEffect } from "react";
2import { useSelector } from "react-redux";
3import { useAppDispatch, useAppSelector } from "../../../../redux/hooks";
4import { selectCurrentToolCall } from "../../../../redux/selectors/selectCurrentToolCall";
5import { callCurrentTool } from "../../../../redux/thunks/callCurrentTool";
6import { cancelCurrentToolCall } from "../../../../redux/thunks/cancelCurrentToolCall";
7import { isJetBrains } from "../../../../util";
8import { BlockSettingsTopToolbar } from "./BlockSettingsTopToolbar";
9import { EditOutcomeToolbar } from "./EditOutcomeToolbar";
10import { EditToolbar } from "./EditToolbar";
11import { IsApplyingToolbar } from "./IsApplyingToolbar";
12import { PendingApplyStatesToolbar } from "./PendingApplyStatesToolbar";
13import { PendingToolCallToolbar } from "./PendingToolCallToolbar";
14import { StreamingToolbar } from "./StreamingToolbar";
15import { TtsActiveToolbar } from "./TtsActiveToolbar";
16
17export function LumpToolbar() {
18 const dispatch = useAppDispatch();
19 const ttsActive = useAppSelector((state) => state.ui.ttsActive);
20 const isStreaming = useAppSelector((state) => state.session.isStreaming);
21 const isInEdit = useAppSelector((state) => state.session.isInEdit);
22 const jetbrains = isJetBrains();
23 const toolCallState = useSelector(selectCurrentToolCall);
24 const editApplyState = useAppSelector(
25 (state) => state.editModeState.applyState,
26 );
27 const applyStates = useAppSelector(
28 (state) => state.session.codeBlockApplyStates.states,
29 );
30
31 const pendingApplyStates = applyStates.filter(
32 (state) => state.status === "done",
33 );
34
35 const isApplying = applyStates.some((state) => state.status === "streaming");
36
37 useEffect(() => {
38 if (toolCallState?.status !== "generated") {
39 return;
40 }
41
42 const handleKeyDown = (event: KeyboardEvent) => {
43 const metaKey = event.metaKey || event.ctrlKey;
44 const altKey = event.altKey;
45
46 if (metaKey && event.key === "Enter") {
47 event.preventDefault();
48 event.stopPropagation();
49 void dispatch(callCurrentTool());
50 } else if ((jetbrains ? altKey : metaKey) && event.key === "Backspace") {
51 event.preventDefault();
52 event.stopPropagation();
53 void dispatch(cancelCurrentToolCall());
54 }
55 };
56
57 document.addEventListener("keydown", handleKeyDown);
58 return () => {
59 document.removeEventListener("keydown", handleKeyDown);
60 };
61 }, [toolCallState]);
62
63 if (isApplying) {
64 return <IsApplyingToolbar />;
65 }
66
67 if (isInEdit) {
68 if (editApplyState.status === "done") {
69 return <EditOutcomeToolbar />;
70 }
71
72 return <EditToolbar />;
73 }
74
75 if (ttsActive) {
76 return <TtsActiveToolbar />;
77 }
78
79 if (isStreaming) {
80 return <StreamingToolbar />;
81 }
82
83 if (toolCallState?.status === "generated") {
84 return <PendingToolCallToolbar />;
85 }
86
87 if (pendingApplyStates.length > 0) {
88 return (
89 <PendingApplyStatesToolbar pendingApplyStates={pendingApplyStates} />
90 );
91 }
92
93 return <BlockSettingsTopToolbar />;
94}