From 97532cc88db035179aa5eff6e5dc87bb46d3f22c Mon Sep 17 00:00:00 2001 From: Szymon Szlachtowicz <38212223+Szymx95@users.noreply.github.com> Date: Fri, 7 Jan 2022 14:21:30 +0100 Subject: [PATCH] Refactor channels (#177) --- .../src/components/Channels/Channels.tsx | 57 ++++++++----------- .../src/components/Channels/EmptyChannel.tsx | 46 ++++++++++----- .../src/hooks/messenger/useMessenger.ts | 9 +++ 3 files changed, 65 insertions(+), 47 deletions(-) diff --git a/packages/react-chat/src/components/Channels/Channels.tsx b/packages/react-chat/src/components/Channels/Channels.tsx index 3b4f6c12..fc08ca31 100644 --- a/packages/react-chat/src/components/Channels/Channels.tsx +++ b/packages/react-chat/src/components/Channels/Channels.tsx @@ -1,4 +1,4 @@ -import React, { useEffect } from "react"; +import React from "react"; import styled from "styled-components"; import { ChatState, useChatState } from "../../contexts/chatStateProvider"; @@ -45,43 +45,36 @@ function GenerateChannels({ type, onCommunityClick }: GenerateChannelsProps) { ); } -export function Channels({ onCommunityClick }: ChannelsProps) { - const { clearNotifications, clearMentions, notifications, activeChannel } = - useMessengerContext(); - useEffect(() => { - if (activeChannel) { - if (notifications[activeChannel.id] > 0) { - clearNotifications(activeChannel.id); - clearMentions(activeChannel.id); - } - } - }, [notifications, activeChannel]); - const setChatState = useChatState()[1]; - const identity = useIdentity(); +type ChatsListProps = { + onCommunityClick?: () => void; +}; +function ChatsSideBar({ onCommunityClick }: ChatsListProps) { + const setChatState = useChatState()[1]; + return ( + <> + + Chat + setChatState(ChatState.ChatCreation)}> + + + + + + + + + ); +} + +export function Channels({ onCommunityClick }: ChannelsProps) { + const identity = useIdentity(); return ( {identity ? ( - <> - - Chat - setChatState(ChatState.ChatCreation)}> - - - - - - - - + ) : ( )} diff --git a/packages/react-chat/src/components/Channels/EmptyChannel.tsx b/packages/react-chat/src/components/Channels/EmptyChannel.tsx index f4bbac45..a33d5f21 100644 --- a/packages/react-chat/src/components/Channels/EmptyChannel.tsx +++ b/packages/react-chat/src/components/Channels/EmptyChannel.tsx @@ -9,11 +9,11 @@ import { textMediumStyles } from "../Text"; import { ChannelInfo, ChannelLogo, ChannelName } from "./Channel"; -type EmptyChannelProps = { +type ChannelBeggingTextProps = { channel: ChannelData; }; -export function EmptyChannel({ channel }: EmptyChannelProps) { +function ChannelBeggingText({ channel }: ChannelBeggingTextProps) { const identity = useIdentity(); const { contacts } = useMessengerContext(); const members = useMemo(() => { @@ -25,23 +25,18 @@ export function EmptyChannel({ channel }: EmptyChannelProps) { } return []; }, [channel, contacts]); - return ( - - - - {" "} - {!channel.icon && channel.name.slice(0, 1).toUpperCase()} - - - - {channel.type === "dm" ? ( + switch (channel.type) { + case "dm": + return ( Any messages you send here are encrypted and can only be read by you and
{channel.name.slice(0, 10)}.
- ) : channel.type === "group" ? ( + ); + case "group": + return ( {identity && {utils.bufToHex(identity.publicKey)}}{" "} created a group with{" "} @@ -52,11 +47,32 @@ export function EmptyChannel({ channel }: EmptyChannelProps) { ))} - ) : ( + ); + case "channel": + return ( Welcome to the beginning of the #{channel.name} channel! - )} + ); + } + return null; +} + +type EmptyChannelProps = { + channel: ChannelData; +}; + +export function EmptyChannel({ channel }: EmptyChannelProps) { + return ( + + + + {" "} + {!channel.icon && channel.name.slice(0, 1).toUpperCase()} + + + + ); } diff --git a/packages/react-chat/src/hooks/messenger/useMessenger.ts b/packages/react-chat/src/hooks/messenger/useMessenger.ts index d17ffd65..b980082d 100644 --- a/packages/react-chat/src/hooks/messenger/useMessenger.ts +++ b/packages/react-chat/src/hooks/messenger/useMessenger.ts @@ -228,6 +228,15 @@ export function useMessenger( [messenger, groupChat, activeChannel] ); + useEffect(() => { + if (activeChannel) { + if (notifications[activeChannel.id] > 0) { + clearNotifications(activeChannel.id); + clearMentions(activeChannel.id); + } + } + }, [notifications, activeChannel]); + return { messenger, messages,