Chat creation mode fixes (#219)

This commit is contained in:
Maria Rushkova 2022-02-04 15:56:30 +01:00 committed by GitHub
parent f531ccc0f7
commit b82bf0c0e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 111 additions and 36 deletions

View File

@ -38,6 +38,17 @@ export function ChatCreation({
[groupChatMembersIds, contacts] [groupChatMembersIds, contacts]
); );
const contactsList = useMemo(() => {
return Object.values(contacts)
.filter(
(member) =>
member.id.includes(query) ||
member?.customName?.includes(query) ||
member.trueName.includes(query)
)
.filter((member) => !groupChatMembersIds.includes(member.id));
}, [query, groupChatMembersIds, contacts]);
const setChatState = useChatState()[1]; const setChatState = useChatState()[1];
const addMember = useCallback( const addMember = useCallback(
@ -94,7 +105,11 @@ export function ChatCreation({
> >
{narrow && ( {narrow && (
<BackButton <BackButton
onBtnClick={() => setChatState(ChatState.ChatBody)} onBtnClick={() =>
setEditGroup
? setEditGroup?.(false)
: setChatState(ChatState.ChatBody)
}
className="narrow" className="narrow"
/> />
)} )}
@ -137,33 +152,60 @@ export function ChatCreation({
Confirm Confirm
</CreationBtn> </CreationBtn>
{!narrow && <ActivityButton className="creation" />} {!narrow && <ActivityButton className="creation" />}
<SearchBlock {!narrow && (
query={query} <SearchBlock
discludeList={groupChatMembersIds} query={query}
onClick={addMember} discludeList={groupChatMembersIds}
/> onClick={addMember}
/>
)}
</CreationBar> </CreationBar>
{!setEditGroup && ( {((!setEditGroup && groupChatMembers.length === 0) || narrow) &&
<Contacts> Object.keys(contacts).length > 0 && (
<ContactsHeading>Contacts</ContactsHeading> <Contacts>
<ContactsList> <ContactsHeading>Contacts</ContactsHeading>
{userPK && <ContactsList>
!query && {userPK && narrow
Object.values(contacts) ? contactsList.map((contact) => (
.filter( <Contact key={contact.id}>
(e) => e.id != userPK && !groupChatMembersIds.includes(e.id) <Member
) contact={contact}
.map((contact) => ( isOnline={contact.online}
<Member onClick={() => addMember(contact.id)}
key={contact.id} />
contact={contact} </Contact>
isOnline={contact.online} ))
onClick={() => addMember(contact.id)} : Object.values(contacts)
/> .filter(
))} (e) =>
</ContactsList> e.id != userPK && !groupChatMembersIds.includes(e.id)
</Contacts> )
.map((contact) => (
<Contact key={contact.id}>
<Member
contact={contact}
isOnline={contact.online}
onClick={() => addMember(contact.id)}
/>
</Contact>
))}
</ContactsList>
</Contacts>
)}
{!setEditGroup && Object.keys(contacts).length === 0 && (
<EmptyContacts>
<EmptyContactsHeading>
You only can send direct messages to your Contacts.{" "}
</EmptyContactsHeading>
<EmptyContactsHeading>
{" "}
Send a contact request to the person you would like to chat with,
you will be able to chat with them once they have accepted your
contact request.
</EmptyContactsHeading>
</EmptyContacts>
)} )}
{!activeChannel && ( {!activeChannel && (
<ChatInput <ChatInput
createChat={createChat} createChat={createChat}
@ -175,11 +217,11 @@ export function ChatCreation({
} }
const CreationWrapper = styled.div` const CreationWrapper = styled.div`
height: 100%;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
width: 79%; justify-content: space-between;
height: 100%; flex: 1;
max-width: calc(100% - 250px);
background-color: ${({ theme }) => theme.bodyBackgroundColor}; background-color: ${({ theme }) => theme.bodyBackgroundColor};
padding: 8px 16px; padding: 8px 16px;
@ -192,8 +234,9 @@ const CreationWrapper = styled.div`
const CreationBar = styled.div` const CreationBar = styled.div`
display: flex; display: flex;
align-items: center; align-items: center;
margin-bottom: 32px; margin-bottom: 24px;
position: relative; position: relative;
&.limit { &.limit {
align-items: flex-start; align-items: flex-start;
} }
@ -223,6 +266,7 @@ const InputBar = styled.div`
const Input = styled.input` const Input = styled.input`
width: 100%; width: 100%;
min-width: 20px;
background-color: ${({ theme }) => theme.inputColor}; background-color: ${({ theme }) => theme.inputColor};
border: 1px solid ${({ theme }) => theme.inputColor}; border: 1px solid ${({ theme }) => theme.inputColor};
outline: none; outline: none;
@ -293,6 +337,17 @@ const Contacts = styled.div`
overflow: auto; overflow: auto;
`; `;
const Contact = styled.div`
display: flex;
align-items: center;
padding: 12px 12px 0 16px;
border-radius: 8px;
&:hover {
background: ${({ theme }) => theme.inputColor};
}
`;
const ContactsHeading = styled.p` const ContactsHeading = styled.p`
color: ${({ theme }) => theme.secondary}; color: ${({ theme }) => theme.secondary};
@ -304,6 +359,17 @@ export const ContactsList = styled.div`
flex-direction: column; flex-direction: column;
`; `;
const EmptyContacts = styled(Contacts)`
justify-content: center;
align-items: center;
`;
const EmptyContactsHeading = styled(ContactsHeading)`
max-width: 550px;
margin-bottom: 24px;
text-align: center;
`;
const SearchMembers = styled.div` const SearchMembers = styled.div`
position: relative; position: relative;
flex: 1; flex: 1;

View File

@ -116,7 +116,6 @@ export const MemberIcon = styled(IconBtn)`
`; `;
const Column = styled.div` const Column = styled.div`
width: calc(100% - 69px);
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin-left: 8px; margin-left: 8px;

View File

@ -41,11 +41,9 @@ export const SearchBlock = ({
> >
<ContactsList> <ContactsList>
{searchList.map((member) => ( {searchList.map((member) => (
<Member <SearchContact key={member.id}>
key={member.id} <Member contact={member} onClick={() => onClick(member.id)} />
contact={member} </SearchContact>
onClick={() => onClick(member.id)}
/>
))} ))}
</ContactsList> </ContactsList>
</SearchContacts> </SearchContacts>
@ -66,3 +64,15 @@ const SearchContacts = styled.div`
max-height: 200px; max-height: 200px;
overflow: auto; overflow: auto;
`; `;
const SearchContact = styled.div`
width: 340px;
display: flex;
align-items: center;
padding: 12px 12px 0 16px;
border-radius: 8px;
&:hover {
background: ${({ theme }) => theme.inputColor};
}
`;