diff --git a/src/pages/inbox/components/DirectMessageButton/components/DirectMessageModal/DirectMessageModal.module.scss b/src/pages/inbox/components/DirectMessageButton/components/DirectMessageModal/DirectMessageModal.module.scss index 1dbf1f3dee..155096ff76 100644 --- a/src/pages/inbox/components/DirectMessageButton/components/DirectMessageModal/DirectMessageModal.module.scss +++ b/src/pages/inbox/components/DirectMessageButton/components/DirectMessageModal/DirectMessageModal.module.scss @@ -20,10 +20,6 @@ padding: 0 1.5rem; } - .modalContent { - //padding: 0; - } - .modalCloseWrapper { top: 0.5rem; margin: 0; @@ -58,28 +54,6 @@ align-items: center; } -// .control { -// background-color: var(--secondaryBackground); -// color: var(--primaryText); -// } - -// .menuList { -// background-color: var(--tertiaryFill); -// } - -// .option { -// color: var(--primaryText); -// } - -// .indicatorsContainer { -// display: none; -// } - -// .singleValue { -// background-color: var(--secondaryBackground); -// color: var(--primaryText); -// } - .infoText { margin: 1rem 0; padding: 0 1rem; diff --git a/src/pages/inbox/components/DirectMessageButton/components/DirectMessageModal/DirectMessageModal.tsx b/src/pages/inbox/components/DirectMessageButton/components/DirectMessageModal/DirectMessageModal.tsx index 4a3550aa0d..5d413d5139 100644 --- a/src/pages/inbox/components/DirectMessageButton/components/DirectMessageModal/DirectMessageModal.tsx +++ b/src/pages/inbox/components/DirectMessageButton/components/DirectMessageModal/DirectMessageModal.tsx @@ -1,16 +1,7 @@ -import React, { - FC, - ReactElement, - useCallback, - useEffect, - useMemo, - useRef, - useState, -} from "react"; +import React, { FC, ReactElement, useEffect } from "react"; import { useDispatch } from "react-redux"; import Select from "react-select"; import { Modal, UserAvatar } from "@/shared/components"; -import { KeyboardKeys } from "@/shared/constants"; import { useDMUserChatChannel } from "@/shared/hooks/useCases"; import useThemeColor from "@/shared/hooks/useThemeColor"; import { SearchIcon } from "@/shared/icons"; @@ -18,7 +9,6 @@ import { DMUser } from "@/shared/interfaces"; import { Button, Loader } from "@/shared/ui-kit"; import { emptyFunction } from "@/shared/utils"; import { inboxActions } from "@/store/states"; -import { DirectMessageUserItem, SearchInput } from "./components"; import { selectorStyles } from "./components/selectorStyles"; import { useDMUsers } from "./hooks"; import styles from "./DirectMessageModal.module.scss"; @@ -30,6 +20,12 @@ interface DirectMessageModalProps { groupMessage?: boolean; } +interface SelectOption { + value: string; + user: DMUser; + label: JSX.Element; +} + const DirectMessageModal: FC = (props) => { const { isOpen, @@ -39,9 +35,6 @@ const DirectMessageModal: FC = (props) => { } = props; const dispatch = useDispatch(); const { getThemeColor } = useThemeColor(); - const listRef = useRef(null); - //const [searchText, setSearchText] = useState(""); - const [activeItemIndex, setActiveItemIndex] = useState(null); const { loading: areDMUsersLoading, dmUsers, @@ -56,50 +49,6 @@ const DirectMessageModal: FC = (props) => { error: isChannelLoadedWithError, } = useDMUserChatChannel(); - // const filteredDMUsers = useMemo(() => { - // if (!searchText) { - // return dmUsers; - // } - - // const lowerCasedSearchText = searchText.toLowerCase(); - - // return dmUsers.filter((item) => - // item.userName.toLowerCase().startsWith(lowerCasedSearchText), - // ); - // }, [dmUsers, searchText]); - - //const totalUsersAmount = filteredDMUsers.length; - - // const handleArrowUp = useCallback(() => { - // setActiveItemIndex((currentIndex) => { - // if (totalUsersAmount === 0) { - // return null; - // } - // if (currentIndex === null) { - // return totalUsersAmount - 1; - // } - - // const nextIndex = currentIndex - 1; - - // return nextIndex < 0 ? totalUsersAmount - 1 : nextIndex; - // }); - // }, [totalUsersAmount]); - - // const handleArrowDown = useCallback(() => { - // setActiveItemIndex((currentIndex) => { - // if (totalUsersAmount === 0) { - // return null; - // } - // if (currentIndex === null) { - // return 0; - // } - - // const nextIndex = currentIndex + 1; - - // return nextIndex >= totalUsersAmount ? 0 : nextIndex; - // }); - // }, [totalUsersAmount]); - const handleUserItemClick = (item: DMUser) => { fetchDMUserChatChannel(item.uid); }; @@ -110,77 +59,9 @@ const DirectMessageModal: FC = (props) => { return; } - setActiveItemIndex(null); - //setSearchText(""); resetDMUserChatChannel(); }, [isOpen]); - // useEffect(() => { - // setActiveItemIndex(null); - // }, [searchText]); - - useEffect(() => { - if (activeItemIndex !== null) { - const listElement = listRef.current?.children.item(activeItemIndex); - listElement?.scrollIntoView(false); - } - }, [activeItemIndex]); - - // useEffect(() => { - // if (!isOpen) { - // return; - // } - - // const handler = (event: KeyboardEvent) => { - // const key = event.key as KeyboardKeys; - - // switch (key) { - // case KeyboardKeys.ArrowUp: - // handleArrowUp(); - // break; - // case KeyboardKeys.ArrowDown: - // handleArrowDown(); - // break; - // default: - // break; - // } - // }; - - // window.addEventListener("keyup", handler); - - // return () => { - // window.removeEventListener("keyup", handler); - // }; - // }, [isOpen, handleArrowUp, handleArrowDown]); - - // useEffect(() => { - // if (!isOpen) { - // return; - // } - - // const handler = (event: KeyboardEvent) => { - // const key = event.key as KeyboardKeys; - - // if (key !== KeyboardKeys.Enter) { - // return; - // } - - // const item = filteredDMUsers.find( - // (dmUser, index) => index === activeItemIndex, - // ); - - // if (item) { - // handleUserItemClick(item); - // } - // }; - - // window.addEventListener("keyup", handler); - - // return () => { - // window.removeEventListener("keyup", handler); - // }; - // }, [isOpen, activeItemIndex, filteredDMUsers]); - useEffect(() => { if (dmUserChatChannel) { dispatch(inboxActions.addChatChannelItem(dmUserChatChannel)); @@ -206,7 +87,7 @@ const DirectMessageModal: FC = (props) => { return

No users found

; } - const options = dmUsers.map((user) => ({ + const options: SelectOption[] = dmUsers.map((user) => ({ value: user.userName, user: user, label: ( @@ -222,12 +103,18 @@ const DirectMessageModal: FC = (props) => { ), })); + const handleClick = (item: SelectOption) => { + if (!groupMessage) { + handleUserItemClick(item.user); + } else { + console.log("HANDLE GROUP MESSAGE"); + } + }; + return ( <>