From e0e79d3375c554de8e9843a8d9f37638153ff7c9 Mon Sep 17 00:00:00 2001
From: Maria Rushkova <66270386+mrushkova@users.noreply.github.com>
Date: Thu, 4 Nov 2021 15:18:42 +0100
Subject: [PATCH] Fix group creation (#112)
---
.../src/components/Channels/Channel.tsx | 4 +-
.../src/components/Channels/Channels.tsx | 16 ++++----
.../src/components/Channels/EmptyChannel.tsx | 7 +++-
packages/react-chat/src/components/Chat.tsx | 1 +
.../src/components/Chat/ChatBody.tsx | 4 +-
.../src/components/Chat/ChatCreation.tsx | 40 +++++++++++--------
.../src/components/Members/Member.tsx | 19 +++++----
.../components/NarrowMode/NarrowChannels.tsx | 2 +-
8 files changed, 52 insertions(+), 41 deletions(-)
diff --git a/packages/react-chat/src/components/Channels/Channel.tsx b/packages/react-chat/src/components/Channels/Channel.tsx
index f312aed8..d80d3668 100644
--- a/packages/react-chat/src/components/Channels/Channel.tsx
+++ b/packages/react-chat/src/components/Channels/Channel.tsx
@@ -66,7 +66,7 @@ export function Channel({
) : (
"#"
)}{" "}
- {channel.name.slice(0, 10)}
+ {channel.name}
{activeView && (
{channel.description}
@@ -103,8 +103,6 @@ export const ChannelInfo = styled.div`
const ChannelTextInfo = styled.div`
display: flex;
flex-direction: column;
- text-overflow: ellipsis;
- overflow: hidden;
`;
export const ChannelLogo = styled.div`
diff --git a/packages/react-chat/src/components/Channels/Channels.tsx b/packages/react-chat/src/components/Channels/Channels.tsx
index a4b1c745..6e891b23 100644
--- a/packages/react-chat/src/components/Channels/Channels.tsx
+++ b/packages/react-chat/src/components/Channels/Channels.tsx
@@ -12,7 +12,7 @@ interface ChannelsProps {
activeChannelId: string;
channels: ChannelData[];
membersList: string[];
- groupList: string[];
+ groupList: string[][];
setCreateChat: (val: boolean) => void;
}
@@ -66,20 +66,18 @@ export function Channels({
{groupList.length > 0 &&
groupList.map((group) => (
{
onCommunityClick({
- id: group,
- name: group.slice(0, 10),
- description: "Contact",
+ id: group.join(""),
+ name: group.join(", ").slice(0, 10),
});
setCreateChat(false);
}}
diff --git a/packages/react-chat/src/components/Channels/EmptyChannel.tsx b/packages/react-chat/src/components/Channels/EmptyChannel.tsx
index 00f74a91..7d804b2a 100644
--- a/packages/react-chat/src/components/Channels/EmptyChannel.tsx
+++ b/packages/react-chat/src/components/Channels/EmptyChannel.tsx
@@ -11,6 +11,8 @@ type EmptyChannelProps = {
};
export function EmptyChannel({ channel }: EmptyChannelProps) {
+ const groupName = channel.name.split(", ");
+
return (
@@ -34,8 +36,9 @@ export function EmptyChannel({ channel }: EmptyChannelProps) {
) : channel.type === "group" ? (
- You created a group with {channel.name.slice(1, -1)} and{" "}
- {channel.name.at(-1)}
+ You created a group with{" "}
+ {groupName.slice(groupName.length - 1)} and{" "}
+ {groupName.at(-1)}
) : (
diff --git a/packages/react-chat/src/components/Chat.tsx b/packages/react-chat/src/components/Chat.tsx
index 43a35fba..8a76d8b9 100644
--- a/packages/react-chat/src/components/Chat.tsx
+++ b/packages/react-chat/src/components/Chat.tsx
@@ -130,6 +130,7 @@ export function Chat({
)}
{createChat && communityData && (
void;
channels: ChannelData[];
membersList: string[];
- groupList: string[];
+ groupList: [][];
setMembersList: any;
setGroupList: any;
setCreateChat: (val: boolean) => void;
@@ -88,6 +88,7 @@ export function ChatBody({
{editGroup && community ? (
)}
+
([]);
+ const { contacts } = useMessengerContext();
+
const addMember = (member: string) => {
setStyledGroup((prevMembers: string[]) => {
if (prevMembers.find((mem) => mem === member)) {
@@ -40,13 +47,14 @@ export function ChatCreation({
const removeMember = (member: string) => {
const idx = styledGroup.indexOf(member);
- styledGroup.splice(idx, 1);
+ setStyledGroup(styledGroup.splice(idx, 1));
};
const createChat = (group: string[]) => {
group.length > 1
- ? (setGroupList((prevGroups: string[]) => {
- [...prevGroups, group];
+ ? (setGroupList((prevGroups: string[][]) => {
+ prevGroups.push(group);
+ return prevGroups;
}),
setActiveChannel({
id: group.join(""),
@@ -64,6 +72,7 @@ export function ChatCreation({
id: group[0],
name: group[0],
type: "dm",
+ description: "Contact",
}));
setCreateChat(false);
};
@@ -120,19 +129,16 @@ export function ChatCreation({
Contacts
- {community.membersList.map((member) => (
- addMember(member)}
- />
- ))}
+ {contacts
+ .filter((e) => e.id != bufToHex(identity.publicKey))
+ .map((contact) => (
+ addMember(contact.id)}
+ />
+ ))}
)}
diff --git a/packages/react-chat/src/components/Members/Member.tsx b/packages/react-chat/src/components/Members/Member.tsx
index 304b6c2b..0b115281 100644
--- a/packages/react-chat/src/components/Members/Member.tsx
+++ b/packages/react-chat/src/components/Members/Member.tsx
@@ -9,9 +9,10 @@ import { UserIcon } from "../Icons/UserIcon";
interface MemberProps {
member: string;
isOnline?: boolean;
- setShowChannels: (val: boolean) => void;
+ setShowChannels?: (val: boolean) => void;
setShowMembers?: (val: boolean) => void;
setMembersList?: any;
+ onClick?: () => void;
}
export function Member({
@@ -20,11 +21,12 @@ export function Member({
setShowChannels,
setShowMembers,
setMembersList,
+ onClick,
}: MemberProps) {
const narrow = useNarrow();
const switchMemberList = useCallback(() => {
- setShowChannels(false);
+ if (setShowChannels) setShowChannels(false);
if (setShowMembers) setShowMembers(false);
}, [setShowMembers]);
@@ -36,17 +38,17 @@ export function Member({
return [...prevMembers, member];
}
});
- setShowChannels(true);
+ if (setShowChannels) setShowChannels(true);
};
const [showMenu, setShowMenu] = useState(false);
+ const onMemberClick = () => {
+ narrow && setShowMembers ? switchMemberList() : startDialog(member);
+ };
+
return (
- {
- narrow && setShowMembers ? switchMemberList() : startDialog(member);
- }}
- >
+
void;
channels: ChannelData[];
membersList: string[];
- groupList: string[];
+ groupList: string[][];
setCreateChat: (val: boolean) => void;
}