Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move mode toggle out of settings #469

Merged
merged 5 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: move mode toggle out of settings
  • Loading branch information
Jshen123 committed May 7, 2023
commit 70f307f7c6c56f0feda6ad1824b332700a10d99e
50 changes: 39 additions & 11 deletions src/components/ChatWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
TASK_STATUS_EXECUTING,
TASK_STATUS_COMPLETED,
TASK_STATUS_FINAL,
AUTOMATIC_MODE,
PAUSE_MODE,
} from "../types/agentTypes";
import clsx from "clsx";
Expand Down Expand Up @@ -57,10 +58,13 @@ const ChatWindow = ({
}: ChatWindowProps) => {
const [t] = useTranslation();
const [hasUserScrolled, setHasUserScrolled] = useState(false);

const scrollRef = useRef<HTMLDivElement>(null);
const isAgentPaused = useAgentStore.use.isAgentPaused();
const agentMode = useAgentStore.use.agentMode();
const agent = useAgentStore.use.agent();
const [isPauseMode, setIsPauseMode] = useState(agentMode === PAUSE_MODE);
const updateAgentMode = useAgentStore.use.updateAgentMode();
const isWebSearchEnabled = useAgentStore.use.isWebSearchEnabled();
const setIsWebSearchEnabled = useAgentStore.use.setIsWebSearchEnabled();

Expand Down Expand Up @@ -93,6 +97,11 @@ const ChatWindow = ({
}
};

const handleUpdateAgentMode = (value: boolean) => {
setIsPauseMode(value);
updateAgentMode(value ? PAUSE_MODE : AUTOMATIC_MODE);
};

return (
<div
className={
Expand Down Expand Up @@ -167,22 +176,41 @@ const ChatWindow = ({
)}
</div>
{displaySettings && (
<>
<div className="flex items-center justify-center">
<div className="m-1 flex items-center gap-2 rounded-lg border-[2px] border-white/20 bg-zinc-700 px-2 py-1">
<p className="font-mono text-sm">Web search</p>
<Switch
value={isWebSearchEnabled}
onChange={handleChangeWebSearch}
/>
</div>
</div>
</>
<div className="flex flex-col items-center justify-center md:flex-row">
<SwitchContainer label="Web Search">
<Switch
value={isWebSearchEnabled}
onChange={handleChangeWebSearch}
/>
</SwitchContainer>
<SwitchContainer label={agentMode}>
<Switch
disabled={agent !== null}
value={isPauseMode}
onChange={handleUpdateAgentMode}
/>
</SwitchContainer>
</div>
)}
</div>
);
};

const SwitchContainer = ({
label,
children,
}: {
label: string;
children: React.ReactNode;
}) => {
return (
<div className="m-1 flex w-44 items-center justify-center gap-2 rounded-lg border-[2px] border-white/20 bg-zinc-700 px-2 py-1">
<p className="font-mono text-sm">{label}</p>
{children}
</div>
);
};

const ExampleAgentButton = ({
name,
children,
Expand Down
32 changes: 0 additions & 32 deletions src/components/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
FaExclamationCircle,
FaSyncAlt,
FaCoins,
FaTachometerAlt,
} from "react-icons/fa";
import Dialog from "./Dialog";
import Input from "./Input";
Expand All @@ -16,8 +15,6 @@ import Accordion from "./Accordion";
import type { ModelSettings, SettingModel } from "../utils/types";
import LanguageCombobox from "./LanguageCombobox";
import clsx from "clsx";
import { AUTOMATIC_MODE, PAUSE_MODE } from "../types/agentTypes";
import { useAgentStore } from "./stores";
import { useTranslation } from "next-i18next";

export const SettingsDialog: React.FC<{
Expand All @@ -29,9 +26,6 @@ export const SettingsDialog: React.FC<{
...customSettings.settings,
});
const [t] = useTranslation();
const agent = useAgentStore.use.agent();
const agentMode = useAgentStore.use.agentMode();
const updateAgentMode = useAgentStore.use.updateAgentMode();

useEffect(() => {
setSettings(customSettings.settings);
Expand Down Expand Up @@ -244,32 +238,6 @@ export const SettingsDialog: React.FC<{
attributes={{ options: GPT_MODEL_NAMES }}
disabled={disabled}
/>
<Input
left={
<>
<FaTachometerAlt />
<span className="ml-2">{`${t("LABEL_MODE", {
ns: "settings",
})}`}</span>
</>
}
value={agentMode}
disabled={agent !== null}
onChange={() => null}
setValue={updateAgentMode as (agentMode: string) => void}
type="combobox"
toolTipProperties={{
message: `${t("AUTOMATIC_MODE", { ns: "settings" })} ${t(
"AUTOMATIC_MODE_DESCRIPTION",
{ ns: "settings" }
)} \n\n${t("PAUSE_MODE", { ns: "settings" })}: ${t(
"PAUSE_MODE_DESCRIPTION",
{ ns: "settings" }
)}`,
disabled: false,
}}
attributes={{ options: [AUTOMATIC_MODE, PAUSE_MODE] }}
/>
<Accordion
child={advancedSettings}
name={t("ADVANCED_SETTINGS", { ns: "settings" })}
Expand Down
4 changes: 3 additions & 1 deletion src/components/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import React, { useEffect, useState } from "react";

interface SwitchProps {
value: boolean;
disabled?: boolean;
onChange: (checked: boolean) => void;
}

const Switch = ({ value, onChange }: SwitchProps) => {
const Switch = ({ value, disabled = false, onChange }: SwitchProps) => {
const [checked, setChecked] = useState(false);

// Due to SSR, we should only change the internal state after the initial render
Expand All @@ -28,6 +29,7 @@ const Switch = ({ value, onChange }: SwitchProps) => {
"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",
"focus:outline-none focus-visible:ring focus-visible:ring-sky-500 focus-visible:ring-opacity-75"
)}
disabled={disabled}
onCheckedChange={handleChange}
checked={checked}
>
Expand Down