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

55 lines
1.3 KiB
TypeScript
Raw Permalink Normal View History

2022-05-20 00:45:07 +00:00
import type { FunctionComponent } from "react";
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-20 00:45:07 +00:00
type Props = {
onSend?: () => void;
recipient: string;
};
const NewMessageArea: FunctionComponent<Props> = ({ onSend, recipient }) => {
2022-05-19 22:55:02 +00:00
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();
2022-05-20 00:45:07 +00:00
onSend?.();
2022-05-19 22:55:02 +00:00
}
2022-05-20 00:45:07 +00:00
}, [isSendingMessage, onSend]);
2021-07-31 14:33:18 +00:00
return (
2022-05-19 22:55:02 +00:00
<Form
ref={formRef}
2022-05-20 00:45:07 +00:00
action={`/messages/${recipient}`}
2022-05-19 22:55:02 +00:00
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">
<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-20 00:45:07 +00:00
};
2021-08-01 07:40:18 +00:00
export default NewMessageArea;