From ea0851eb9498f466490e1e13d7a1702bde1eb58e Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Tue, 13 Jul 2021 13:05:54 +0530 Subject: [PATCH] Keep memberlist panel open on room/grid change Signed-off-by: RMidhunSuresh --- src/domain/navigation/index.js | 12 ++++++++++++ src/domain/session/RoomGridViewModel.js | 8 +++----- src/domain/session/leftpanel/LeftPanelViewModel.js | 14 ++++++-------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/domain/navigation/index.js b/src/domain/navigation/index.js index 836f24f1..2f039eef 100644 --- a/src/domain/navigation/index.js +++ b/src/domain/navigation/index.js @@ -92,6 +92,16 @@ function pushRightPanelSegment(array, segment) { array.push(new Segment(segment)); } +export function addPanelIfNeeded(navigation, panel, path) { + const segment = navigation.path.get(panel); + let _path = path; + if (segment?.value) { + _path = _path.with(navigation.segment("right-panel")); + _path = _path.with(segment) + } + return _path; +} + export function parseUrlPath(urlPath, currentNavPath, defaultSessionId) { // substr(1) to take of initial / const parts = urlPath.substr(1).split("/"); @@ -122,6 +132,8 @@ export function parseUrlPath(urlPath, currentNavPath, defaultSessionId) { segments.push(new Segment("room", roomId)); if (currentNavPath.get("details")?.value) { pushRightPanelSegment(segments, "details"); + } else if (currentNavPath.get("members")?.value) { + pushRightPanelSegment(segments, "members"); } } else if (type === "last-session") { let sessionSegment = currentNavPath.get("session"); diff --git a/src/domain/session/RoomGridViewModel.js b/src/domain/session/RoomGridViewModel.js index e0f78b29..a193d48b 100644 --- a/src/domain/session/RoomGridViewModel.js +++ b/src/domain/session/RoomGridViewModel.js @@ -15,6 +15,7 @@ limitations under the License. */ import {ViewModel} from "../ViewModel.js"; +import {addPanelIfNeeded} from "../navigation/index.js"; function dedupeSparse(roomIds) { return roomIds.map((id, idx) => { @@ -79,13 +80,10 @@ export class RoomGridViewModel extends ViewModel { } _switchToRoom(roomId) { - const detailsShown = !!this.navigation.path.get("details")?.value; let path = this.navigation.path.until("rooms"); path = path.with(this.navigation.segment("room", roomId)); - if (detailsShown) { - path = path.with(this.navigation.segment("right-panel", true)); - path = path.with(this.navigation.segment("details", true)); - } + path = addPanelIfNeeded(this.navigation, "details", path); + path = addPanelIfNeeded(this.navigation, "members", path); this.navigation.applyPath(path); } diff --git a/src/domain/session/leftpanel/LeftPanelViewModel.js b/src/domain/session/leftpanel/LeftPanelViewModel.js index 0fdfcf36..549adf6a 100644 --- a/src/domain/session/leftpanel/LeftPanelViewModel.js +++ b/src/domain/session/leftpanel/LeftPanelViewModel.js @@ -20,6 +20,7 @@ import {RoomTileViewModel} from "./RoomTileViewModel.js"; import {InviteTileViewModel} from "./InviteTileViewModel.js"; import {RoomFilter} from "./RoomFilter.js"; import {ApplyMap} from "../../../observable/map/ApplyMap.js"; +import {addPanelIfNeeded} from "../../navigation/index.js"; export class LeftPanelViewModel extends ViewModel { constructor(options) { @@ -92,13 +93,10 @@ export class LeftPanelViewModel extends ViewModel { } } - _pathForDetails(path) { + _pathForRightPanel(path) { let _path = path; - const details = this.navigation.path.get("details"); - if (details?.value) { - _path = _path.with(this.navigation.segment("right-panel")); - _path = _path.with(details) - } + _path = addPanelIfNeeded(this.navigation, "details", _path); + _path = addPanelIfNeeded(this.navigation, "members", _path); return _path; } @@ -108,13 +106,13 @@ export class LeftPanelViewModel extends ViewModel { if (this.gridEnabled) { if (room) { path = path.with(room); - path = this._pathForDetails(path); + path = this._pathForRightPanel(path); } } else { if (room) { path = path.with(this.navigation.segment("rooms", [room.value])); path = path.with(room); - path = this._pathForDetails(path); + path = this._pathForRightPanel(path); } else { path = path.with(this.navigation.segment("rooms", [])); path = path.with(this.navigation.segment("empty-grid-tile", 0));