diff --git a/packages/react-chat-example/src/index.tsx b/packages/react-chat-example/src/index.tsx index 5792914..13c8116 100644 --- a/packages/react-chat-example/src/index.tsx +++ b/packages/react-chat-example/src/index.tsx @@ -23,7 +23,6 @@ const fetchMetadata = async (link: string) => { }; function DragDiv() { - console.log(); const [x, setX] = useState(0); const [y, setY] = useState(0); const [width, setWidth] = useState(window.innerWidth - 50); diff --git a/packages/react-chat/src/components/Channels.tsx b/packages/react-chat/src/components/Channels.tsx index 6be9af2..f24d5ea 100644 --- a/packages/react-chat/src/components/Channels.tsx +++ b/packages/react-chat/src/components/Channels.tsx @@ -3,28 +3,22 @@ import styled from "styled-components"; import { useNarrow } from "../contexts/narrowProvider"; import { ChannelData, channels } from "../helpers/channelsMock"; -import { CommunityData } from "../helpers/communityMock"; -import { Community } from "./Community"; import { MutedIcon } from "./Icons/MutedIcon"; import { textMediumStyles } from "./Text"; interface ChannelsProps { - community: CommunityData; notifications: { [id: string]: number }; clearNotifications: (id: string) => void; - onCommunityClick: () => void; - setActiveChannel: (val: ChannelData) => void; + onCommunityClick: (val: ChannelData) => void; activeChannelId: number; } export function Channels({ - community, notifications, - setActiveChannel, + onCommunityClick, clearNotifications, activeChannelId, - onCommunityClick, }: ChannelsProps) { useEffect(() => { const channel = channels.find((channel) => channel.id === activeChannelId); @@ -36,27 +30,24 @@ export function Channels({ }, [notifications, activeChannelId]); return ( - - - - {channels.map((channel) => ( - 0 && !channel.isMuted - ? notifications[channel.name] - : undefined - } - onClick={() => { - setActiveChannel(channel); - }} - /> - ))} - - + + {channels.map((channel) => ( + 0 && !channel.isMuted + ? notifications[channel.name] + : undefined + } + onClick={() => { + onCommunityClick(channel); + }} + /> + ))} + ); } @@ -127,21 +118,6 @@ export function Channel({ ); } -const ChannelsWrapper = styled.div` - width: 21%; - height: 100%; - min-width: 196px; - background-color: ${({ theme }) => theme.sectionBackgroundColor}; - padding: 10px 0.6%; - display: flex; - flex-direction: column; -`; - -const StyledCommunity = styled(Community)` - padding: 0 0 0 10px; - margin: 0 0 16px; -`; - const ChannelDescription = styled.p` font-size: 12px; line-height: 16px; diff --git a/packages/react-chat/src/components/Chat.tsx b/packages/react-chat/src/components/Chat.tsx index c180303..ca23ce3 100644 --- a/packages/react-chat/src/components/Chat.tsx +++ b/packages/react-chat/src/components/Chat.tsx @@ -10,6 +10,7 @@ import { Theme } from "../styles/themes"; import { Channels } from "./Channels"; import { ChatBody } from "./Chat/ChatBody"; +import { Community } from "./Community"; import { Members } from "./Members"; import { CommunityModal } from "./Modals/CommunityModal"; @@ -44,14 +45,15 @@ export function Chat({ theme, community, fetchMetadata }: ChatProps) { return ( {showChannels && !narrow && ( - + + + setActiveChannel(e)} + activeChannelId={activeChannel.id} + /> + )} {showMembers && !narrow && ( @@ -92,3 +95,18 @@ const ChatWrapper = styled.div` height: 100%; display: flex; `; + +const ChannelsWrapper = styled.div` + width: 21%; + height: 100%; + min-width: 196px; + background-color: ${({ theme }) => theme.sectionBackgroundColor}; + padding: 10px 0.6%; + display: flex; + flex-direction: column; +`; + +const StyledCommunity = styled(Community)` + padding: 0 0 0 10px; + margin: 0 0 16px; +`; diff --git a/packages/react-chat/src/components/Chat/ChatBody.tsx b/packages/react-chat/src/components/Chat/ChatBody.tsx index a9d1ecf..a642985 100644 --- a/packages/react-chat/src/components/Chat/ChatBody.tsx +++ b/packages/react-chat/src/components/Chat/ChatBody.tsx @@ -36,6 +36,7 @@ interface ChatBodyProps { onCommunityClick: () => void; fetchMetadata?: (url: string) => Promise; loadingMessages: boolean; + clearNotifications: (id: string) => void; } export function ChatBody({ @@ -55,6 +56,7 @@ export function ChatBody({ onCommunityClick, fetchMetadata, loadingMessages, + clearNotifications, }: ChatBodyProps) { const narrow = useNarrow(); const [showChannelsList, setShowChannelsList] = useState(false); @@ -140,6 +142,7 @@ export function ChatBody({ setActiveChannel={setActiveChannel} setShowChannels={setShowChannelsList} activeChannelId={activeChannelId} + clearNotifications={clearNotifications} /> )} {showMembersList && narrow && ( diff --git a/packages/react-chat/src/components/Chat/ChatMessages.tsx b/packages/react-chat/src/components/Chat/ChatMessages.tsx index 4bf04e0..d4d5eae 100644 --- a/packages/react-chat/src/components/Chat/ChatMessages.tsx +++ b/packages/react-chat/src/components/Chat/ChatMessages.tsx @@ -34,10 +34,14 @@ export function ChatMessages({ }, [messages, messages.length, scrollOnBot]); useEffect(() => { - if ((ref?.current?.clientHeight ?? 0) < (ref?.current?.scrollHeight ?? 0)) { - loadNextDay(); + if (!loadingMessages) { + if ( + (ref?.current?.clientHeight ?? 0) >= (ref?.current?.scrollHeight ?? 0) + ) { + loadNextDay(); + } } - }, [messages, messages.length]); + }, [messages, messages.length, loadingMessages]); useEffect(() => { const setScroll = () => { diff --git a/packages/react-chat/src/components/NarrowMode/NarrowChannels.tsx b/packages/react-chat/src/components/NarrowMode/NarrowChannels.tsx index d7f0b79..e0fd668 100644 --- a/packages/react-chat/src/components/NarrowMode/NarrowChannels.tsx +++ b/packages/react-chat/src/components/NarrowMode/NarrowChannels.tsx @@ -1,8 +1,8 @@ import React from "react"; import styled from "styled-components"; -import { ChannelData, channels } from "../../helpers/channelsMock"; -import { Channel, ChannelList } from "../Channels"; +import { ChannelData } from "../../helpers/channelsMock"; +import { Channels } from "../Channels"; import { NarrowTopbar } from "./NarrowTopbar"; @@ -12,6 +12,7 @@ interface NarrowChannelsProps { setActiveChannel: (val: ChannelData) => void; activeChannelId: number; setShowChannels: (val: boolean) => void; + clearNotifications: (id: string) => void; } export function NarrowChannels({ @@ -20,29 +21,20 @@ export function NarrowChannels({ setActiveChannel, activeChannelId, setShowChannels, + clearNotifications, }: NarrowChannelsProps) { return ( - - {channels.map((channel) => ( - 0 && !channel.isMuted - ? notifications[channel.name] - : undefined - } - onClick={() => { - setActiveChannel(channel); - setShowChannels(false); - }} - /> - ))} - + { + setActiveChannel(e); + setShowChannels(false); + }} + activeChannelId={activeChannelId} + /> ); }