First implementation of context switching

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner 2021-03-25 16:15:41 +01:00
parent 356e4bc6fc
commit ef3d87f8e8
No known key found for this signature in database
GPG key ID: 9760693FDD98A790
2 changed files with 25 additions and 1 deletions

View file

@ -79,7 +79,7 @@ import { CommunityPrototypeStore } from "../../stores/CommunityPrototypeStore";
import DialPadModal from "../views/voip/DialPadModal"; import DialPadModal from "../views/voip/DialPadModal";
import { showToast as showMobileGuideToast } from '../../toasts/MobileGuideToast'; import { showToast as showMobileGuideToast } from '../../toasts/MobileGuideToast';
import { shouldUseLoginForWelcome } from "../../utils/pages"; import { shouldUseLoginForWelcome } from "../../utils/pages";
import SpaceStore from "../../stores/SpaceStore"; import SpaceStore, {LAST_VIEWED_ROOMS, LAST_VIEWED_ROOMS_HOME} from "../../stores/SpaceStore";
import SpaceRoomDirectory from "./SpaceRoomDirectory"; import SpaceRoomDirectory from "./SpaceRoomDirectory";
import {replaceableComponent} from "../../utils/replaceableComponent"; import {replaceableComponent} from "../../utils/replaceableComponent";
import RoomListStore from "../../stores/room-list/RoomListStore"; import RoomListStore from "../../stores/room-list/RoomListStore";
@ -875,6 +875,14 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
private viewRoom(roomInfo: IRoomInfo) { private viewRoom(roomInfo: IRoomInfo) {
this.focusComposer = true; this.focusComposer = true;
// persist last viewed room from a space
const activeSpace = SpaceStore.instance.activeSpace;
const activeSpaceId = activeSpace?.roomId || LAST_VIEWED_ROOMS_HOME;
const lastViewedRooms = JSON.parse(window.localStorage.getItem(LAST_VIEWED_ROOMS)) || {};
lastViewedRooms[activeSpaceId] = roomInfo.room_id;
window.localStorage.setItem(LAST_VIEWED_ROOMS, JSON.stringify(lastViewedRooms));
if (roomInfo.room_alias) { if (roomInfo.room_alias) {
console.log( console.log(
`Switching to room alias ${roomInfo.room_alias} at event ` + `Switching to room alias ${roomInfo.room_alias} at event ` +

View file

@ -41,6 +41,10 @@ type SpaceKey = string | symbol;
interface IState {} interface IState {}
const ACTIVE_SPACE_LS_KEY = "mx_active_space"; const ACTIVE_SPACE_LS_KEY = "mx_active_space";
export const LAST_VIEWED_ROOMS = "mx_last_viewed_rooms";
// We can't use HOME_SPACE here because JSON.stringify() will ignore any Symbols
export const LAST_VIEWED_ROOMS_HOME = "home_space";
export const HOME_SPACE = Symbol("home-space"); export const HOME_SPACE = Symbol("home-space");
export const SUGGESTED_ROOMS = Symbol("suggested-rooms"); export const SUGGESTED_ROOMS = Symbol("suggested-rooms");
@ -111,6 +115,18 @@ export class SpaceStoreClass extends AsyncStoreWithClient<IState> {
this.emit(UPDATE_SELECTED_SPACE, this.activeSpace); this.emit(UPDATE_SELECTED_SPACE, this.activeSpace);
this.emit(SUGGESTED_ROOMS, this._suggestedRooms = []); this.emit(SUGGESTED_ROOMS, this._suggestedRooms = []);
// view last selected room from space
const spaceId = space?.roomId || LAST_VIEWED_ROOMS_HOME;
const lastViewedRooms = JSON.parse(window.localStorage.getItem(LAST_VIEWED_ROOMS));
const roomId = lastViewedRooms[spaceId];
if (roomId) {
defaultDispatcher.dispatch({
action: "view_room",
room_id: roomId,
});
} // TODO: Handle else
// persist space selected // persist space selected
if (space) { if (space) {
window.localStorage.setItem(ACTIVE_SPACE_LS_KEY, space.roomId); window.localStorage.setItem(ACTIVE_SPACE_LS_KEY, space.roomId);