From ef6880c1665df3d766c3b6aff5fdec457a194a6a Mon Sep 17 00:00:00 2001 From: Pavel Prichodko <14926950+prichodko@users.noreply.github.com> Date: Sun, 9 Oct 2022 17:47:34 -0500 Subject: [PATCH] allow interaction only if account is member --- .../status-react/src/protocol/use-account.tsx | 2 +- .../chat/components/chat-input/index.tsx | 19 +++++++++++- .../chat/components/chat-message/index.tsx | 9 +++--- .../components/chat-message/reactions.tsx | 30 +++++++++++-------- .../status-react/src/routes/chat/index.tsx | 5 ++-- 5 files changed, 44 insertions(+), 21 deletions(-) diff --git a/packages/status-react/src/protocol/use-account.tsx b/packages/status-react/src/protocol/use-account.tsx index 2b6ede98..1e1c1b4f 100644 --- a/packages/status-react/src/protocol/use-account.tsx +++ b/packages/status-react/src/protocol/use-account.tsx @@ -9,7 +9,7 @@ export const useAccount = () => { account, createAccount: () => client.createAccount(), deleteAccount: () => client.deleteAccount(), - isMember: account ? client.community.isMember(account.chatKey) : false, + isMember: account?.membership === 'approved', } as const } diff --git a/packages/status-react/src/routes/chat/components/chat-input/index.tsx b/packages/status-react/src/routes/chat/components/chat-input/index.tsx index 3db7bb52..30cff605 100644 --- a/packages/status-react/src/routes/chat/components/chat-input/index.tsx +++ b/packages/status-react/src/routes/chat/components/chat-input/index.tsx @@ -1,6 +1,7 @@ import React, { useEffect, useRef, useState } from 'react' import { useChatContext } from '../../../../contexts/chat-context' +import { useAccount } from '../../../../protocol' // import { EmojiIcon } from '../../../../icons/emoji-icon' // import { GifIcon } from '../../../../icons/gif-icon' // import { ImageIcon } from '../../../../icons/image-icon' @@ -19,6 +20,8 @@ interface Props { export const ChatInput = (props: Props) => { const { value, editing, onSubmit } = props + const { isMember } = useAccount() + const [inputValue, setInputValue] = useState(value ?? '') const { state, dispatch } = useChatContext() @@ -56,10 +59,15 @@ export const ChatInput = (props: Props) => { {/* @@ -109,4 +117,13 @@ const Input = styled('input', { background: 'none', alignItems: 'center', width: '100%', + fontSize: '15px', + + '&:disabled': { + cursor: 'not-allowed', + }, + + '&::placeholder': { + color: '$accent-5', + }, }) diff --git a/packages/status-react/src/routes/chat/components/chat-message/index.tsx b/packages/status-react/src/routes/chat/components/chat-message/index.tsx index d42f4eef..bc98d8f0 100644 --- a/packages/status-react/src/routes/chat/components/chat-message/index.tsx +++ b/packages/status-react/src/routes/chat/components/chat-message/index.tsx @@ -6,7 +6,7 @@ import { useMatch } from 'react-router-dom' import { useChatContext } from '../../../../contexts/chat-context' // import { BellIcon } from '../../../../icons/bell-icon' // import { PinIcon } from '../../../../icons/pin-icon' -import { useProtocol } from '../../../../protocol' +import { useAccount, useProtocol } from '../../../../protocol' import { keyframes, styled } from '../../../../styles/config' import { Avatar, @@ -60,6 +60,7 @@ export const ChatMessage = (props: Props) => { const { message, collapse, highlight } = props const { client, account } = useProtocol() + const { isMember } = useAccount() const { params } = useMatch(':id')! const chatId = params.id! @@ -237,7 +238,7 @@ export const ChatMessage = (props: Props) => { {response && } {renderMessage()} - {account && ( + {isMember && ( { const { reactions, onClick } = props + const { isMember } = useAccount() + const [open, setOpen] = useState(false) - const hasReaction = Object.values(reactions).some(value => value.size > 0) + const hasReaction = useMemo(() => { + return Object.values(reactions).some(value => value.size > 0) + }, [reactions]) if (hasReaction === false) { return null @@ -43,16 +47,18 @@ export const MessageReactions = (props: Props) => { /> ))} - - - - - + {isMember && ( + + + + + + )} ) } diff --git a/packages/status-react/src/routes/chat/index.tsx b/packages/status-react/src/routes/chat/index.tsx index cd0f909b..5fb625f4 100644 --- a/packages/status-react/src/routes/chat/index.tsx +++ b/packages/status-react/src/routes/chat/index.tsx @@ -6,7 +6,7 @@ import { useLocation, useMatch } from 'react-router-dom' import { MemberSidebar } from '../../components/member-sidebar' import { useAppState } from '../../contexts/app-context' import { ChatProvider, useChatContext } from '../../contexts/chat-context' -import { useAccount, useChat, useMessages, useProtocol } from '../../protocol' +import { useChat, useMessages, useProtocol } from '../../protocol' import { styled } from '../../styles/config' import { Avatar, Flex, Heading, Text } from '../../system' import { ChatInput } from './components/chat-input' @@ -44,7 +44,6 @@ const ChatStart = (props: ChatStartProps) => { const Body = () => { const { client } = useProtocol() const { state } = useChatContext() - const { account } = useAccount() const { params } = useMatch(':id')! // eslint-disable-line @typescript-eslint/no-non-null-assertion const chatId = params.id! @@ -125,7 +124,7 @@ const Body = () => { return ( <> {renderContent()} - {account && } + ) }