Fix showing menu/picker on click (#197)

* Fix closing emoji picker

* Show contact menu only after login

Co-authored-by: Szymon Szlachtowicz <38212223+Szymx95@users.noreply.github.com>
This commit is contained in:
Maria Rushkova 2022-01-20 02:19:25 +01:00 committed by GitHub
parent 27b81243fc
commit 5ebaa149c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 55 deletions

View File

@ -89,6 +89,8 @@ export function ChatInput({
setInputHeight(target.scrollHeight); setInputHeight(target.scrollHeight);
}, []); }, []);
const rowHeight = inputHeight + (image ? 73 : 0);
const onInputChange = useCallback((e: React.ChangeEvent<HTMLDivElement>) => { const onInputChange = useCallback((e: React.ChangeEvent<HTMLDivElement>) => {
const element = document.getSelection(); const element = document.getSelection();
const inputElement = inputRef.current; const inputElement = inputRef.current;
@ -219,10 +221,6 @@ export function ChatInput({
return ( return (
<View className={`${createChat && "creation"}`}> <View className={`${createChat && "creation"}`}>
<SizeLimitModal /> <SizeLimitModal />
<EmojiWrapper ref={ref}>
<EmojiPicker addEmoji={addEmoji} showEmoji={showEmoji} />
</EmojiWrapper>
<AddPictureInputWrapper> <AddPictureInputWrapper>
<PictureIcon /> <PictureIcon />
<AddPictureInput <AddPictureInput
@ -268,7 +266,7 @@ export function ChatInput({
</CloseButton> </CloseButton>
</ReplyWrapper> </ReplyWrapper>
)} )}
<Row style={{ height: `${inputHeight + (image ? 73 : 0)}px` }}> <Row style={{ height: `${rowHeight}px` }}>
<InputWrapper> <InputWrapper>
{image && ( {image && (
<ImageWrapper> <ImageWrapper>
@ -309,6 +307,7 @@ export function ChatInput({
)} )}
</InputWrapper> </InputWrapper>
<InputButtons> <InputButtons>
<EmojiWrapper ref={ref}>
<ChatButton <ChatButton
onClick={() => { onClick={() => {
if (!disabled) setShowEmoji(!showEmoji); if (!disabled) setShowEmoji(!showEmoji);
@ -317,6 +316,12 @@ export function ChatInput({
> >
<EmojiIcon isActive={showEmoji} /> <EmojiIcon isActive={showEmoji} />
</ChatButton> </ChatButton>
<EmojiPicker
addEmoji={addEmoji}
showEmoji={showEmoji}
bottom={rowHeight - 24}
/>
</EmojiWrapper>
<ChatButton disabled={disabled}> <ChatButton disabled={disabled}>
<StickerIcon /> <StickerIcon />
</ChatButton> </ChatButton>
@ -338,9 +343,7 @@ const InputWrapper = styled.div`
`; `;
const EmojiWrapper = styled.div` const EmojiWrapper = styled.div`
position: absolute; position: relative;
bottom: calc(100% - 6px);
right: 8px;
`; `;
const View = styled.div` const View = styled.div`

View File

@ -8,9 +8,10 @@ import { lightTheme, Theme } from "../../styles/themes";
type EmojiPickerProps = { type EmojiPickerProps = {
showEmoji: boolean; showEmoji: boolean;
addEmoji: (e: any) => void; addEmoji: (e: any) => void;
bottom: number;
}; };
export function EmojiPicker({ showEmoji, addEmoji }: EmojiPickerProps) { export function EmojiPicker({ showEmoji, addEmoji, bottom }: EmojiPickerProps) {
const theme = useTheme() as Theme; const theme = useTheme() as Theme;
const low = useLow(); const low = useLow();
@ -23,6 +24,9 @@ export function EmojiPicker({ showEmoji, addEmoji }: EmojiPickerProps) {
color={theme.tertiary} color={theme.tertiary}
emojiSize={26} emojiSize={26}
style={{ style={{
position: "absolute",
bottom: `calc(100% + ${bottom}px)`,
right: "-76px",
color: theme.secondary, color: theme.secondary,
height: low ? "200px" : "355px", height: low ? "200px" : "355px",
overflow: "auto", overflow: "auto",

View File

@ -1,7 +1,7 @@
import React, { useState } from "react"; import React, { useState } from "react";
import styled from "styled-components"; import styled from "styled-components";
import { useMessengerContext } from "../../contexts/messengerProvider"; import { useIdentity } from "../../contexts/identityProvider";
import { Contact } from "../../models/Contact"; import { Contact } from "../../models/Contact";
import { ContactMenu } from "../Form/ContactMenu"; import { ContactMenu } from "../Form/ContactMenu";
import { Icon } from "../Icons/Icon"; import { Icon } from "../Icons/Icon";
@ -13,39 +13,16 @@ interface MemberProps {
contact: Contact; contact: Contact;
isOnline?: boolean; isOnline?: boolean;
isYou?: boolean; isYou?: boolean;
switchShowMembers?: () => void;
onClick?: () => void; onClick?: () => void;
} }
export function Member({ export function Member({ contact, isOnline, isYou, onClick }: MemberProps) {
contact, const identity = useIdentity();
isOnline,
isYou,
switchShowMembers,
onClick,
}: MemberProps) {
const { setChannel } = useMessengerContext();
const [showMenu, setShowMenu] = useState(false); const [showMenu, setShowMenu] = useState(false);
const onMemberClick = () => {
if (!isYou) {
switchShowMembers?.();
setChannel({
id: contact.id,
name: contact?.customName ?? contact.trueName,
type: "dm",
description: `Chatkey: ${contact.id} `,
members: [contact],
});
}
};
return ( return (
<MemberData <MemberData onClick={onClick} className={`${isYou && "you"}`}>
onClick={onClick ? onClick : onMemberClick}
className={`${isYou && "you"}`}
>
<MemberIcon <MemberIcon
style={{ style={{
backgroundImage: "unset", backgroundImage: "unset",
@ -53,7 +30,9 @@ export function Member({
className={ className={
!isYou && isOnline ? "online" : !isYou && !isOnline ? "offline" : "" !isYou && isOnline ? "online" : !isYou && !isOnline ? "offline" : ""
} }
onClick={() => setShowMenu((e) => !e)} onClick={() => {
if (identity) setShowMenu((e) => !e);
}}
> >
{showMenu && <ContactMenu id={contact.id} setShowMenu={setShowMenu} />} {showMenu && <ContactMenu id={contact.id} setShowMenu={setShowMenu} />}
<UserLogo <UserLogo

View File

@ -20,6 +20,7 @@ const MembersWrapper = styled.div`
flex-direction: column; flex-direction: column;
background-color: ${({ theme }) => theme.sectionBackgroundColor}; background-color: ${({ theme }) => theme.sectionBackgroundColor};
padding: 16px; padding: 16px;
overflow-y: scroll;
`; `;
const MemberHeading = styled.h2` const MemberHeading = styled.h2`

View File

@ -12,11 +12,7 @@ import { LogoutModalName } from "../Modals/LogoutModal";
import { Member } from "./Member"; import { Member } from "./Member";
interface MembersListProps { export function MembersList() {
switchShowMembers?: () => void;
}
export function MembersList({ switchShowMembers }: MembersListProps) {
const { contacts, nickname } = useMessengerContext(); const { contacts, nickname } = useMessengerContext();
const identity = useIdentity(); const identity = useIdentity();
const { setModal } = useModal(LogoutModalName); const { setModal } = useModal(LogoutModalName);
@ -68,7 +64,6 @@ export function MembersList({ switchShowMembers }: MembersListProps) {
key={contact.id} key={contact.id}
contact={contact} contact={contact}
isOnline={contact.online} isOnline={contact.online}
switchShowMembers={switchShowMembers}
/> />
))} ))}
</MemberCategory> </MemberCategory>
@ -81,7 +76,6 @@ export function MembersList({ switchShowMembers }: MembersListProps) {
key={contact.id} key={contact.id}
contact={contact} contact={contact}
isOnline={contact.online} isOnline={contact.online}
switchShowMembers={switchShowMembers}
/> />
))} ))}
</MemberCategory> </MemberCategory>
@ -93,7 +87,6 @@ export function MembersList({ switchShowMembers }: MembersListProps) {
const MembersListWrap = styled.div` const MembersListWrap = styled.div`
display: flex; display: flex;
flex-direction: column; flex-direction: column;
overflow-y: scroll;
&::-webkit-scrollbar { &::-webkit-scrollbar {
width: 0; width: 0;

View File

@ -113,7 +113,7 @@ export function UiMessage({
<UserMessageWrapper> <UserMessageWrapper>
<Icon <Icon
onClick={() => { onClick={() => {
setShowMenu((e) => !e); if (identity) setShowMenu((e) => !e);
}} }}
> >
{showMenu && ( {showMenu && (

View File

@ -15,7 +15,7 @@ export function NarrowMembers({ switchShowMembersList }: NarrowMembersProps) {
list="Community members" list="Community members"
onBtnClick={switchShowMembersList} onBtnClick={switchShowMembersList}
/> />
<MembersList switchShowMembers={switchShowMembersList} /> <MembersList />
</ListWrapper> </ListWrapper>
); );
} }