Make addPanelIfNeeded more generic

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-07-15 15:03:32 +05:30
parent b126ba1370
commit c7e12c98b5
3 changed files with 9 additions and 9 deletions

View file

@ -92,12 +92,14 @@ function pushRightPanelSegment(array, segment) {
array.push(new Segment(segment)); array.push(new Segment(segment));
} }
export function addPanelIfNeeded(navigation, panel, path) { export function addPanelIfNeeded(navigation, path) {
const segment = navigation.path.get(panel); const segments = navigation.path.segments;
const i = segments.findIndex(segment => segment.type === "right-panel");
let _path = path; let _path = path;
if (segment?.value) { if (i !== -1) {
_path = _path.with(navigation.segment("right-panel")); _path = path.until("room");
_path = _path.with(segment) _path = _path.with(segments[i]);
_path = _path.with(segments[i + 1]);
} }
return _path; return _path;
} }

View file

@ -82,8 +82,7 @@ export class RoomGridViewModel extends ViewModel {
_switchToRoom(roomId) { _switchToRoom(roomId) {
let path = this.navigation.path.until("rooms"); let path = this.navigation.path.until("rooms");
path = path.with(this.navigation.segment("room", roomId)); path = path.with(this.navigation.segment("room", roomId));
path = addPanelIfNeeded(this.navigation, "details", path); path = addPanelIfNeeded(this.navigation, path);
path = addPanelIfNeeded(this.navigation, "members", path);
this.navigation.applyPath(path); this.navigation.applyPath(path);
} }

View file

@ -95,8 +95,7 @@ export class LeftPanelViewModel extends ViewModel {
_pathForRightPanel(path) { _pathForRightPanel(path) {
let _path = path; let _path = path;
_path = addPanelIfNeeded(this.navigation, "details", _path); _path = addPanelIfNeeded(this.navigation, _path);
_path = addPanelIfNeeded(this.navigation, "members", _path);
return _path; return _path;
} }