Add empty state for channel (#41)

This commit is contained in:
Maria Rushkova 2021-10-06 09:33:31 +02:00 committed by GitHub
parent a2859e1e03
commit 370f6c65e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 91 additions and 8 deletions

View File

@ -183,7 +183,7 @@ const ChannelWrapper = styled.div<ThemeProps>`
} }
`; `;
const ChannelInfo = styled.div` export const ChannelInfo = styled.div`
display: flex; display: flex;
align-items: center; align-items: center;
`; `;
@ -193,7 +193,7 @@ const ChannelTextInfo = styled.div`
flex-direction: column; flex-direction: column;
`; `;
const ChannelLogo = styled.div<ThemeProps>` export const ChannelLogo = styled.div<ThemeProps>`
width: 24px; width: 24px;
height: 24px; height: 24px;
display: flex; display: flex;
@ -225,7 +225,7 @@ const ChannelLogo = styled.div<ThemeProps>`
} }
`; `;
const ChannelName = styled.p<ThemeProps>` export const ChannelName = styled.p<ThemeProps>`
font-weight: 500; font-weight: 500;
opacity: 0.7; opacity: 0.7;
color: ${({ theme }) => theme.primary}; color: ${({ theme }) => theme.primary};

View File

@ -8,6 +8,7 @@ import { ChatMessage } from "../../models/ChatMessage";
import { Theme } from "../../styles/themes"; import { Theme } from "../../styles/themes";
import { Channel } from "../Channels"; import { Channel } from "../Channels";
import { Community } from "../Community"; import { Community } from "../Community";
import { EmptyChannel } from "../EmptyChannel";
import { MembersIcon } from "../Icons/MembersIcon"; import { MembersIcon } from "../Icons/MembersIcon";
import { NarrowChannels } from "../NarrowMode/NarrowChannels"; import { NarrowChannels } from "../NarrowMode/NarrowChannels";
import { NarrowTopbar } from "../NarrowMode/NarrowTopbar"; import { NarrowTopbar } from "../NarrowMode/NarrowTopbar";
@ -72,12 +73,14 @@ export function ChatBody({
<MembersIcon theme={theme} /> <MembersIcon theme={theme} />
</MemberBtn> </MemberBtn>
</ChatTopbar> </ChatTopbar>
{!showChannelsList && !showMembersList && ( {!showChannelsList &&
<> !showMembersList &&
(messages.length > 0 ? (
<ChatMessages messages={messages} theme={theme} /> <ChatMessages messages={messages} theme={theme} />
) : (
<EmptyChannel theme={theme} channel={channel} />
))}
<ChatInput theme={theme} addMessage={sendMessage} /> <ChatInput theme={theme} addMessage={sendMessage} />
</>
)}
{showChannelsList && narrow && ( {showChannelsList && narrow && (
<NarrowChannels <NarrowChannels
theme={theme} theme={theme}

View File

@ -0,0 +1,80 @@
import React from "react";
import styled from "styled-components";
import { ChannelData } from "../helpers/channelsMock";
import { Theme } from "../styles/themes";
import { ChannelInfo, ChannelLogo, ChannelName } from "./Channels";
import { textMediumStyles } from "./Text";
type EmptyChannelProps = {
theme: Theme;
channel: ChannelData;
};
export function EmptyChannel({ theme, channel }: EmptyChannelProps) {
return (
<Wrapper>
<ChannelInfoEmpty>
<ChannelLogoEmpty
style={{
backgroundImage: channel.icon ? `url(${channel.icon}` : "",
}}
theme={theme}
>
{" "}
{!channel.icon && channel.name.slice(0, 1).toUpperCase()}
</ChannelLogoEmpty>
<ChannelNameEmpty theme={theme} className={"active"}>
{channel.name}
</ChannelNameEmpty>
</ChannelInfoEmpty>
<EmptyText theme={theme}>
Welcome to the beginning of the <span>#{channel.name}</span> channel!
</EmptyText>
</Wrapper>
);
}
interface ThemeProps {
theme: Theme;
}
const Wrapper = styled.div`
display: flex;
flex-direction: column;
align-items: center;
height: calc(100% - 44px);
padding: 8px 16px 0;
`;
const ChannelInfoEmpty = styled(ChannelInfo)`
flex-direction: column;
`;
const ChannelLogoEmpty = styled(ChannelLogo)`
width: 120px;
height: 120px;
font-weight: bold;
font-size: 51px;
line-height: 62px;
margin-bottom: 16px;
`;
const ChannelNameEmpty = styled(ChannelName)`
font-weight: bold;
font-size: 22px;
line-height: 30px;
margin-bottom: 16px;
`;
const EmptyText = styled.p<ThemeProps>`
display: inline-block;
color: ${({ theme }) => theme.secondary};
& > span {
color: ${({ theme }) => theme.primary};
}
${textMediumStyles}
`;