This commit is contained in:
Zhang Minghan 2023-09-24 09:31:06 +08:00
parent f57b5710a0
commit 3d165bf42d

View File

@ -27,6 +27,7 @@ function Wrapper({ onSend }: WrapperProps) {
const [ data, setData ] = useState<string>(""); const [ data, setData ] = useState<string>("");
const [ quota, setQuota ] = useState<number>(0); const [ quota, setQuota ] = useState<number>(0);
const model = useSelector(selectModel); const model = useSelector(selectModel);
const modelRef = useRef(model);
const auth = useSelector(selectAuthenticated); const auth = useSelector(selectAuthenticated);
const { toast } = useToast(); const { toast } = useToast();
@ -75,12 +76,14 @@ function Wrapper({ onSend }: WrapperProps) {
} }
useEffect(() => { useEffect(() => {
ref.current && (ref.current as HTMLInputElement).focus(); const target = ref.current as HTMLInputElement | null;
ref.current && (ref.current as HTMLInputElement).removeEventListener("keydown", () => {}); if (!target) return;
ref.current && target.focus();
(ref.current as HTMLInputElement).addEventListener("keydown", (e) => { target.removeEventListener("keydown", () => {});
target.addEventListener("keydown", (e) => {
if (e.key === "Enter") { if (e.key === "Enter") {
handleSend(model); // cannot use model here, because model is not updated
handleSend(modelRef.current);
} }
}); });
@ -88,6 +91,11 @@ function Wrapper({ onSend }: WrapperProps) {
ref.current && (ref.current as HTMLInputElement).removeEventListener("keydown", () => {}); ref.current && (ref.current as HTMLInputElement).removeEventListener("keydown", () => {});
} }
}, [ref]); }, [ref]);
useEffect(() => {
modelRef.current = model;
}, [model]);
return ( return (
<div className={`generation-wrapper`}> <div className={`generation-wrapper`}>
{ {