Files
DeepTutor/web/components/visualize/VisualizeConfigPanel.tsx
jiakeboge e18dfb311f perf(web): decouple chat input state to resolve lag in long conversations (#351) (#360)
Extract `ComposerInput` component to isolate frequent keystroke renders.
Refactor `ChatComposer` to use `hasContent` flag instead of full `input` state.
 Apply `React.memo` to heavy config panels (Quiz, Math, Research, Visualize).
Stabilize parent callbacks in `ChatPage` using `useCallback`.
Fix residual syntax errors and missing `canSend` definition in composer.
Address HKUDS/DeepTutor#351 by implementing deep state colocation.
2026-04-22 17:06:08 +08:00

55 lines
1.5 KiB
TypeScript

"use client";
import { memo } from "react";
import { useTranslation } from "react-i18next";
import {
summarizeVisualizeConfig,
type VisualizeFormConfig,
} from "@/lib/visualize-types";
import {
CollapsibleConfigSection,
Field,
INPUT_CLS,
} from "@/components/chat/home/composer-field";
interface VisualizeConfigPanelProps {
value: VisualizeFormConfig;
onChange: (next: VisualizeFormConfig) => void;
collapsed: boolean;
onToggleCollapsed: () => void;
}
export default memo(function VisualizeConfigPanel({
value,
onChange,
collapsed,
onToggleCollapsed,
}: VisualizeConfigPanelProps) {
const { t } = useTranslation();
return (
<CollapsibleConfigSection
collapsed={collapsed}
summary={summarizeVisualizeConfig(value, t)}
onToggleCollapsed={onToggleCollapsed}
bodyClassName="flex flex-wrap items-end gap-x-3 gap-y-2 px-3.5 pb-2.5"
>
<Field label={t("Render Mode")} width="w-[120px]">
<select
value={value.render_mode}
onChange={(e) =>
onChange({ ...value, render_mode: e.target.value as VisualizeFormConfig["render_mode"] })
}
className={`${INPUT_CLS} w-full`}
>
<option value="auto">{t("Auto")}</option>
<option value="chartjs">{t("Chart.js")}</option>
<option value="svg">{t("SVG")}</option>
<option value="mermaid">{t("Mermaid")}</option>
<option value="html">{t("HTML")}</option>
</select>
</Field>
</CollapsibleConfigSection>
);
});