Refactor channels (#177)
This commit is contained in:
parent
bf2e1b0ee2
commit
97532cc88d
|
@ -1,4 +1,4 @@
|
||||||
import React, { useEffect } from "react";
|
import React from "react";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
|
|
||||||
import { ChatState, useChatState } from "../../contexts/chatStateProvider";
|
import { ChatState, useChatState } from "../../contexts/chatStateProvider";
|
||||||
|
@ -45,25 +45,13 @@ function GenerateChannels({ type, onCommunityClick }: GenerateChannelsProps) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Channels({ onCommunityClick }: ChannelsProps) {
|
type ChatsListProps = {
|
||||||
const { clearNotifications, clearMentions, notifications, activeChannel } =
|
onCommunityClick?: () => void;
|
||||||
useMessengerContext();
|
};
|
||||||
useEffect(() => {
|
|
||||||
if (activeChannel) {
|
|
||||||
if (notifications[activeChannel.id] > 0) {
|
|
||||||
clearNotifications(activeChannel.id);
|
|
||||||
clearMentions(activeChannel.id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, [notifications, activeChannel]);
|
|
||||||
const setChatState = useChatState()[1];
|
|
||||||
const identity = useIdentity();
|
|
||||||
|
|
||||||
|
function ChatsSideBar({ onCommunityClick }: ChatsListProps) {
|
||||||
|
const setChatState = useChatState()[1];
|
||||||
return (
|
return (
|
||||||
<ChannelList>
|
|
||||||
<GenerateChannels type={"channel"} onCommunityClick={onCommunityClick} />
|
|
||||||
<Chats>
|
|
||||||
{identity ? (
|
|
||||||
<>
|
<>
|
||||||
<ChatsBar>
|
<ChatsBar>
|
||||||
<Heading>Chat</Heading>
|
<Heading>Chat</Heading>
|
||||||
|
@ -72,16 +60,21 @@ export function Channels({ onCommunityClick }: ChannelsProps) {
|
||||||
</EditBtn>
|
</EditBtn>
|
||||||
</ChatsBar>
|
</ChatsBar>
|
||||||
<ChatsList>
|
<ChatsList>
|
||||||
<GenerateChannels
|
<GenerateChannels type={"group"} onCommunityClick={onCommunityClick} />
|
||||||
type={"group"}
|
<GenerateChannels type={"dm"} onCommunityClick={onCommunityClick} />
|
||||||
onCommunityClick={onCommunityClick}
|
|
||||||
/>
|
|
||||||
<GenerateChannels
|
|
||||||
type={"dm"}
|
|
||||||
onCommunityClick={onCommunityClick}
|
|
||||||
/>
|
|
||||||
</ChatsList>
|
</ChatsList>
|
||||||
</>
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function Channels({ onCommunityClick }: ChannelsProps) {
|
||||||
|
const identity = useIdentity();
|
||||||
|
return (
|
||||||
|
<ChannelList>
|
||||||
|
<GenerateChannels type={"channel"} onCommunityClick={onCommunityClick} />
|
||||||
|
<Chats>
|
||||||
|
{identity ? (
|
||||||
|
<ChatsSideBar onCommunityClick={onCommunityClick} />
|
||||||
) : (
|
) : (
|
||||||
<UserCreation permission={true} />
|
<UserCreation permission={true} />
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -9,11 +9,11 @@ import { textMediumStyles } from "../Text";
|
||||||
|
|
||||||
import { ChannelInfo, ChannelLogo, ChannelName } from "./Channel";
|
import { ChannelInfo, ChannelLogo, ChannelName } from "./Channel";
|
||||||
|
|
||||||
type EmptyChannelProps = {
|
type ChannelBeggingTextProps = {
|
||||||
channel: ChannelData;
|
channel: ChannelData;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function EmptyChannel({ channel }: EmptyChannelProps) {
|
function ChannelBeggingText({ channel }: ChannelBeggingTextProps) {
|
||||||
const identity = useIdentity();
|
const identity = useIdentity();
|
||||||
const { contacts } = useMessengerContext();
|
const { contacts } = useMessengerContext();
|
||||||
const members = useMemo(() => {
|
const members = useMemo(() => {
|
||||||
|
@ -25,23 +25,18 @@ export function EmptyChannel({ channel }: EmptyChannelProps) {
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}, [channel, contacts]);
|
}, [channel, contacts]);
|
||||||
return (
|
|
||||||
<Wrapper>
|
|
||||||
<ChannelInfoEmpty>
|
|
||||||
<ChannelLogoEmpty icon={channel.icon}>
|
|
||||||
{" "}
|
|
||||||
{!channel.icon && channel.name.slice(0, 1).toUpperCase()}
|
|
||||||
</ChannelLogoEmpty>
|
|
||||||
<ChannelNameEmpty active={true} channel={channel} />
|
|
||||||
</ChannelInfoEmpty>
|
|
||||||
|
|
||||||
{channel.type === "dm" ? (
|
switch (channel.type) {
|
||||||
|
case "dm":
|
||||||
|
return (
|
||||||
<EmptyText>
|
<EmptyText>
|
||||||
Any messages you send here are encrypted and can only be read by you
|
Any messages you send here are encrypted and can only be read by you
|
||||||
and <br />
|
and <br />
|
||||||
<span>{channel.name.slice(0, 10)}</span>.
|
<span>{channel.name.slice(0, 10)}</span>.
|
||||||
</EmptyText>
|
</EmptyText>
|
||||||
) : channel.type === "group" ? (
|
);
|
||||||
|
case "group":
|
||||||
|
return (
|
||||||
<EmptyTextGroup>
|
<EmptyTextGroup>
|
||||||
{identity && <span>{utils.bufToHex(identity.publicKey)}</span>}{" "}
|
{identity && <span>{utils.bufToHex(identity.publicKey)}</span>}{" "}
|
||||||
created a group with{" "}
|
created a group with{" "}
|
||||||
|
@ -52,11 +47,32 @@ export function EmptyChannel({ channel }: EmptyChannelProps) {
|
||||||
</span>
|
</span>
|
||||||
))}
|
))}
|
||||||
</EmptyTextGroup>
|
</EmptyTextGroup>
|
||||||
) : (
|
);
|
||||||
|
case "channel":
|
||||||
|
return (
|
||||||
<EmptyText>
|
<EmptyText>
|
||||||
Welcome to the beginning of the <span>#{channel.name}</span> channel!
|
Welcome to the beginning of the <span>#{channel.name}</span> channel!
|
||||||
</EmptyText>
|
</EmptyText>
|
||||||
)}
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
type EmptyChannelProps = {
|
||||||
|
channel: ChannelData;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function EmptyChannel({ channel }: EmptyChannelProps) {
|
||||||
|
return (
|
||||||
|
<Wrapper>
|
||||||
|
<ChannelInfoEmpty>
|
||||||
|
<ChannelLogoEmpty icon={channel.icon}>
|
||||||
|
{" "}
|
||||||
|
{!channel.icon && channel.name.slice(0, 1).toUpperCase()}
|
||||||
|
</ChannelLogoEmpty>
|
||||||
|
<ChannelNameEmpty active={true} channel={channel} />
|
||||||
|
</ChannelInfoEmpty>
|
||||||
|
<ChannelBeggingText channel={channel} />
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -228,6 +228,15 @@ export function useMessenger(
|
||||||
[messenger, groupChat, activeChannel]
|
[messenger, groupChat, activeChannel]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (activeChannel) {
|
||||||
|
if (notifications[activeChannel.id] > 0) {
|
||||||
|
clearNotifications(activeChannel.id);
|
||||||
|
clearMentions(activeChannel.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [notifications, activeChannel]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messenger,
|
messenger,
|
||||||
messages,
|
messages,
|
||||||
|
|
Loading…
Reference in New Issue