shellphone.app/app/features/messages/components/new-message-area.tsx

47 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-05-19 22:55:02 +00:00
import { useEffect, useRef } from "react";
import { Form, useTransition } from "@remix-run/react";
import { IoSend } from "react-icons/io5";
2021-07-31 14:33:18 +00:00
2022-05-19 22:55:02 +00:00
function NewMessageArea() {
const transition = useTransition();
const formRef = useRef<HTMLFormElement>(null);
const textFieldRef = useRef<HTMLTextAreaElement>(null);
const isSendingMessage = transition.state === "submitting";
2021-08-01 07:40:18 +00:00
2022-05-19 22:55:02 +00:00
useEffect(() => {
if (isSendingMessage) {
formRef.current?.reset();
textFieldRef.current?.focus();
}
}, [isSendingMessage]);
2021-07-31 14:33:18 +00:00
return (
2022-05-19 22:55:02 +00:00
<Form
ref={formRef}
method="post"
className="absolute bottom-0 w-screen backdrop-filter backdrop-blur-xl bg-white bg-opacity-75 border-t flex flex-row h-14 mb-16 p-2 pr-0"
replace
2021-07-31 14:33:18 +00:00
>
<textarea
2022-05-19 22:55:02 +00:00
ref={textFieldRef}
2022-05-14 10:22:06 +00:00
name="content"
2022-05-19 22:55:02 +00:00
className="resize-none rounded-full flex-1"
style={{
scrollbarWidth: "none",
}}
2021-07-31 14:33:18 +00:00
autoCapitalize="sentences"
autoCorrect="on"
placeholder="Text message"
rows={1}
spellCheck
2022-05-14 10:22:06 +00:00
required
2021-07-31 14:33:18 +00:00
/>
<button type="submit">
<IoSend className="h-8 w-8 pl-1 pr-2" />
2021-07-31 14:33:18 +00:00
</button>
2022-05-19 22:55:02 +00:00
</Form>
);
2022-05-19 22:55:02 +00:00
}
2021-08-01 07:40:18 +00:00
export default NewMessageArea;