From 6c4acf8935f3bab45e44e1bab085ce3c938cfd2e Mon Sep 17 00:00:00 2001 From: Alexander Zinchuk Date: Mon, 30 Jan 2023 19:13:15 +0100 Subject: [PATCH] Profile Info: Save state for multi-tabs (#2434) --- src/global/actions/ui/chats.ts | 1 + src/global/actions/ui/misc.ts | 9 ++++++--- src/global/cache.ts | 1 + src/global/init.ts | 1 + src/global/types.ts | 1 + 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/global/actions/ui/chats.ts b/src/global/actions/ui/chats.ts index d1cedde26..ab3def4d3 100644 --- a/src/global/actions/ui/chats.ts +++ b/src/global/actions/ui/chats.ts @@ -87,6 +87,7 @@ addActionHandler('openChatWithInfo', (global, actions, payload): ActionReturnTyp ...selectTabState(global, tabId), isChatInfoShown: true, }, tabId); + global = { ...global, lastIsChatInfoShown: true }; setGlobal(global); actions.openChat({ ...payload, tabId }); diff --git a/src/global/actions/ui/misc.ts b/src/global/actions/ui/misc.ts index 92c6ee4ec..7099f3638 100644 --- a/src/global/actions/ui/misc.ts +++ b/src/global/actions/ui/misc.ts @@ -26,9 +26,12 @@ const MAX_STORED_EMOJIS = 8 * 4; // Represents four rows of recent emojis addActionHandler('toggleChatInfo', (global, actions, payload): ActionReturnType => { const { force, tabId = getCurrentTabId() } = payload || {}; - return updateTabState(global, { - isChatInfoShown: force !== undefined ? force : !selectTabState(global, tabId).isChatInfoShown, - }, tabId); + const isChatInfoShown = force !== undefined ? force : !selectTabState(global, tabId).isChatInfoShown; + + global = updateTabState(global, { isChatInfoShown }, tabId); + global = { ...global, lastIsChatInfoShown: isChatInfoShown }; + + return global; }); addActionHandler('setLeftColumnWidth', (global, actions, payload): ActionReturnType => { diff --git a/src/global/cache.ts b/src/global/cache.ts index 236c0cfb4..c6fba4a8f 100644 --- a/src/global/cache.ts +++ b/src/global/cache.ts @@ -384,6 +384,7 @@ export function serializeGlobal(global: T) { 'serviceNotifications', 'attachmentSettings', 'leftColumnWidth', + 'lastIsChatInfoShown', ]), customEmojis: reduceCustomEmojis(global), users: reduceUsers(global), diff --git a/src/global/init.ts b/src/global/init.ts index 1bbac9d10..ce6382e92 100644 --- a/src/global/init.ts +++ b/src/global/init.ts @@ -48,6 +48,7 @@ addActionHandler('init', (global, actions, payload): ActionReturnType => { const initialTabState = cloneDeep(INITIAL_TAB_STATE); initialTabState.id = tabId; + initialTabState.isChatInfoShown = Boolean(global.lastIsChatInfoShown); global = { ...global, byTabId: { diff --git a/src/global/types.ts b/src/global/types.ts index e46ec14a5..780cbb991 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -534,6 +534,7 @@ export type GlobalState = { serverTimeOffset: number; blurredTabTokens: number[]; leftColumnWidth?: number; + lastIsChatInfoShown?: boolean; initialUnreadNotifications?: number; notificationIndex?: number; allNotificationsCount?: number;