2022-05-19 22:55:02 +00:00
|
|
|
import { useEffect, useRef } from "react";
|
|
|
|
import { Form, useTransition } from "@remix-run/react";
|
2021-09-07 20:59:38 +00:00
|
|
|
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"
|
2022-05-19 23:05:06 +00:00
|
|
|
className="absolute bottom-0 w-screen backdrop-filter backdrop-blur-xl bg-white bg-opacity-75 border-t flex flex-row p-2 pr-0"
|
2022-05-19 22:55:02 +00:00
|
|
|
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">
|
2021-09-07 20:59:38 +00:00
|
|
|
<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>
|
2021-07-31 15:57:43 +00:00
|
|
|
);
|
2022-05-19 22:55:02 +00:00
|
|
|
}
|
2021-08-01 07:40:18 +00:00
|
|
|
|
|
|
|
export default NewMessageArea;
|