Skip to content

Commit d446ed5

Browse files
committed
🤖 refactor: extract duplicated mode switch code
Extracted MODE_OPTIONS constant and ModeHelpTooltip component to eliminate duplication between full and compact mode switch sections. _Generated with `cmux`_
1 parent 3425ffc commit d446ed5

File tree

1 file changed

+25
-33
lines changed

1 file changed

+25
-33
lines changed

src/components/ChatInput.tsx

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
prepareCompactionMessage,
2828
type CommandHandlerContext,
2929
} from "@/utils/chatCommands";
30-
import { ToggleGroup } from "./ToggleGroup";
30+
import { ToggleGroup, type ToggleOption } from "./ToggleGroup";
3131
import { CUSTOM_EVENTS } from "@/constants/events";
3232
import type { UIMode } from "@/types/mode";
3333
import {
@@ -88,6 +88,26 @@ export interface ChatInputAPI {
8888
appendText: (text: string) => void;
8989
}
9090

91+
92+
const MODE_OPTIONS: Array<ToggleOption<UIMode>> = [
93+
{ value: "exec", label: "Exec", activeClassName: "bg-exec-mode text-white" },
94+
{ value: "plan", label: "Plan", activeClassName: "bg-plan-mode text-white" },
95+
];
96+
97+
const ModeHelpTooltip: React.FC = () => (
98+
<TooltipWrapper inline>
99+
<HelpIndicator>?</HelpIndicator>
100+
<Tooltip className="tooltip" align="center" width="wide">
101+
<strong>Exec Mode:</strong> AI edits files and execute commands
102+
<br />
103+
<br />
104+
<strong>Plan Mode:</strong> AI proposes plans but does not edit files
105+
<br />
106+
<br />
107+
Toggle with: {formatKeybind(KEYBINDS.TOGGLE_MODE)}
108+
</Tooltip>
109+
</TooltipWrapper>
110+
);
91111
export interface ChatInputProps {
92112
workspaceId: string;
93113
onMessageSent?: () => void; // Optional callback after successful send
@@ -890,51 +910,23 @@ export const ChatInput: React.FC<ChatInputProps> = ({
890910
)}
891911
>
892912
<ToggleGroup<UIMode>
893-
options={[
894-
{ value: "exec", label: "Exec", activeClassName: "bg-exec-mode text-white" },
895-
{ value: "plan", label: "Plan", activeClassName: "bg-plan-mode text-white" },
896-
]}
913+
options={MODE_OPTIONS}
897914
value={mode}
898915
onChange={setMode}
899916
/>
900917
</div>
901-
<TooltipWrapper inline>
902-
<HelpIndicator>?</HelpIndicator>
903-
<Tooltip className="tooltip" align="center" width="wide">
904-
<strong>Exec Mode:</strong> AI edits files and execute commands
905-
<br />
906-
<br />
907-
<strong>Plan Mode:</strong> AI proposes plans but does not edit files
908-
<br />
909-
<br />
910-
Toggle with: {formatKeybind(KEYBINDS.TOGGLE_MODE)}
911-
</Tooltip>
912-
</TooltipWrapper>
918+
<ModeHelpTooltip />
913919
</div>
914920

915921
{/* Mode Switch - compact version for narrow viewports */}
916922
<div className="ml-auto hidden items-center gap-1.5 max-[550px]:flex">
917923
<ToggleGroup<UIMode>
918-
options={[
919-
{ value: "exec", label: "Exec", activeClassName: "bg-exec-mode text-white" },
920-
{ value: "plan", label: "Plan", activeClassName: "bg-plan-mode text-white" },
921-
]}
924+
options={MODE_OPTIONS}
922925
value={mode}
923926
onChange={setMode}
924927
compact
925928
/>
926-
<TooltipWrapper inline>
927-
<HelpIndicator>?</HelpIndicator>
928-
<Tooltip className="tooltip" align="center" width="wide">
929-
<strong>Exec Mode:</strong> AI edits files and execute commands
930-
<br />
931-
<br />
932-
<strong>Plan Mode:</strong> AI proposes plans but does not edit files
933-
<br />
934-
<br />
935-
Toggle with: {formatKeybind(KEYBINDS.TOGGLE_MODE)}
936-
</Tooltip>
937-
</TooltipWrapper>
929+
<ModeHelpTooltip />
938930
</div>
939931
</div>
940932
</div>

0 commit comments

Comments
 (0)