mirror of
https://github.com/element-hq/element-web
synced 2024-11-23 17:56:01 +03:00
Merge pull request #5795 from SimonBrandner/spaces/context-switching
[Spaces] Context switching
This commit is contained in:
commit
b2e9f6731b
1 changed files with 30 additions and 0 deletions
|
@ -51,6 +51,12 @@ export const UPDATE_SELECTED_SPACE = Symbol("selected-space");
|
|||
|
||||
const MAX_SUGGESTED_ROOMS = 20;
|
||||
|
||||
const getLastViewedRoomsStorageKey = (space?: Room) => {
|
||||
const lastViewRooms = "mx_last_viewed_rooms";
|
||||
const homeSpace = "home_space";
|
||||
return `${lastViewRooms}_${space?.roomId || homeSpace}`;
|
||||
}
|
||||
|
||||
const partitionSpacesAndRooms = (arr: Room[]): [Room[], Room[]] => { // [spaces, rooms]
|
||||
return arr.reduce((result, room: Room) => {
|
||||
result[room.isSpaceRoom() ? 0 : 1].push(room);
|
||||
|
@ -111,6 +117,25 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
this.emit(UPDATE_SELECTED_SPACE, this.activeSpace);
|
||||
this.emit(SUGGESTED_ROOMS, this._suggestedRooms = []);
|
||||
|
||||
// view last selected room from space
|
||||
const roomId = window.localStorage.getItem(getLastViewedRoomsStorageKey(this.activeSpace));
|
||||
|
||||
if (roomId && this.matrixClient?.getRoom(roomId)?.getMyMembership() === "join") {
|
||||
defaultDispatcher.dispatch({
|
||||
action: "view_room",
|
||||
room_id: roomId,
|
||||
});
|
||||
} else if (space) {
|
||||
defaultDispatcher.dispatch({
|
||||
action: "view_room",
|
||||
room_id: space.roomId,
|
||||
});
|
||||
} else {
|
||||
defaultDispatcher.dispatch({
|
||||
action: "view_home_page",
|
||||
});
|
||||
}
|
||||
|
||||
// persist space selected
|
||||
if (space) {
|
||||
window.localStorage.setItem(ACTIVE_SPACE_LS_KEY, space.roomId);
|
||||
|
@ -488,6 +513,11 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
|
|||
case "view_room": {
|
||||
const room = this.matrixClient?.getRoom(payload.room_id);
|
||||
|
||||
// persist last viewed room from a space
|
||||
if (room) {
|
||||
window.localStorage.setItem(getLastViewedRoomsStorageKey(this.activeSpace), payload.room_id);
|
||||
}
|
||||
|
||||
if (room?.getMyMembership() === "join") {
|
||||
if (room.isSpaceRoom()) {
|
||||
this.setActiveSpace(room);
|
||||
|
|
Loading…
Reference in a new issue