Skip to content

Commit 0ea8cd2

Browse files
汤圆汤圆
authored andcommitted
feat: move mode ouf of setting dialog
1 parent d1a1ced commit 0ea8cd2

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

src/components/ChatWindow.tsx

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
TASK_STATUS_COMPLETED,
2121
TASK_STATUS_FINAL,
2222
PAUSE_MODE,
23+
AUTOMATIC_MODE,
2324
} from "../types/agentTypes";
2425
import clsx from "clsx";
2526
import { getMessageContainerStyle, getTaskStatusIcon } from "./utils/helpers";
@@ -61,6 +62,7 @@ const ChatWindow = ({
6162
const agent = useAgentStore.use.agent();
6263
const isWebSearchEnabled = useAgentStore.use.isWebSearchEnabled();
6364
const setIsWebSearchEnabled = useAgentStore.use.setIsWebSearchEnabled();
65+
const updateAgentMode = useAgentStore.use.updateAgentMode();
6466

6567
const handleScroll = (event: React.UIEvent<HTMLDivElement>) => {
6668
const { scrollTop, scrollHeight, clientHeight } = event.currentTarget;
@@ -116,6 +118,10 @@ const ChatWindow = ({
116118
return depth;
117119
};
118120

121+
const handleUpdateAgentMode = (value: boolean) => {
122+
updateAgentMode(value ? PAUSE_MODE : AUTOMATIC_MODE);
123+
};
124+
119125
return (
120126
<div
121127
className={
@@ -178,20 +184,42 @@ const ChatWindow = ({
178184
)}
179185
</div>
180186
{displaySettings && (
181-
<div className="flex items-center justify-center">
182-
<div className="m-1 flex items-center gap-2 rounded-lg border-[2px] border-white/20 bg-zinc-700 px-2 py-1">
183-
<p className="font-mono text-sm">{t("web-search")}</p>
187+
<div className="flex flex-col items-center justify-center md:flex-row">
188+
<SwitchContainer label="Web Search">
184189
<Switch
190+
disabled={agent !== null}
185191
value={isWebSearchEnabled}
186192
onChange={handleChangeWebSearch}
187193
/>
188-
</div>
194+
</SwitchContainer>
195+
<SwitchContainer label={PAUSE_MODE}>
196+
<Switch
197+
disabled={agent !== null}
198+
value={agentMode === PAUSE_MODE}
199+
onChange={handleUpdateAgentMode}
200+
/>
201+
</SwitchContainer>
189202
</div>
190203
)}
191204
</div>
192205
);
193206
};
194207

208+
const SwitchContainer = ({
209+
label,
210+
children,
211+
}: {
212+
label: string;
213+
children: React.ReactNode;
214+
}) => {
215+
return (
216+
<div className="m-1 flex w-36 items-center justify-center gap-2 rounded-lg border-[2px] border-white/20 bg-zinc-700 px-2 py-1">
217+
<p className="font-mono text-sm">{label}</p>
218+
{children}
219+
</div>
220+
);
221+
};
222+
195223
interface HeaderProps {
196224
title?: string | ReactNode;
197225
messages: Message[];

src/components/SettingsDialog.tsx

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
FaCoins,
1111
FaCode,
1212
FaServer,
13-
FaTachometerAlt,
1413
} from "react-icons/fa";
1514
import Dialog from "./Dialog";
1615
import Input from "./Input";
@@ -19,8 +18,6 @@ import Accordion from "./Accordion";
1918
import type { ModelSettings, SettingModel } from "../utils/types";
2019
import { useGuestMode } from "../hooks/useGuestMode";
2120
import clsx from "clsx";
22-
import { AUTOMATIC_MODE, PAUSE_MODE } from "../types/agentTypes";
23-
import { useAgentStore } from "./stores";
2421

2522
export const SettingsDialog: React.FC<{
2623
show: boolean;
@@ -32,9 +29,6 @@ export const SettingsDialog: React.FC<{
3229
});
3330
const { isGuestMode } = useGuestMode(settings.customGuestKey);
3431
const { t } = useTranslation(["settings", "common"]);
35-
const agent = useAgentStore.use.agent();
36-
const agentMode = useAgentStore.use.agentMode();
37-
const updateAgentMode = useAgentStore.use.updateAgentMode();
3832

3933
useEffect(() => {
4034
setSettings(customSettings.settings);
@@ -253,24 +247,6 @@ export const SettingsDialog: React.FC<{
253247
type="password"
254248
/>
255249
)}
256-
<Input
257-
left={
258-
<>
259-
<FaTachometerAlt />
260-
<span className="ml-2">{t("mode")}</span>
261-
</>
262-
}
263-
value={agentMode}
264-
disabled={agent !== null}
265-
onChange={() => null}
266-
setValue={updateAgentMode as (agentMode: string) => void}
267-
type="combobox"
268-
toolTipProperties={{
269-
message: t("mode-tips") as string,
270-
disabled: false,
271-
}}
272-
attributes={{ options: [AUTOMATIC_MODE, PAUSE_MODE] }}
273-
/>
274250
<Accordion
275251
child={advancedSettings}
276252
name={t("advanced-settings")}

src/components/Switch.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import React, { useEffect, useState } from "react";
44

55
interface SwitchProps {
66
value: boolean;
7+
disabled?: boolean;
78
onChange: (checked: boolean) => void;
89
}
910

10-
const Switch = ({ value, onChange }: SwitchProps) => {
11+
const Switch = ({ value, disabled = false, onChange }: SwitchProps) => {
1112
const [checked, setChecked] = useState(false);
1213

1314
// Due to SSR, we should only change the internal state after the initial render
@@ -23,11 +24,12 @@ const Switch = ({ value, onChange }: SwitchProps) => {
2324
<SwitchPrimitive.Root
2425
className={clsx(
2526
"group",
26-
"radix-state-checked:bg-sky-600",
27-
"radix-state-unchecked:bg-zinc-500 dark:radix-state-unchecked:bg-zinc-800",
28-
"relative inline-flex h-4 w-7 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out",
29-
"focus:outline-none focus-visible:ring focus-visible:ring-sky-500 focus-visible:ring-opacity-75"
27+
"radix-state-checked:bg-sky-600 radix-state-unchecked:bg-zinc-500 dark:radix-state-unchecked:bg-zinc-800",
28+
"relative inline-flex h-4 w-7 flex-shrink-0 rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out",
29+
"focus:outline-none focus-visible:ring focus-visible:ring-sky-500 focus-visible:ring-opacity-75",
30+
disabled ? "cursor-not-allowed opacity-60" : "cursor-pointer "
3031
)}
32+
disabled={disabled}
3133
onCheckedChange={handleChange}
3234
checked={checked}
3335
>

0 commit comments

Comments
 (0)