Ensure the right panel stays the same between room changes if possible

Fixes https://github.com/vector-im/riot-web/issues/10149
This commit is contained in:
Travis Ralston 2019-12-05 23:48:05 -07:00
parent bbdff701b4
commit 4873b526df
3 changed files with 26 additions and 16 deletions

View file

@ -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;
}
}

View file

@ -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,

View file

@ -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,
];