From 648d60b9329664686d528547b790e907501a807c Mon Sep 17 00:00:00 2001 From: AbdelruhmanSamy Date: Sat, 21 Dec 2024 17:43:16 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=92=84=20(messaging):=20Mentions=20UI?= =?UTF-8?q?=20almost=20finished?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/components/ExpandingTextArea.tsx | 105 ++++++++++++------ app/src/features/chats/ChatInputIcons.tsx | 8 +- app/src/features/chats/ChatItem.tsx | 4 +- app/src/features/chats/SenderName.tsx | 2 +- app/src/features/chats/Topbar.tsx | 2 +- .../{useChatMember.ts => useChatMembers.ts} | 1 + app/src/features/chats/hooks/useChats.ts | 1 + .../features/chats/hooks/useMentionList.ts | 20 ++++ app/src/features/chats/utils/helpers.ts | 2 +- app/src/utils/renderWithHighlight.tsx | 18 +-- app/src/utils/renderWithMentions.tsx | 43 +++++++ 11 files changed, 158 insertions(+), 48 deletions(-) rename app/src/features/chats/hooks/{useChatMember.ts => useChatMembers.ts} (99%) create mode 100644 app/src/features/chats/hooks/useMentionList.ts create mode 100644 app/src/utils/renderWithMentions.tsx diff --git a/app/src/components/ExpandingTextArea.tsx b/app/src/components/ExpandingTextArea.tsx index 86a1ca4d..526bdae2 100644 --- a/app/src/components/ExpandingTextArea.tsx +++ b/app/src/components/ExpandingTextArea.tsx @@ -1,59 +1,96 @@ import { useEffect, useRef } from "react"; import styled from "styled-components"; +import { MentionsInput, Mention } from "react-mentions"; +import useMentionList from "@features/chats/hooks/useMentionList"; -const Textarea = styled.textarea` - outline: none; - border: none; - - flex: 1; - align-self: center; - - caret-color: var(--accent-color); +const StyledMentionsInput = styled.div` + width: 100%; + max-width: 27rem; color: var(--color-text); - - resize: none; - overflow: hidden; - - font-size: 1rem; - line-height: 1.5; - padding: 0.25rem; - - max-height: 300px; `; type PropsType = { input: string; setInput: (value: string) => void; - onKeyDown?: (e: React.KeyboardEvent) => void; + onKeyDown?: ( + e: + | React.KeyboardEvent + | React.KeyboardEvent + ) => void; }; function ExpandingTextArea({ input, setInput, onKeyDown }: PropsType) { - const ref = useRef(null); + const textareaRef = useRef(null); + + const { filteredMembers } = useMentionList(); function handleInput() { - if (ref.current) { - ref.current.style.height = "auto"; - ref.current.style.height = `${ref.current.scrollHeight}px`; + if (textareaRef.current) { + textareaRef.current.style.height = "auto"; + textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`; } } + useEffect(() => { - if (ref.current) { - if (ref.current.value === "" || input === "") { - ref.current.style.height = "32px"; + if (textareaRef.current) { + if (textareaRef.current.value === "" || input === "") { + textareaRef.current.style.height = "32px"; } } }, [input]); + console.log(filteredMembers); + return ( -