Hide lists (#44)

This commit is contained in:
Maria Rushkova 2021-10-06 11:59:32 +02:00 committed by GitHub
parent b40ce941d9
commit e4be0447e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 7 deletions

View File

@ -21,7 +21,6 @@ export function Chat({ theme, community }: ChatProps) {
const [showMembers, setShowMembers] = useState(true); const [showMembers, setShowMembers] = useState(true);
const [showChannels, setShowChannels] = useState(true); const [showChannels, setShowChannels] = useState(true);
const narrow = useNarrow(); const narrow = useNarrow();
// const className = useMemo(() => (narrow ? 'narrow' : ''), [narrow]);
const { const {
messenger, messenger,

View File

@ -1,6 +1,7 @@
import React from "react"; import React, { useCallback } from "react";
import styled from "styled-components"; import styled from "styled-components";
import { useNarrow } from "../contexts/narrowProvider";
import { CommunityData } from "../helpers/communityMock"; import { CommunityData } from "../helpers/communityMock";
import { Theme } from "../styles/themes"; import { Theme } from "../styles/themes";
@ -30,12 +31,14 @@ interface MembersListProps {
theme: Theme; theme: Theme;
community: CommunityData; community: CommunityData;
setShowChannels: (val: boolean) => void; setShowChannels: (val: boolean) => void;
setShowMembers?: (val: boolean) => void;
} }
export function MembersList({ export function MembersList({
theme, theme,
community, community,
setShowChannels, setShowChannels,
setShowMembers,
}: MembersListProps) { }: MembersListProps) {
return ( return (
<MembersListWrap> <MembersListWrap>
@ -59,6 +62,7 @@ export function MembersList({
member={member} member={member}
isOnline={member.isOnline} isOnline={member.isOnline}
setShowChannels={setShowChannels} setShowChannels={setShowChannels}
setShowMembers={setShowMembers}
/> />
))} ))}
</MemberCategory> </MemberCategory>
@ -73,6 +77,7 @@ export function MembersList({
member={member} member={member}
isOnline={member.isOnline} isOnline={member.isOnline}
setShowChannels={setShowChannels} setShowChannels={setShowChannels}
setShowMembers={setShowMembers}
/> />
))} ))}
</MemberCategory> </MemberCategory>
@ -85,6 +90,7 @@ interface MemberProps {
member: any; member: any;
isOnline: boolean; isOnline: boolean;
setShowChannels: (val: boolean) => void; setShowChannels: (val: boolean) => void;
setShowMembers?: (val: boolean) => void;
} }
export function Member({ export function Member({
@ -92,9 +98,21 @@ export function Member({
member, member,
isOnline, isOnline,
setShowChannels, setShowChannels,
setShowMembers,
}: MemberProps) { }: MemberProps) {
const narrow = useNarrow();
const switchMemberList = useCallback(() => {
setShowChannels(false);
if (setShowMembers) setShowMembers(false);
}, [setShowMembers]);
return ( return (
<MemberData onClick={() => setShowChannels(true)}> <MemberData
onClick={() =>
narrow && setShowMembers ? switchMemberList() : setShowChannels(true)
}
>
<MemberIcon <MemberIcon
style={{ style={{
backgroundImage: member.avatar ? `url(${member.avatar})` : "unset", backgroundImage: member.avatar ? `url(${member.avatar})` : "unset",

View File

@ -25,7 +25,7 @@ export function NarrowChannels({
setShowChannels, setShowChannels,
}: NarrowChannelsProps) { }: NarrowChannelsProps) {
return ( return (
<ListWrapper> <ListWrapper theme={theme}>
<NarrowTopbar <NarrowTopbar
theme={theme} theme={theme}
list="Channels" list="Channels"
@ -56,6 +56,11 @@ export function NarrowChannels({
); );
} }
const ListWrapper = styled.div` interface ThemeProps {
theme: Theme;
}
const ListWrapper = styled.div<ThemeProps>`
padding: 18px; padding: 18px;
background: ${({ theme }) => theme.bodyBackgroundColor};
`; `;

View File

@ -21,7 +21,7 @@ export function NarrowMembers({
setShowMembersList, setShowMembersList,
}: NarrowMembersProps) { }: NarrowMembersProps) {
return ( return (
<ListWrapper> <ListWrapper theme={theme}>
<NarrowTopbar <NarrowTopbar
theme={theme} theme={theme}
list="Community members" list="Community members"
@ -32,11 +32,17 @@ export function NarrowMembers({
theme={theme} theme={theme}
community={community} community={community}
setShowChannels={setShowChannels} setShowChannels={setShowChannels}
setShowMembers={setShowMembersList}
/> />
</ListWrapper> </ListWrapper>
); );
} }
const ListWrapper = styled.div` interface ThemeProps {
theme: Theme;
}
const ListWrapper = styled.div<ThemeProps>`
padding: 18px; padding: 18px;
background: ${({ theme }) => theme.bodyBackgroundColor};
`; `;