Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 8369d42

Browse files
committed
Hoist activeSpace tracking from RoomList to LeftPanel
1 parent ee5d0d6 commit 8369d42

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

src/components/structures/LeftPanel.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ limitations under the License.
1616

1717
import * as React from "react";
1818
import { createRef } from "react";
19+
import classNames from "classnames";
20+
import { Room } from "matrix-js-sdk/src/models/room";
21+
1922
import GroupFilterPanel from "./GroupFilterPanel";
2023
import CustomRoomTagPanel from "./CustomRoomTagPanel";
21-
import classNames from "classnames";
2224
import dis from "../../dispatcher/dispatcher";
2325
import { _t } from "../../languageHandler";
2426
import RoomList from "../views/rooms/RoomList";
@@ -40,6 +42,7 @@ import RoomListNumResults from "../views/rooms/RoomListNumResults";
4042
import LeftPanelWidget from "./LeftPanelWidget";
4143
import {replaceableComponent} from "../../utils/replaceableComponent";
4244
import {mediaFromMxc} from "../../customisations/Media";
45+
import SpaceStore, {UPDATE_SELECTED_SPACE} from "../../stores/SpaceStore";
4346

4447
interface IProps {
4548
isMinimized: boolean;
@@ -49,6 +52,7 @@ interface IProps {
4952
interface IState {
5053
showBreadcrumbs: boolean;
5154
showGroupFilterPanel: boolean;
55+
activeSpace?: Room;
5256
}
5357

5458
// List of CSS classes which should be included in keyboard navigation within the room list
@@ -74,11 +78,13 @@ export default class LeftPanel extends React.Component<IProps, IState> {
7478
this.state = {
7579
showBreadcrumbs: BreadcrumbsStore.instance.visible,
7680
showGroupFilterPanel: SettingsStore.getValue('TagPanel.enableTagPanel'),
81+
activeSpace: SpaceStore.instance.activeSpace,
7782
};
7883

7984
BreadcrumbsStore.instance.on(UPDATE_EVENT, this.onBreadcrumbsUpdate);
8085
RoomListStore.instance.on(LISTS_UPDATE_EVENT, this.onBreadcrumbsUpdate);
8186
OwnProfileStore.instance.on(UPDATE_EVENT, this.onBackgroundImageUpdate);
87+
SpaceStore.instance.on(UPDATE_SELECTED_SPACE, this.updateActiveSpace);
8288
this.bgImageWatcherRef = SettingsStore.watchSetting(
8389
"RoomList.backgroundImage", null, this.onBackgroundImageUpdate);
8490
this.groupFilterPanelWatcherRef = SettingsStore.watchSetting("TagPanel.enableTagPanel", null, () => {
@@ -96,9 +102,14 @@ export default class LeftPanel extends React.Component<IProps, IState> {
96102
BreadcrumbsStore.instance.off(UPDATE_EVENT, this.onBreadcrumbsUpdate);
97103
RoomListStore.instance.off(LISTS_UPDATE_EVENT, this.onBreadcrumbsUpdate);
98104
OwnProfileStore.instance.off(UPDATE_EVENT, this.onBackgroundImageUpdate);
105+
SpaceStore.instance.off(UPDATE_SELECTED_SPACE, this.updateActiveSpace);
99106
this.props.resizeNotifier.off("middlePanelResizedNoisy", this.onResize);
100107
}
101108

109+
private updateActiveSpace = (activeSpace: Room) => {
110+
this.setState({ activeSpace });
111+
};
112+
102113
private onExplore = () => {
103114
dis.fire(Action.ViewRoomDirectory);
104115
};
@@ -407,6 +418,7 @@ export default class LeftPanel extends React.Component<IProps, IState> {
407418
onBlur={this.onBlur}
408419
isMinimized={this.props.isMinimized}
409420
onResize={this.onResize}
421+
activeSpace={this.state.activeSpace}
410422
/>;
411423

412424
const containerClasses = classNames({

src/components/views/rooms/RoomList.tsx

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ interface IProps {
6666
onResize: () => void;
6767
resizeNotifier: ResizeNotifier;
6868
isMinimized: boolean;
69+
activeSpace: Room;
6970
}
7071

7172
interface IState {
7273
sublists: ITagMap;
7374
isNameFiltering: boolean;
7475
currentRoomId?: string;
75-
activeSpace: Room;
7676
suggestedRooms: ISpaceSummaryRoom[];
7777
}
7878

@@ -200,7 +200,7 @@ const TAG_AESTHETICS: ITagAestheticsMap = {
200200
/>
201201
<IconizedContextMenuOption
202202
label={_t("Explore rooms")}
203-
iconClassName="mx_RoomList_iconExplore"
203+
iconClassName="mx_RoomList_iconBrowse"
204204
onClick={(e) => {
205205
e.preventDefault();
206206
e.stopPropagation();
@@ -287,7 +287,6 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
287287
this.state = {
288288
sublists: {},
289289
isNameFiltering: !!RoomListStore.instance.getFirstNameFilterCondition(),
290-
activeSpace: SpaceStore.instance.activeSpace,
291290
suggestedRooms: SpaceStore.instance.suggestedRooms,
292291
};
293292

@@ -300,15 +299,13 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
300299
}
301300

302301
public componentDidMount(): void {
303-
SpaceStore.instance.on(UPDATE_SELECTED_SPACE, this.updateActiveSpace);
304302
SpaceStore.instance.on(SUGGESTED_ROOMS, this.updateSuggestedRooms);
305303
RoomListStore.instance.on(LISTS_UPDATE_EVENT, this.updateLists);
306304
this.customTagStoreRef = CustomRoomTagStore.addListener(this.updateLists);
307305
this.updateLists(); // trigger the first update
308306
}
309307

310308
public componentWillUnmount() {
311-
SpaceStore.instance.off(UPDATE_SELECTED_SPACE, this.updateActiveSpace);
312309
SpaceStore.instance.off(SUGGESTED_ROOMS, this.updateSuggestedRooms);
313310
RoomListStore.instance.off(LISTS_UPDATE_EVENT, this.updateLists);
314311
defaultDispatcher.unregister(this.dispatcherRef);
@@ -374,10 +371,6 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
374371
return room;
375372
};
376373

377-
private updateActiveSpace = (activeSpace: Room) => {
378-
this.setState({ activeSpace });
379-
};
380-
381374
private updateSuggestedRooms = (suggestedRooms: ISpaceSummaryRoom[]) => {
382375
this.setState({ suggestedRooms });
383376
};
@@ -438,20 +431,20 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
438431

439432
private onSpaceInviteClick = () => {
440433
const initialText = RoomListStore.instance.getFirstNameFilterCondition()?.search;
441-
if (this.state.activeSpace.getJoinRule() === "public") {
434+
if (this.props.activeSpace.getJoinRule() === "public") {
442435
const modal = Modal.createTrackedDialog("Space Invite", "User Menu", InfoDialog, {
443-
title: _t("Invite to %(spaceName)s", { spaceName: this.state.activeSpace.name }),
436+
title: _t("Invite to %(spaceName)s", { spaceName: this.props.activeSpace.name }),
444437
description: <React.Fragment>
445438
<span>{ _t("Share your public space") }</span>
446-
<SpacePublicShare space={this.state.activeSpace} onFinished={() => modal.close()} />
439+
<SpacePublicShare space={this.props.activeSpace} onFinished={() => modal.close()} />
447440
</React.Fragment>,
448441
fixedWidth: false,
449442
button: false,
450443
className: "mx_SpacePanel_sharePublicSpace",
451444
hasCloseButton: true,
452445
});
453446
} else {
454-
showRoomInviteDialog(this.state.activeSpace.roomId, initialText);
447+
showRoomInviteDialog(this.props.activeSpace.roomId, initialText);
455448
}
456449
};
457450

@@ -600,13 +593,13 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
600593
kind="link"
601594
onClick={this.onExplore}
602595
>
603-
{ this.state.activeSpace ? _t("Explore rooms") : _t("Explore all public rooms") }
596+
{ this.props.activeSpace ? _t("Explore rooms") : _t("Explore all public rooms") }
604597
</AccessibleButton>
605598
</div>;
606-
} else if (this.state.activeSpace) {
599+
} else if (this.props.activeSpace) {
607600
explorePrompt = <div className="mx_RoomList_explorePrompt">
608601
<div>{ _t("Quick actions") }</div>
609-
{ this.state.activeSpace.canInvite(MatrixClientPeg.get().getUserId()) && <AccessibleButton
602+
{ this.props.activeSpace.canInvite(MatrixClientPeg.get().getUserId()) && <AccessibleButton
610603
className="mx_RoomList_explorePrompt_spaceInvite"
611604
onClick={this.onSpaceInviteClick}
612605
>

0 commit comments

Comments
 (0)