Fix message loading and narrow notifications (#74)
This commit is contained in:
parent
6bd351ed41
commit
1bc239fa71
|
@ -23,7 +23,6 @@ const fetchMetadata = async (link: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
function DragDiv() {
|
function DragDiv() {
|
||||||
console.log();
|
|
||||||
const [x, setX] = useState(0);
|
const [x, setX] = useState(0);
|
||||||
const [y, setY] = useState(0);
|
const [y, setY] = useState(0);
|
||||||
const [width, setWidth] = useState(window.innerWidth - 50);
|
const [width, setWidth] = useState(window.innerWidth - 50);
|
||||||
|
|
|
@ -3,28 +3,22 @@ import styled from "styled-components";
|
||||||
|
|
||||||
import { useNarrow } from "../contexts/narrowProvider";
|
import { useNarrow } from "../contexts/narrowProvider";
|
||||||
import { ChannelData, channels } from "../helpers/channelsMock";
|
import { ChannelData, channels } from "../helpers/channelsMock";
|
||||||
import { CommunityData } from "../helpers/communityMock";
|
|
||||||
|
|
||||||
import { Community } from "./Community";
|
|
||||||
import { MutedIcon } from "./Icons/MutedIcon";
|
import { MutedIcon } from "./Icons/MutedIcon";
|
||||||
import { textMediumStyles } from "./Text";
|
import { textMediumStyles } from "./Text";
|
||||||
|
|
||||||
interface ChannelsProps {
|
interface ChannelsProps {
|
||||||
community: CommunityData;
|
|
||||||
notifications: { [id: string]: number };
|
notifications: { [id: string]: number };
|
||||||
clearNotifications: (id: string) => void;
|
clearNotifications: (id: string) => void;
|
||||||
onCommunityClick: () => void;
|
onCommunityClick: (val: ChannelData) => void;
|
||||||
setActiveChannel: (val: ChannelData) => void;
|
|
||||||
activeChannelId: number;
|
activeChannelId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Channels({
|
export function Channels({
|
||||||
community,
|
|
||||||
notifications,
|
notifications,
|
||||||
setActiveChannel,
|
onCommunityClick,
|
||||||
clearNotifications,
|
clearNotifications,
|
||||||
activeChannelId,
|
activeChannelId,
|
||||||
onCommunityClick,
|
|
||||||
}: ChannelsProps) {
|
}: ChannelsProps) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const channel = channels.find((channel) => channel.id === activeChannelId);
|
const channel = channels.find((channel) => channel.id === activeChannelId);
|
||||||
|
@ -36,27 +30,24 @@ export function Channels({
|
||||||
}, [notifications, activeChannelId]);
|
}, [notifications, activeChannelId]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ChannelsWrapper>
|
<ChannelList>
|
||||||
<StyledCommunity onClick={onCommunityClick} community={community} />
|
{channels.map((channel) => (
|
||||||
<ChannelList>
|
<Channel
|
||||||
{channels.map((channel) => (
|
key={channel.id}
|
||||||
<Channel
|
channel={channel}
|
||||||
key={channel.id}
|
isActive={channel.id === activeChannelId}
|
||||||
channel={channel}
|
isMuted={channel.isMuted || false}
|
||||||
isActive={channel.id === activeChannelId}
|
notification={
|
||||||
isMuted={channel.isMuted || false}
|
notifications[channel.name] > 0 && !channel.isMuted
|
||||||
notification={
|
? notifications[channel.name]
|
||||||
notifications[channel.name] > 0 && !channel.isMuted
|
: undefined
|
||||||
? notifications[channel.name]
|
}
|
||||||
: undefined
|
onClick={() => {
|
||||||
}
|
onCommunityClick(channel);
|
||||||
onClick={() => {
|
}}
|
||||||
setActiveChannel(channel);
|
/>
|
||||||
}}
|
))}
|
||||||
/>
|
</ChannelList>
|
||||||
))}
|
|
||||||
</ChannelList>
|
|
||||||
</ChannelsWrapper>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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`
|
const ChannelDescription = styled.p`
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
line-height: 16px;
|
line-height: 16px;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import { Theme } from "../styles/themes";
|
||||||
|
|
||||||
import { Channels } from "./Channels";
|
import { Channels } from "./Channels";
|
||||||
import { ChatBody } from "./Chat/ChatBody";
|
import { ChatBody } from "./Chat/ChatBody";
|
||||||
|
import { Community } from "./Community";
|
||||||
import { Members } from "./Members";
|
import { Members } from "./Members";
|
||||||
import { CommunityModal } from "./Modals/CommunityModal";
|
import { CommunityModal } from "./Modals/CommunityModal";
|
||||||
|
|
||||||
|
@ -44,14 +45,15 @@ export function Chat({ theme, community, fetchMetadata }: ChatProps) {
|
||||||
return (
|
return (
|
||||||
<ChatWrapper>
|
<ChatWrapper>
|
||||||
{showChannels && !narrow && (
|
{showChannels && !narrow && (
|
||||||
<Channels
|
<ChannelsWrapper>
|
||||||
notifications={notifications}
|
<StyledCommunity onClick={showModal} community={community} />
|
||||||
clearNotifications={clearNotifications}
|
<Channels
|
||||||
community={community}
|
notifications={notifications}
|
||||||
setActiveChannel={setActiveChannel}
|
clearNotifications={clearNotifications}
|
||||||
activeChannelId={activeChannel.id}
|
onCommunityClick={(e) => setActiveChannel(e)}
|
||||||
onCommunityClick={showModal}
|
activeChannelId={activeChannel.id}
|
||||||
/>
|
/>
|
||||||
|
</ChannelsWrapper>
|
||||||
)}
|
)}
|
||||||
<ChatBody
|
<ChatBody
|
||||||
theme={theme}
|
theme={theme}
|
||||||
|
@ -70,6 +72,7 @@ export function Chat({ theme, community, fetchMetadata }: ChatProps) {
|
||||||
onCommunityClick={showModal}
|
onCommunityClick={showModal}
|
||||||
fetchMetadata={fetchMetadata}
|
fetchMetadata={fetchMetadata}
|
||||||
loadingMessages={loadingMessages}
|
loadingMessages={loadingMessages}
|
||||||
|
clearNotifications={clearNotifications}
|
||||||
/>
|
/>
|
||||||
{showMembers && !narrow && (
|
{showMembers && !narrow && (
|
||||||
<Members community={community} setShowChannels={setShowChannels} />
|
<Members community={community} setShowChannels={setShowChannels} />
|
||||||
|
@ -92,3 +95,18 @@ const ChatWrapper = styled.div`
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: flex;
|
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;
|
||||||
|
`;
|
||||||
|
|
|
@ -36,6 +36,7 @@ interface ChatBodyProps {
|
||||||
onCommunityClick: () => void;
|
onCommunityClick: () => void;
|
||||||
fetchMetadata?: (url: string) => Promise<Metadata | undefined>;
|
fetchMetadata?: (url: string) => Promise<Metadata | undefined>;
|
||||||
loadingMessages: boolean;
|
loadingMessages: boolean;
|
||||||
|
clearNotifications: (id: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ChatBody({
|
export function ChatBody({
|
||||||
|
@ -55,6 +56,7 @@ export function ChatBody({
|
||||||
onCommunityClick,
|
onCommunityClick,
|
||||||
fetchMetadata,
|
fetchMetadata,
|
||||||
loadingMessages,
|
loadingMessages,
|
||||||
|
clearNotifications,
|
||||||
}: ChatBodyProps) {
|
}: ChatBodyProps) {
|
||||||
const narrow = useNarrow();
|
const narrow = useNarrow();
|
||||||
const [showChannelsList, setShowChannelsList] = useState(false);
|
const [showChannelsList, setShowChannelsList] = useState(false);
|
||||||
|
@ -140,6 +142,7 @@ export function ChatBody({
|
||||||
setActiveChannel={setActiveChannel}
|
setActiveChannel={setActiveChannel}
|
||||||
setShowChannels={setShowChannelsList}
|
setShowChannels={setShowChannelsList}
|
||||||
activeChannelId={activeChannelId}
|
activeChannelId={activeChannelId}
|
||||||
|
clearNotifications={clearNotifications}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{showMembersList && narrow && (
|
{showMembersList && narrow && (
|
||||||
|
|
|
@ -34,10 +34,14 @@ export function ChatMessages({
|
||||||
}, [messages, messages.length, scrollOnBot]);
|
}, [messages, messages.length, scrollOnBot]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if ((ref?.current?.clientHeight ?? 0) < (ref?.current?.scrollHeight ?? 0)) {
|
if (!loadingMessages) {
|
||||||
loadNextDay();
|
if (
|
||||||
|
(ref?.current?.clientHeight ?? 0) >= (ref?.current?.scrollHeight ?? 0)
|
||||||
|
) {
|
||||||
|
loadNextDay();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [messages, messages.length]);
|
}, [messages, messages.length, loadingMessages]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const setScroll = () => {
|
const setScroll = () => {
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
|
|
||||||
import { ChannelData, channels } from "../../helpers/channelsMock";
|
import { ChannelData } from "../../helpers/channelsMock";
|
||||||
import { Channel, ChannelList } from "../Channels";
|
import { Channels } from "../Channels";
|
||||||
|
|
||||||
import { NarrowTopbar } from "./NarrowTopbar";
|
import { NarrowTopbar } from "./NarrowTopbar";
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ interface NarrowChannelsProps {
|
||||||
setActiveChannel: (val: ChannelData) => void;
|
setActiveChannel: (val: ChannelData) => void;
|
||||||
activeChannelId: number;
|
activeChannelId: number;
|
||||||
setShowChannels: (val: boolean) => void;
|
setShowChannels: (val: boolean) => void;
|
||||||
|
clearNotifications: (id: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function NarrowChannels({
|
export function NarrowChannels({
|
||||||
|
@ -20,29 +21,20 @@ export function NarrowChannels({
|
||||||
setActiveChannel,
|
setActiveChannel,
|
||||||
activeChannelId,
|
activeChannelId,
|
||||||
setShowChannels,
|
setShowChannels,
|
||||||
|
clearNotifications,
|
||||||
}: NarrowChannelsProps) {
|
}: NarrowChannelsProps) {
|
||||||
return (
|
return (
|
||||||
<ListWrapper>
|
<ListWrapper>
|
||||||
<NarrowTopbar list="Channels" community={community} />
|
<NarrowTopbar list="Channels" community={community} />
|
||||||
<ChannelList>
|
<Channels
|
||||||
{channels.map((channel) => (
|
notifications={notifications}
|
||||||
<Channel
|
clearNotifications={clearNotifications}
|
||||||
key={channel.id}
|
onCommunityClick={(e) => {
|
||||||
channel={channel}
|
setActiveChannel(e);
|
||||||
isActive={channel.id === activeChannelId}
|
setShowChannels(false);
|
||||||
isMuted={channel.isMuted || false}
|
}}
|
||||||
notification={
|
activeChannelId={activeChannelId}
|
||||||
notifications[channel.name] > 0 && !channel.isMuted
|
/>
|
||||||
? notifications[channel.name]
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
onClick={() => {
|
|
||||||
setActiveChannel(channel);
|
|
||||||
setShowChannels(false);
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</ChannelList>
|
|
||||||
</ListWrapper>
|
</ListWrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue