Show group members for group (#201)

This commit is contained in:
Maria Rushkova 2022-01-25 11:58:04 +01:00 committed by GitHub
parent fb0bd2fc8c
commit a024960b98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 14 deletions

View File

@ -1,12 +1,23 @@
import React from "react"; import React, { useMemo } from "react";
import styled from "styled-components"; import styled from "styled-components";
import { useMessengerContext } from "../../contexts/messengerProvider";
import { MembersList } from "./MembersList"; import { MembersList } from "./MembersList";
export function Members() { export function Members() {
const { activeChannel } = useMessengerContext();
const heading = useMemo(
() =>
activeChannel && activeChannel?.type === "group"
? "Group members"
: "Members",
[activeChannel]
);
return ( return (
<MembersWrapper> <MembersWrapper>
<MemberHeading>Members</MemberHeading> <MemberHeading>{heading}</MemberHeading>
<MembersList /> <MembersList />
</MembersWrapper> </MembersWrapper>
); );

View File

@ -13,7 +13,7 @@ import { LogoutModalName } from "../Modals/LogoutModal";
import { Member } from "./Member"; import { Member } from "./Member";
export function MembersList() { export function MembersList() {
const { contacts, nickname } = useMessengerContext(); const { contacts, nickname, activeChannel } = useMessengerContext();
const identity = useIdentity(); const identity = useIdentity();
const { setModal } = useModal(LogoutModalName); const { setModal } = useModal(LogoutModalName);
@ -27,13 +27,26 @@ export function MembersList() {
} }
}, [contacts, identity]); }, [contacts, identity]);
const members = useMemo(
() =>
activeChannel &&
activeChannel?.type === "group" &&
activeChannel.members &&
identity
? activeChannel.members.filter(
(e) => e.id !== utils.bufToHex(identity.publicKey)
)
: userContacts,
[activeChannel]
);
const onlineContacts = useMemo( const onlineContacts = useMemo(
() => userContacts.filter((e) => e.online), () => members.filter((e) => e.online),
[userContacts] [members]
); );
const offlineContacts = useMemo( const offlineContacts = useMemo(
() => userContacts.filter((e) => !e.online), () => members.filter((e) => !e.online),
[userContacts] [members]
); );
return ( return (

View File

@ -1,5 +1,6 @@
import React from "react"; import React, { useMemo } from "react";
import { useMessengerContext } from "../../contexts/messengerProvider";
import { MembersList } from "../Members/MembersList"; import { MembersList } from "../Members/MembersList";
import { ListWrapper, NarrowTopbar } from "./NarrowTopbar"; import { ListWrapper, NarrowTopbar } from "./NarrowTopbar";
@ -9,12 +10,18 @@ interface NarrowMembersProps {
} }
export function NarrowMembers({ switchShowMembersList }: NarrowMembersProps) { export function NarrowMembers({ switchShowMembersList }: NarrowMembersProps) {
const { activeChannel } = useMessengerContext();
const listName = useMemo(
() =>
activeChannel && activeChannel?.type === "group"
? "Group members"
: "Community members",
[activeChannel]
);
return ( return (
<ListWrapper> <ListWrapper>
<NarrowTopbar <NarrowTopbar list={listName} onBtnClick={switchShowMembersList} />
list="Community members"
onBtnClick={switchShowMembersList}
/>
<MembersList /> <MembersList />
</ListWrapper> </ListWrapper>
); );

View File

@ -10,13 +10,17 @@ interface NarrowTopbarProps {
} }
export function NarrowTopbar({ list, onBtnClick }: NarrowTopbarProps) { export function NarrowTopbar({ list, onBtnClick }: NarrowTopbarProps) {
const { communityData } = useMessengerContext(); const { communityData, activeChannel } = useMessengerContext();
return ( return (
<TopbarWrapper> <TopbarWrapper>
<BackButton onBtnClick={onBtnClick} /> <BackButton onBtnClick={onBtnClick} />
<HeadingWrapper> <HeadingWrapper>
<Heading>{list}</Heading> <Heading>{list}</Heading>
<SubHeading>{communityData?.name}</SubHeading> <SubHeading>
{activeChannel?.type === "group"
? activeChannel.name
: communityData?.name}
</SubHeading>
</HeadingWrapper> </HeadingWrapper>
</TopbarWrapper> </TopbarWrapper>
); );