From cded53a4681c7a162fa147c8c53c3216a114f583 Mon Sep 17 00:00:00 2001 From: Maria Rushkova <66270386+mrushkova@users.noreply.github.com> Date: Thu, 3 Feb 2022 15:12:31 +0100 Subject: [PATCH] UI fixes changes (#218) --- .../src/components/Channels/Channels.tsx | 2 +- .../src/components/Chat/ChatTopbar.tsx | 2 +- .../src/components/CommunityChatRoom.tsx | 9 +- .../src/components/Form/ChannelMenu.tsx | 26 +++-- .../src/components/Form/DropdownMenu.tsx | 6 +- .../src/components/Form/ImageMenu.tsx | 20 ++-- .../src/components/Form/MessageMenu.tsx | 94 +++++++++---------- .../components/Messages/MessageReactions.tsx | 12 ++- .../src/components/Messages/UiMessage.tsx | 1 - 9 files changed, 98 insertions(+), 74 deletions(-) diff --git a/packages/react-chat/src/components/Channels/Channels.tsx b/packages/react-chat/src/components/Channels/Channels.tsx index e0e5428d..9fdc2043 100644 --- a/packages/react-chat/src/components/Channels/Channels.tsx +++ b/packages/react-chat/src/components/Channels/Channels.tsx @@ -64,7 +64,7 @@ function ChatsSideBar({ onCommunityClick, setEditGroup }: ChatsListProps) { return ( <> - Chat + Messages setChatState(ChatState.ChatCreation)}> diff --git a/packages/react-chat/src/components/Chat/ChatTopbar.tsx b/packages/react-chat/src/components/Chat/ChatTopbar.tsx index bc2090fc..32d521a7 100644 --- a/packages/react-chat/src/components/Chat/ChatTopbar.tsx +++ b/packages/react-chat/src/components/Chat/ChatTopbar.tsx @@ -104,7 +104,7 @@ export function ChatTopbar({ - {!narrow && ( + {!narrow && activeChannel.type !== "dm" && ( diff --git a/packages/react-chat/src/components/CommunityChatRoom.tsx b/packages/react-chat/src/components/CommunityChatRoom.tsx index b74f9ce7..9208ad60 100644 --- a/packages/react-chat/src/components/CommunityChatRoom.tsx +++ b/packages/react-chat/src/components/CommunityChatRoom.tsx @@ -2,6 +2,7 @@ import React, { useState } from "react"; import styled from "styled-components"; import { ChatState, useChatState } from "../contexts/chatStateProvider"; +import { useMessengerContext } from "../contexts/messengerProvider"; import { useNarrow } from "../contexts/narrowProvider"; import { Channels } from "./Channels/Channels"; @@ -49,6 +50,8 @@ export function CommunityChatRoom() { const [showMembers, setShowMembers] = useState(false); const [editGroup, setEditGroup] = useState(false); const narrow = useNarrow(); + const { activeChannel } = useMessengerContext(); + return ( {!narrow && ( @@ -66,7 +69,11 @@ export function CommunityChatRoom() { setEditGroup={setEditGroup} /> )} - {showMembers && !narrow && state === ChatState.ChatBody && } + {showMembers && + !narrow && + state === ChatState.ChatBody && + activeChannel && + activeChannel.type !== "dm" && } {state === ChatState.ChatCreation && } diff --git a/packages/react-chat/src/components/Form/ChannelMenu.tsx b/packages/react-chat/src/components/Form/ChannelMenu.tsx index 725396dc..d5f4e660 100644 --- a/packages/react-chat/src/components/Form/ChannelMenu.tsx +++ b/packages/react-chat/src/components/Form/ChannelMenu.tsx @@ -1,9 +1,10 @@ -import React, { useMemo, useState } from "react"; +import React, { useMemo, useRef, useState } from "react"; import styled from "styled-components"; import { useMessengerContext } from "../../contexts/messengerProvider"; import { useModal } from "../../contexts/modalProvider"; import { useNarrow } from "../../contexts/narrowProvider"; +import { useClickOutside } from "../../hooks/useClickOutside"; import { useContextMenu } from "../../hooks/useContextMenu"; import { ChannelData } from "../../models/ChannelData"; import { AddMemberIcon } from "../Icons/AddMemberIcon"; @@ -56,10 +57,13 @@ export const ChannelMenu = ({ [setShowChannelMenu, setShowSideMenu] ); + const ref = useRef(null); + useClickOutside(ref, () => setShowMenu(false)); + if (showMenu || setShowChannelMenu) { return ( - - {narrow && !className && ( + + {narrow && channel.type !== "dm" && ( { if (switchMemberList) switchMemberList(); @@ -106,7 +110,10 @@ export const ChannelMenu = ({ { if (channel.isMuted) { - channelsDispatch({ type: "ToggleMuted", payload: channel.id }); + channelsDispatch({ + type: "ToggleMuted", + payload: channel.id, + }); setShowMenu(false); } }} @@ -121,12 +128,15 @@ export const ChannelMenu = ({ {!channel.isMuted && } {(channel.isMuted ? "Unmute" : "Mute") + - (channel.type === "group" ? " Group" : " CommunityChatRoom")} + (channel.type === "group" ? " Group" : "Chat")} {!channel.isMuted && showSubmenu && ( - channelsDispatch({ type: "ToggleMuted", payload: channel.id }) + channelsDispatch({ + type: "ToggleMuted", + payload: channel.id, + }) } className={className} /> @@ -155,9 +165,7 @@ export const ChannelMenu = ({ )} - {channel.type === "group" - ? "Leave Group" - : "Delete CommunityChatRoom"} + {channel.type === "group" ? "Leave Group" : "Delete Chat"} )} diff --git a/packages/react-chat/src/components/Form/DropdownMenu.tsx b/packages/react-chat/src/components/Form/DropdownMenu.tsx index f799dffb..0542cf45 100644 --- a/packages/react-chat/src/components/Form/DropdownMenu.tsx +++ b/packages/react-chat/src/components/Form/DropdownMenu.tsx @@ -7,15 +7,19 @@ type DropdownMenuProps = { children: ReactNode; className?: string; style?: { top: number; left: number }; + menuRef?: React.MutableRefObject; + id?: string; }; export function DropdownMenu({ children, className, style, + menuRef, + id, }: DropdownMenuProps) { return ( - + {children} ); diff --git a/packages/react-chat/src/components/Form/ImageMenu.tsx b/packages/react-chat/src/components/Form/ImageMenu.tsx index 3aba2e2c..4fa1a934 100644 --- a/packages/react-chat/src/components/Form/ImageMenu.tsx +++ b/packages/react-chat/src/components/Form/ImageMenu.tsx @@ -21,17 +21,15 @@ export const ImageMenu = ({ imageId }: ImageMenuProps) => { useClickOutside(ref, () => setShowMenu(false)); return showMenu ? ( -
- - copyImg(imageId)}> - Copy image - - downloadImg(imageId)}> - - Download image - - -
+ + copyImg(imageId)}> + Copy image + + downloadImg(imageId)}> + + Download image + + ) : ( <> ); diff --git a/packages/react-chat/src/components/Form/MessageMenu.tsx b/packages/react-chat/src/components/Form/MessageMenu.tsx index eb092c9c..476a5e2e 100644 --- a/packages/react-chat/src/components/Form/MessageMenu.tsx +++ b/packages/react-chat/src/components/Form/MessageMenu.tsx @@ -53,64 +53,62 @@ export const MessageMenu = ({ ); return userPK && showMenu ? ( -
- - - + + + + + + { + setReply({ + sender: message.sender, + content: message.content, + image: message.image, + id: message.id, + }); + setShowMenu(false); + }} + > + + Reply - - { - setReply({ - sender: message.sender, - content: message.content, - image: message.image, - id: message.id, - }); - setShowMenu(false); - }} - > - - Reply - - {userMessage && ( - { - setShowMenu(false); - }} - > - - Edit - - )} - {activeChannel?.type !== "channel" && ( - { - setShowMenu(false); - }} - > - - Pin - - )} - {userMessage && ( { setShowMenu(false); }} > - - Delete message + + Edit )} - -
+ {activeChannel?.type !== "channel" && ( + { + setShowMenu(false); + }} + > + + Pin + + )} + + {userMessage && ( + { + setShowMenu(false); + }} + > + + Delete message + + )} + ) : ( <> ); diff --git a/packages/react-chat/src/components/Messages/MessageReactions.tsx b/packages/react-chat/src/components/Messages/MessageReactions.tsx index 19b13a75..ce79b23a 100644 --- a/packages/react-chat/src/components/Messages/MessageReactions.tsx +++ b/packages/react-chat/src/components/Messages/MessageReactions.tsx @@ -1,5 +1,5 @@ import { BaseEmoji, Emoji } from "emoji-mart"; -import React from "react"; +import React, { useCallback } from "react"; import styled from "styled-components"; import { ReactionButton } from "../Reactions/ReactionButton"; @@ -16,12 +16,22 @@ export function MessageReactions({ const isMyReactionIncluded = (emoji: BaseEmoji) => messageReactions.includes(emoji); // temporary function while message reactions are not added to waku + const handleReaction = useCallback( + (emoji: BaseEmoji) => { + messageReactions.find((e) => e === emoji) + ? setMessageReactions((prev) => prev.filter((e) => e != emoji)) + : setMessageReactions((prev) => [...prev, emoji]); + }, + [messageReactions, setMessageReactions] + ); + return ( {messageReactions.map((reaction) => ( handleReaction(reaction)} >

1

diff --git a/packages/react-chat/src/components/Messages/UiMessage.tsx b/packages/react-chat/src/components/Messages/UiMessage.tsx index 06bccac3..d5748941 100644 --- a/packages/react-chat/src/components/Messages/UiMessage.tsx +++ b/packages/react-chat/src/components/Messages/UiMessage.tsx @@ -107,7 +107,6 @@ export function UiMessage({ if (identity) setShowMenu((e) => !e); }} disabled={!identity} - ref={ref} > {" "}