From 44adc496b6b3a511a1febdee81bbf6157decb6d4 Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Fri, 27 Aug 2021 21:08:42 +0300 Subject: [PATCH] Left Search: Do not show unneeded context menu items --- .../left/search/LeftSearchResultChat.tsx | 2 +- src/hooks/useChatContextActions.ts | 35 +++++++++---------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/components/left/search/LeftSearchResultChat.tsx b/src/components/left/search/LeftSearchResultChat.tsx index bfdc8520..e5b28baf 100644 --- a/src/components/left/search/LeftSearchResultChat.tsx +++ b/src/components/left/search/LeftSearchResultChat.tsx @@ -48,7 +48,7 @@ const LeftSearchResultChat: FC = ({ isPinned, isMuted, handleDelete: openDeleteModal, - }); + }, true); const handleClick = () => { onClick(chatId); diff --git a/src/hooks/useChatContextActions.ts b/src/hooks/useChatContextActions.ts index 119fc2b7..b8d64a2c 100644 --- a/src/hooks/useChatContextActions.ts +++ b/src/hooks/useChatContextActions.ts @@ -22,26 +22,20 @@ export default ({ folderId?: number; isPinned?: boolean; isMuted?: boolean; -}) => { +}, isInSearch = false) => { const lang = useLang(); - const { - toggleChatPinned, - updateChatMutedState, - toggleChatArchived, - toggleChatUnread, - } = getDispatch(); - return useMemo(() => { if (!chat) { return undefined; } - const isChatWithSelf = privateChatUser?.isSelf; - - const actionUnreadMark = chat.unreadCount || chat.hasUnreadMark - ? { title: lang('MarkAsRead'), icon: 'readchats', handler: () => toggleChatUnread({ id: chat.id }) } - : { title: lang('MarkAsUnread'), icon: 'unread', handler: () => toggleChatUnread({ id: chat.id }) }; + const { + toggleChatPinned, + updateChatMutedState, + toggleChatArchived, + toggleChatUnread, + } = getDispatch(); const actionPin = isPinned ? { @@ -51,6 +45,14 @@ export default ({ } : { title: lang('PinToTop'), icon: 'pin', handler: () => toggleChatPinned({ id: chat.id, folderId }) }; + if (isInSearch) { + return [actionPin]; + } + + const actionUnreadMark = chat.unreadCount || chat.hasUnreadMark + ? { title: lang('MarkAsRead'), icon: 'readchats', handler: () => toggleChatUnread({ id: chat.id }) } + : { title: lang('MarkAsUnread'), icon: 'unread', handler: () => toggleChatUnread({ id: chat.id }) }; + const actionMute = isMuted ? { title: lang('ChatList.Unmute'), @@ -81,14 +83,11 @@ export default ({ return [ actionUnreadMark, actionPin, - ...(!isChatWithSelf ? [ + ...(!privateChatUser?.isSelf ? [ actionMute, actionArchive, ] : []), actionDelete, ]; - }, [ - chat, privateChatUser, lang, isPinned, handleDelete, toggleChatUnread, toggleChatPinned, folderId, - updateChatMutedState, toggleChatArchived, isMuted, - ]); + }, [chat, isPinned, lang, isInSearch, isMuted, handleDelete, privateChatUser?.isSelf, folderId]); };