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));
}
export function addPanelIfNeeded(navigation, panel, path) {
const segment = navigation.path.get(panel);
export function addPanelIfNeeded(navigation, path) {
const segments = navigation.path.segments;
const i = segments.findIndex(segment => segment.type === "right-panel");
let _path = path;
if (segment?.value) {
_path = _path.with(navigation.segment("right-panel"));
_path = _path.with(segment)
if (i !== -1) {
_path = path.until("room");
_path = _path.with(segments[i]);
_path = _path.with(segments[i + 1]);
}
return _path;
}

View file

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

View file

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