From 98402eb11993852ac9fae551804d31d46a839c33 Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Mon, 6 Mar 2023 09:20:41 +0800 Subject: [PATCH] feat: text input for mobile --- src/common/component/MixedInput/index.tsx | 5 +- src/common/component/Send/index.tsx | 78 ++++++++++++----------- src/common/component/TextInput/index.tsx | 48 ++++++++++++++ src/common/component/styled/Textarea.tsx | 3 +- 4 files changed, 93 insertions(+), 41 deletions(-) create mode 100644 src/common/component/TextInput/index.tsx diff --git a/src/common/component/MixedInput/index.tsx b/src/common/component/MixedInput/index.tsx index 70476334..385d24f2 100644 --- a/src/common/component/MixedInput/index.tsx +++ b/src/common/component/MixedInput/index.tsx @@ -17,13 +17,11 @@ import { MentionCombobox } from "@udecode/plate"; import { createComboboxPlugin } from "@udecode/plate-combobox"; -import { useTranslation } from "react-i18next"; import { ReactEditor } from "slate-react"; import useUploadFile from "../../hook/useUploadFile"; import { CONFIG } from "./config"; import User from "../User"; import { useAppSelector } from "../../../app/store"; -import Button from "../styled/Button"; import { isMobile } from "../../utils"; export const TEXT_EDITOR_PREFIX = "_text_editor"; @@ -49,7 +47,7 @@ const Plugins: FC = ({ sendMessages, members = [] }) => { - const { t } = useTranslation(); + // const { getMenuProps, getItemProps } = useComboboxControls(); const [context, to] = id.split("_") as [ctx, number]; const { addStageFile } = useUploadFile({ context, id: to }); @@ -229,7 +227,6 @@ const Plugins: FC = ({ /> ) : null} - ); }; diff --git a/src/common/component/Send/index.tsx b/src/common/component/Send/index.tsx index 9e0370c4..f4dbb68d 100644 --- a/src/common/component/Send/index.tsx +++ b/src/common/component/Send/index.tsx @@ -17,6 +17,7 @@ import MixedInput, { useMixedEditor } from "../MixedInput"; import useDraft from "../../hook/useDraft"; import useUploadFile from "../../hook/useUploadFile"; import { useAppDispatch, useAppSelector } from "../../../app/store"; +import TextInput from "../TextInput"; const Modes = { text: "text", @@ -138,45 +139,50 @@ const Send: FC = ({ context == "channel" ? (channelsData[id]?.is_public ? uids : channelsData[id]?.members) : []; const isMarkdownMode = mode == Modes.markdown; return ( -
- {replying_mid && } - {mode == Modes.text && } + <> + {/* mobile input */} + + {/* PC input */} + -
+ ); }; diff --git a/src/common/component/TextInput/index.tsx b/src/common/component/TextInput/index.tsx new file mode 100644 index 00000000..4754a827 --- /dev/null +++ b/src/common/component/TextInput/index.tsx @@ -0,0 +1,48 @@ +import { ChangeEvent, useState } from 'react'; +import { useTranslation } from 'react-i18next'; +import TextareaAutoSize from "react-textarea-autosize"; + +import Button from "../styled/Button"; + +type Props = { + placeholder: string, + sendMessage: any +} +const TextInput = ({ sendMessage, placeholder }: Props) => { + const { t } = useTranslation(); + const [currMsg, setCurrMsg] = useState(""); + const handleMsgChange = (evt: ChangeEvent) => { + setCurrMsg(evt.target.value); + }; + const handleSend = () => { + if (!currMsg) return; + // todo + const msg = [{ type: "text", content: currMsg }]; + sendMessage(msg); + setCurrMsg(""); + }; + return ( +
+ + e.currentTarget.setSelectionRange( + e.currentTarget.value.length, + e.currentTarget.value.length + ) + } + // ref={inputRef} + className="p-1 w-full min-h-[28px] resize-none bg-transparent text-gray-800 dark:text-white text-sm break-all" + maxRows={8} + minRows={1} + // onKeyDown={handleInputKeydown} + onChange={handleMsgChange} + value={currMsg} + placeholder={placeholder} + /> + +
+ ); +}; + +export default TextInput; \ No newline at end of file diff --git a/src/common/component/styled/Textarea.tsx b/src/common/component/styled/Textarea.tsx index 3cac036a..0420156f 100644 --- a/src/common/component/styled/Textarea.tsx +++ b/src/common/component/styled/Textarea.tsx @@ -2,7 +2,8 @@ import { forwardRef, TextareaHTMLAttributes } from "react"; type Props = TextareaHTMLAttributes const StyledTextarea = forwardRef(({ className, ...rest }: Props, ref) => { - return