From b6abe0ee7ca70ba2857bc151451a3d4bce2d649b Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Sat, 19 Jun 2021 02:17:52 +0300 Subject: [PATCH] Message: Show context menu hint when selecting --- src/components/main/Notifications.tsx | 2 +- src/components/middle/message/Message.tsx | 10 ++++++++- src/global/cache.ts | 1 + src/global/initial.ts | 2 ++ src/global/types.ts | 5 ++++- src/modules/actions/ui/messages.ts | 25 +++++++++++++++++++++-- 6 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/components/main/Notifications.tsx b/src/components/main/Notifications.tsx index 98f1a1f72..f245e0d2c 100644 --- a/src/components/main/Notifications.tsx +++ b/src/components/main/Notifications.tsx @@ -24,7 +24,7 @@ const Notifications: FC = ({ notifications, dismissN
{notifications.map(({ message }) => ( ))} diff --git a/src/components/middle/message/Message.tsx b/src/components/middle/message/Message.tsx index e2edb2176..20bc8b930 100644 --- a/src/components/middle/message/Message.tsx +++ b/src/components/middle/message/Message.tsx @@ -148,7 +148,7 @@ type DispatchProps = Pick; const NBSP = '\u00A0'; @@ -215,6 +215,7 @@ const Message: FC = ({ setReplyingToId, openForwardMenu, clickInlineButton, + disableContextMenuHint, }) => { // eslint-disable-next-line no-null/no-null const ref = useRef(null); @@ -233,6 +234,12 @@ const Message: FC = ({ handleContextMenuClose, handleContextMenuHide, } = useContextMenuHandlers(ref, false, true); + useEffect(() => { + if (isContextMenuOpen) { + disableContextMenuHint(); + } + }, [isContextMenuOpen, disableContextMenuHint]); + const noAppearanceAnimation = appearanceOrder <= 0; const [isShown, markShown] = useFlag(noAppearanceAnimation); useEffect(() => { @@ -931,5 +938,6 @@ export default memo(withGlobal( 'setReplyingToId', 'openForwardMenu', 'clickInlineButton', + 'disableContextMenuHint', ]), )(Message)); diff --git a/src/global/cache.ts b/src/global/cache.ts index be1f863a1..4be5a72f5 100644 --- a/src/global/cache.ts +++ b/src/global/cache.ts @@ -118,6 +118,7 @@ function updateCache() { 'recentEmojis', 'emojiKeywords', 'push', + 'shouldShowContextMenuHint', ]), isChatInfoShown: reduceShowChatInfo(global), users: reduceUsers(global), diff --git a/src/global/initial.ts b/src/global/initial.ts index ffdc07eaf..a41a86f8e 100644 --- a/src/global/initial.ts +++ b/src/global/initial.ts @@ -133,4 +133,6 @@ export const INITIAL_STATE: GlobalState = { }, twoFaSettings: {}, + + shouldShowContextMenuHint: true, }; diff --git a/src/global/types.ts b/src/global/types.ts index f128609f0..03a15e81a 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -390,6 +390,9 @@ export type GlobalState = { safeLinkModalUrl?: string; historyCalendarSelectedAt?: number; + + // TODO To be removed in August 2021 + shouldShowContextMenuHint?: boolean; }; export type ActionTypes = ( @@ -398,7 +401,7 @@ export type ActionTypes = ( 'showNotification' | 'dismissNotification' | 'showError' | 'dismissError' | // ui 'toggleChatInfo' | 'setIsUiReady' | 'addRecentEmoji' | 'addRecentSticker' | 'toggleLeftColumn' | - 'toggleSafeLinkModal' | 'openHistoryCalendar' | 'closeHistoryCalendar' | + 'toggleSafeLinkModal' | 'openHistoryCalendar' | 'closeHistoryCalendar' | 'disableContextMenuHint' | // auth 'setAuthPhoneNumber' | 'setAuthCode' | 'setAuthPassword' | 'signUp' | 'returnToAuthPhoneNumber' | 'signOut' | 'setAuthRememberMe' | 'clearAuthError' | 'uploadProfilePhoto' | 'goToAuthQrCode' | 'clearCache' | diff --git a/src/modules/actions/ui/messages.ts b/src/modules/actions/ui/messages.ts index 9e882ee32..234182fd3 100644 --- a/src/modules/actions/ui/messages.ts +++ b/src/modules/actions/ui/messages.ts @@ -24,6 +24,7 @@ import { selectForwardedMessageIdsByGroupId, selectIsViewportNewest, selectReplyingToId, } from '../../selectors'; import { findLast } from '../../../util/iteratees'; +import { IS_TOUCH_ENV } from '../../../util/environment'; const FOCUS_DURATION = 2000; const POLL_RESULT_OPEN_DELAY_MS = 450; @@ -371,16 +372,36 @@ addReducer('toggleMessageSelection', (global, actions, payload) => { } = payload!; const currentMessageList = selectCurrentMessageList(global); if (!currentMessageList) { - return undefined; + return; } const { chatId, threadId, type: messageListType } = currentMessageList; - return toggleMessageSelection( + global = toggleMessageSelection( global, chatId, threadId, messageListType, messageId, groupedId, childMessageIds, withShift, ); + + setGlobal(global); + + if (global.shouldShowContextMenuHint) { + actions.disableContextMenuHint(); + actions.showNotification({ + // eslint-disable-next-line max-len + message: `To **edit** or **reply**, close this menu. Then ${IS_TOUCH_ENV ? 'long tap' : 'right click'} on a message.`, + }); + } }); +addReducer('disableContextMenuHint', (global) => { + if (!global.shouldShowContextMenuHint) { + return undefined; + } + + return { + ...global, + shouldShowContextMenuHint: false, + }; +}); addReducer('exitMessageSelectMode', exitMessageSelectMode);