From 4873b526df86d5d9f10454d16f05013d158283f8 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 5 Dec 2019 23:48:05 -0700 Subject: [PATCH] Ensure the right panel stays the same between room changes if possible Fixes https://github.com/vector-im/riot-web/issues/10149 --- src/components/structures/RightPanel.js | 16 +++++++++++++--- src/stores/RightPanelStore.js | 16 +++------------- src/stores/RightPanelStorePhases.js | 10 ++++++++++ 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/components/structures/RightPanel.js b/src/components/structures/RightPanel.js index 39aff9be8d..9f78e09c6e 100644 --- a/src/components/structures/RightPanel.js +++ b/src/components/structures/RightPanel.js @@ -28,7 +28,8 @@ import RateLimitedFunc from '../../ratelimitedfunc'; import { showGroupInviteDialog, showGroupAddRoomDialog } from '../../GroupAddressPicker'; import GroupStore from '../../stores/GroupStore'; import SettingsStore from "../../settings/SettingsStore"; -import {RIGHT_PANEL_PHASES} from "../../stores/RightPanelStorePhases"; +import {RIGHT_PANEL_PHASES, RIGHT_PANEL_PHASES_NO_ARGS} from "../../stores/RightPanelStorePhases"; +import RightPanelStore from "../../stores/RightPanelStore"; export default class RightPanel extends React.Component { static get propTypes() { @@ -63,12 +64,21 @@ export default class RightPanel extends React.Component { } _getPhaseFromProps() { + const rps = RightPanelStore.getSharedInstance(); if (this.props.groupId) { - return RIGHT_PANEL_PHASES.GroupMemberList; + if (!RIGHT_PANEL_PHASES_NO_ARGS.includes(rps.groupPanelPhase)) { + rps.setPhase(RIGHT_PANEL_PHASES.GroupMemberList); + return RIGHT_PANEL_PHASES.GroupMemberList; + } + return rps.groupPanelPhase; } else if (this.props.user) { return RIGHT_PANEL_PHASES.RoomMemberInfo; } else { - return RIGHT_PANEL_PHASES.RoomMemberList; + if (!RIGHT_PANEL_PHASES_NO_ARGS.includes(rps.roomPanelPhase)) { + rps.setPhase(RIGHT_PANEL_PHASES.RoomMemberList); + return RIGHT_PANEL_PHASES.RoomMemberList; + } + return rps.roomPanelPhase; } } diff --git a/src/stores/RightPanelStore.js b/src/stores/RightPanelStore.js index 8cb0df514a..520a458755 100644 --- a/src/stores/RightPanelStore.js +++ b/src/stores/RightPanelStore.js @@ -17,7 +17,7 @@ limitations under the License. import dis from '../dispatcher'; import {Store} from 'flux/utils'; import SettingsStore, {SettingLevel} from "../settings/SettingsStore"; -import {RIGHT_PANEL_PHASES} from "./RightPanelStorePhases"; +import {RIGHT_PANEL_PHASES, RIGHT_PANEL_PHASES_NO_ARGS} from "./RightPanelStorePhases"; const INITIAL_STATE = { // Whether or not to show the right panel at all. We split out rooms and groups @@ -32,16 +32,6 @@ const INITIAL_STATE = { const GROUP_PHASES = Object.keys(RIGHT_PANEL_PHASES).filter(k => k.startsWith("Group")); -// These are the phases that are safe to persist (the ones that don't require additional -// arguments, basically). -const PHASES_TO_PERSIST = [ - RIGHT_PANEL_PHASES.NotificationPanel, - RIGHT_PANEL_PHASES.FilePanel, - RIGHT_PANEL_PHASES.RoomMemberList, - RIGHT_PANEL_PHASES.GroupMemberList, - RIGHT_PANEL_PHASES.GroupRoomList, -]; - /** * A class for tracking the state of the right panel between layouts and * sessions. @@ -96,7 +86,7 @@ export default class RightPanelStore extends Store { this._state.showGroupPanel, ); - if (PHASES_TO_PERSIST.includes(this._state.lastRoomPhase)) { + if (RIGHT_PANEL_PHASES_NO_ARGS.includes(this._state.lastRoomPhase)) { SettingsStore.setValue( "lastRightPanelPhaseForRoom", null, @@ -104,7 +94,7 @@ export default class RightPanelStore extends Store { this._state.lastRoomPhase, ); } - if (PHASES_TO_PERSIST.includes(this._state.lastGroupPhase)) { + if (RIGHT_PANEL_PHASES_NO_ARGS.includes(this._state.lastGroupPhase)) { SettingsStore.setValue( "lastRightPanelPhaseForGroup", null, diff --git a/src/stores/RightPanelStorePhases.js b/src/stores/RightPanelStorePhases.js index 83a6d97345..96807ebf5b 100644 --- a/src/stores/RightPanelStorePhases.js +++ b/src/stores/RightPanelStorePhases.js @@ -29,3 +29,13 @@ export const RIGHT_PANEL_PHASES = Object.freeze({ GroupRoomInfo: 'GroupRoomInfo', GroupMemberInfo: 'GroupMemberInfo', }); + +// These are the phases that are safe to persist (the ones that don't require additional +// arguments). +export const RIGHT_PANEL_PHASES_NO_ARGS = [ + RIGHT_PANEL_PHASES.NotificationPanel, + RIGHT_PANEL_PHASES.FilePanel, + RIGHT_PANEL_PHASES.RoomMemberList, + RIGHT_PANEL_PHASES.GroupMemberList, + RIGHT_PANEL_PHASES.GroupRoomList, +];