diff --git a/package.json b/package.json index 50f980b..b943152 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "pageassist", "displayName": "Page Assist - A Web UI for Local AI Models", - "version": "1.0.4", + "version": "1.0.5", "description": "Use your locally running AI models to assist you in your web browsing.", "author": "n4ze3m", "scripts": { diff --git a/src/components/Option/Playground/PlaygroundForm.tsx b/src/components/Option/Playground/PlaygroundForm.tsx index 459c971..a1a6041 100644 --- a/src/components/Option/Playground/PlaygroundForm.tsx +++ b/src/components/Option/Playground/PlaygroundForm.tsx @@ -19,23 +19,21 @@ export const PlaygroundForm = ({ dropedFile }: Props) => { const textareaRef = React.useRef(null) const inputRef = React.useRef(null) - const resetHeight = () => { - const textarea = textareaRef.current - if (textarea) { - textarea.style.height = "auto" + const textAreaFocus = () => { + if (textareaRef.current) { + textareaRef.current.focus() } } const form = useForm({ initialValues: { message: "", image: "" - } + }, + }) React.useEffect(() => { - if (textareaRef.current) { - textareaRef.current.focus() - } + textAreaFocus() }, []) const onInputChange = async ( @@ -85,9 +83,13 @@ export const PlaygroundForm = ({ dropedFile }: Props) => { const { mutateAsync: sendMessage } = useMutation({ mutationFn: onSubmit, onSuccess: () => { + textAreaFocus() queryClient.invalidateQueries({ queryKey: ["fetchChatHistory"] }) + }, + onError: (error) => { + textAreaFocus() } }) @@ -133,11 +135,12 @@ export const PlaygroundForm = ({ dropedFile }: Props) => { } } form.reset() - resetHeight() + textAreaFocus() await sendMessage({ image: value.image, message: value.message.trim() }) + })} className="shrink-0 flex-grow flex flex-col items-center "> { } } form.reset() - resetHeight() + textAreaFocus() await sendMessage({ image: value.image, message: value.message.trim() diff --git a/src/components/Sidepanel/Chat/form.tsx b/src/components/Sidepanel/Chat/form.tsx index 1c733f9..6e1d820 100644 --- a/src/components/Sidepanel/Chat/form.tsx +++ b/src/components/Sidepanel/Chat/form.tsx @@ -19,10 +19,9 @@ export const SidepanelForm = ({ dropedFile }: Props) => { const inputRef = React.useRef(null) const { sendWhenEnter, setSendWhenEnter } = useWebUI() - const resetHeight = () => { - const textarea = textareaRef.current - if (textarea) { - textarea.style.height = "auto" + const textAreaFocus = () => { + if (textareaRef.current) { + textareaRef.current.focus() } } const form = useForm({ @@ -64,7 +63,13 @@ export const SidepanelForm = ({ dropedFile }: Props) => { } }, [transcript]) const { mutateAsync: sendMessage, isPending: isSending } = useMutation({ - mutationFn: onSubmit + mutationFn: onSubmit, + onSuccess: () => { + textAreaFocus() + }, + onError: (error) => { + textAreaFocus() + } }) return ( @@ -109,7 +114,7 @@ export const SidepanelForm = ({ dropedFile }: Props) => { } } form.reset() - resetHeight() + textAreaFocus() await sendMessage({ image: value.image, message: value.message.trim() @@ -155,7 +160,7 @@ export const SidepanelForm = ({ dropedFile }: Props) => { } } form.reset() - resetHeight() + textAreaFocus() await sendMessage({ image: value.image, message: value.message.trim()