Fix group creation (#112)

This commit is contained in:
Maria Rushkova 2021-11-04 15:18:42 +01:00 committed by GitHub
parent cdac0b6bd5
commit e0e79d3375
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 52 additions and 41 deletions

View File

@ -66,7 +66,7 @@ export function Channel({
) : ( ) : (
"#" "#"
)}{" "} )}{" "}
{channel.name.slice(0, 10)} {channel.name}
</ChannelName> </ChannelName>
{activeView && ( {activeView && (
<ChannelDescription> {channel.description}</ChannelDescription> <ChannelDescription> {channel.description}</ChannelDescription>
@ -103,8 +103,6 @@ export const ChannelInfo = styled.div`
const ChannelTextInfo = styled.div` const ChannelTextInfo = styled.div`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
text-overflow: ellipsis;
overflow: hidden;
`; `;
export const ChannelLogo = styled.div` export const ChannelLogo = styled.div`

View File

@ -12,7 +12,7 @@ interface ChannelsProps {
activeChannelId: string; activeChannelId: string;
channels: ChannelData[]; channels: ChannelData[];
membersList: string[]; membersList: string[];
groupList: string[]; groupList: string[][];
setCreateChat: (val: boolean) => void; setCreateChat: (val: boolean) => void;
} }
@ -66,20 +66,18 @@ export function Channels({
{groupList.length > 0 && {groupList.length > 0 &&
groupList.map((group) => ( groupList.map((group) => (
<Channel <Channel
key={group} key={group.join("")}
channel={{ channel={{
id: group, id: group.join(""),
name: group, name: group.join(", "),
type: "group", type: "group",
description: "Contact",
}} }}
isActive={group === activeChannelId} isActive={group.join("") === activeChannelId}
isMuted={false} isMuted={false}
onClick={() => { onClick={() => {
onCommunityClick({ onCommunityClick({
id: group, id: group.join(""),
name: group.slice(0, 10), name: group.join(", ").slice(0, 10),
description: "Contact",
}); });
setCreateChat(false); setCreateChat(false);
}} }}

View File

@ -11,6 +11,8 @@ type EmptyChannelProps = {
}; };
export function EmptyChannel({ channel }: EmptyChannelProps) { export function EmptyChannel({ channel }: EmptyChannelProps) {
const groupName = channel.name.split(", ");
return ( return (
<Wrapper> <Wrapper>
<ChannelInfoEmpty> <ChannelInfoEmpty>
@ -34,8 +36,9 @@ export function EmptyChannel({ channel }: EmptyChannelProps) {
</EmptyText> </EmptyText>
) : channel.type === "group" ? ( ) : channel.type === "group" ? (
<EmptyText> <EmptyText>
You created a group with <span>{channel.name.slice(1, -1)}</span> and{" "} You created a group with{" "}
<span>{channel.name.at(-1)}</span> <span>{groupName.slice(groupName.length - 1)}</span> and{" "}
<span>{groupName.at(-1)}</span>
</EmptyText> </EmptyText>
) : ( ) : (
<EmptyText> <EmptyText>

View File

@ -130,6 +130,7 @@ export function Chat({
)} )}
{createChat && communityData && ( {createChat && communityData && (
<ChatCreation <ChatCreation
identity={identity}
community={communityData} community={communityData}
setMembersList={setMembersList} setMembersList={setMembersList}
setGroupList={setGroupList} setGroupList={setGroupList}

View File

@ -35,7 +35,7 @@ interface ChatBodyProps {
onEditClick: () => void; onEditClick: () => void;
channels: ChannelData[]; channels: ChannelData[];
membersList: string[]; membersList: string[];
groupList: string[]; groupList: [][];
setMembersList: any; setMembersList: any;
setGroupList: any; setGroupList: any;
setCreateChat: (val: boolean) => void; setCreateChat: (val: boolean) => void;
@ -88,6 +88,7 @@ export function ChatBody({
<ChatBodyWrapper className={className}> <ChatBodyWrapper className={className}>
{editGroup && community ? ( {editGroup && community ? (
<ChatCreation <ChatCreation
identity={identity}
community={community} community={community}
setMembersList={setMembersList} setMembersList={setMembersList}
setGroupList={setGroupList} setGroupList={setGroupList}
@ -112,6 +113,7 @@ export function ChatBody({
/> />
</CommunityWrap> </CommunityWrap>
)} )}
<Channel <Channel
channel={channel} channel={channel}
isActive={narrow ? showChannelsList : true} isActive={narrow ? showChannelsList : true}

View File

@ -1,14 +1,18 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { Identity } from "status-communities/dist/cjs";
import { bufToHex } from "status-communities/dist/cjs/utils";
import styled from "styled-components"; import styled from "styled-components";
import { useMessengerContext } from "../../contexts/messengerProvider";
import { ChannelData } from "../../models/ChannelData"; import { ChannelData } from "../../models/ChannelData";
import { CommunityData } from "../../models/CommunityData"; import { CommunityData } from "../../models/CommunityData";
import { buttonStyles } from "../Buttons/buttonStyle"; import { buttonStyles } from "../Buttons/buttonStyle";
import { Channel } from "../Channels/Channel";
import { CrossIcon } from "../Icons/CrossIcon"; import { CrossIcon } from "../Icons/CrossIcon";
import { Member } from "../Members/Member";
import { SearchBlock } from "../SearchBlock"; import { SearchBlock } from "../SearchBlock";
import { textMediumStyles } from "../Text"; import { textMediumStyles } from "../Text";
interface ChatCreationProps { interface ChatCreationProps {
identity: Identity;
community: CommunityData; community: CommunityData;
setMembersList: any; setMembersList: any;
setGroupList: any; setGroupList: any;
@ -18,6 +22,7 @@ interface ChatCreationProps {
} }
export function ChatCreation({ export function ChatCreation({
identity,
community, community,
setMembersList, setMembersList,
setGroupList, setGroupList,
@ -28,6 +33,8 @@ export function ChatCreation({
const [query, setQuery] = useState(""); const [query, setQuery] = useState("");
const [styledGroup, setStyledGroup] = useState<string[]>([]); const [styledGroup, setStyledGroup] = useState<string[]>([]);
const { contacts } = useMessengerContext();
const addMember = (member: string) => { const addMember = (member: string) => {
setStyledGroup((prevMembers: string[]) => { setStyledGroup((prevMembers: string[]) => {
if (prevMembers.find((mem) => mem === member)) { if (prevMembers.find((mem) => mem === member)) {
@ -40,13 +47,14 @@ export function ChatCreation({
const removeMember = (member: string) => { const removeMember = (member: string) => {
const idx = styledGroup.indexOf(member); const idx = styledGroup.indexOf(member);
styledGroup.splice(idx, 1); setStyledGroup(styledGroup.splice(idx, 1));
}; };
const createChat = (group: string[]) => { const createChat = (group: string[]) => {
group.length > 1 group.length > 1
? (setGroupList((prevGroups: string[]) => { ? (setGroupList((prevGroups: string[][]) => {
[...prevGroups, group]; prevGroups.push(group);
return prevGroups;
}), }),
setActiveChannel({ setActiveChannel({
id: group.join(""), id: group.join(""),
@ -64,6 +72,7 @@ export function ChatCreation({
id: group[0], id: group[0],
name: group[0], name: group[0],
type: "dm", type: "dm",
description: "Contact",
})); }));
setCreateChat(false); setCreateChat(false);
}; };
@ -120,17 +129,14 @@ export function ChatCreation({
<Contacts> <Contacts>
<ContactsHeading>Contacts</ContactsHeading> <ContactsHeading>Contacts</ContactsHeading>
<ContactsList> <ContactsList>
{community.membersList.map((member) => ( {contacts
<Channel .filter((e) => e.id != bufToHex(identity.publicKey))
key={member} .map((contact) => (
channel={{ <Member
id: member, key={contact.id}
name: member.slice(0, 10), member={contact.id}
type: "dm", isOnline={contact.online}
}} onClick={() => addMember(contact.id)}
isActive={false}
isMuted={false}
onClick={() => addMember(member)}
/> />
))} ))}
</ContactsList> </ContactsList>

View File

@ -9,9 +9,10 @@ import { UserIcon } from "../Icons/UserIcon";
interface MemberProps { interface MemberProps {
member: string; member: string;
isOnline?: boolean; isOnline?: boolean;
setShowChannels: (val: boolean) => void; setShowChannels?: (val: boolean) => void;
setShowMembers?: (val: boolean) => void; setShowMembers?: (val: boolean) => void;
setMembersList?: any; setMembersList?: any;
onClick?: () => void;
} }
export function Member({ export function Member({
@ -20,11 +21,12 @@ export function Member({
setShowChannels, setShowChannels,
setShowMembers, setShowMembers,
setMembersList, setMembersList,
onClick,
}: MemberProps) { }: MemberProps) {
const narrow = useNarrow(); const narrow = useNarrow();
const switchMemberList = useCallback(() => { const switchMemberList = useCallback(() => {
setShowChannels(false); if (setShowChannels) setShowChannels(false);
if (setShowMembers) setShowMembers(false); if (setShowMembers) setShowMembers(false);
}, [setShowMembers]); }, [setShowMembers]);
@ -36,17 +38,17 @@ export function Member({
return [...prevMembers, member]; return [...prevMembers, member];
} }
}); });
setShowChannels(true); if (setShowChannels) setShowChannels(true);
}; };
const [showMenu, setShowMenu] = useState(false); const [showMenu, setShowMenu] = useState(false);
return ( const onMemberClick = () => {
<MemberData
onClick={() => {
narrow && setShowMembers ? switchMemberList() : startDialog(member); narrow && setShowMembers ? switchMemberList() : startDialog(member);
}} };
>
return (
<MemberData onClick={onClick ? onClick : onMemberClick}>
<MemberIcon <MemberIcon
style={{ style={{
backgroundImage: "unset", backgroundImage: "unset",
@ -66,6 +68,7 @@ export const MemberData = styled.div`
display: flex; display: flex;
align-items: center; align-items: center;
margin-bottom: 16px; margin-bottom: 16px;
cursor: pointer;
`; `;
export const MemberName = styled.p` export const MemberName = styled.p`

View File

@ -13,7 +13,7 @@ interface NarrowChannelsProps {
setShowChannels: (val: boolean) => void; setShowChannels: (val: boolean) => void;
channels: ChannelData[]; channels: ChannelData[];
membersList: string[]; membersList: string[];
groupList: string[]; groupList: string[][];
setCreateChat: (val: boolean) => void; setCreateChat: (val: boolean) => void;
} }