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

Commit 38634f8

Browse files
authored
Space panel should watch spaces for space name changes (#7432)
1 parent 70dc035 commit 38634f8

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/components/views/rooms/RoomListHeader.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ const RoomListHeader = ({ spacePanelDisabled, onVisibilityChange }: IProps) => {
174174
}
175175
});
176176

177+
const spaceName = useEventEmitterState(activeSpace, "Room.name", () => activeSpace?.name);
178+
177179
useEffect(() => {
178180
if (onVisibilityChange) {
179181
onVisibilityChange();
@@ -320,7 +322,7 @@ const RoomListHeader = ({ spacePanelDisabled, onVisibilityChange }: IProps) => {
320322

321323
let title: string;
322324
if (activeSpace) {
323-
title = activeSpace.name;
325+
title = spaceName;
324326
} else if (communityId) {
325327
title = CommunityPrototypeStore.instance.getSelectedCommunityName();
326328
} else {
@@ -344,7 +346,7 @@ const RoomListHeader = ({ spacePanelDisabled, onVisibilityChange }: IProps) => {
344346
isExpanded={mainMenuDisplayed}
345347
className="mx_RoomListHeader_contextMenuButton"
346348
title={activeSpace
347-
? _t("%(spaceName)s menu", { spaceName: activeSpace.name })
349+
? _t("%(spaceName)s menu", { spaceName })
348350
: _t("Home options")}
349351
>
350352
{ title }

src/components/views/spaces/SpaceTreeLevel.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ export const SpaceButton: React.FC<IButtonProps> = ({
146146
};
147147

148148
interface IItemProps extends InputHTMLAttributes<HTMLLIElement> {
149-
space?: Room;
149+
space: Room;
150150
activeSpaces: SpaceKey[];
151151
isNested?: boolean;
152152
isPanelCollapsed?: boolean;
@@ -157,6 +157,7 @@ interface IItemProps extends InputHTMLAttributes<HTMLLIElement> {
157157
}
158158

159159
interface IItemState {
160+
name: string;
160161
collapsed: boolean;
161162
childSpaces: Room[];
162163
}
@@ -176,15 +177,18 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
176177
);
177178

178179
this.state = {
180+
name: this.props.space.name,
179181
collapsed,
180182
childSpaces: this.childSpaces,
181183
};
182184

183185
SpaceStore.instance.on(this.props.space.roomId, this.onSpaceUpdate);
186+
this.props.space.on("Room.name", this.onRoomNameChange);
184187
}
185188

186189
componentWillUnmount() {
187190
SpaceStore.instance.off(this.props.space.roomId, this.onSpaceUpdate);
191+
this.props.space.off("Room.name", this.onRoomNameChange);
188192
}
189193

190194
private onSpaceUpdate = () => {
@@ -193,6 +197,12 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
193197
});
194198
};
195199

200+
private onRoomNameChange = () => {
201+
this.setState({
202+
name: this.props.space.name,
203+
});
204+
};
205+
196206
private get childSpaces() {
197207
return SpaceStore.instance.getChildSpaces(this.props.space.roomId)
198208
.filter(s => !this.props.parents?.has(s.roomId));
@@ -318,7 +328,7 @@ export class SpaceItem extends React.PureComponent<IItemProps, IItemState> {
318328
space={space}
319329
className={isInvite ? "mx_SpaceButton_invite" : undefined}
320330
selected={activeSpaces.includes(space.roomId)}
321-
label={space.name}
331+
label={this.state.name}
322332
contextMenuTooltip={_t("Space options")}
323333
notificationState={notificationState}
324334
isNarrow={isPanelCollapsed}

src/hooks/useEventEmitter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ export const useEventEmitterState = <T>(
6565
const handler = useCallback((...args: any[]) => {
6666
setValue(fn(...args));
6767
}, [fn]);
68+
// re-run when the emitter changes
69+
useEffect(handler, [emitter]); // eslint-disable-line react-hooks/exhaustive-deps
6870
useEventEmitter(emitter, eventName, handler);
6971
return value;
7072
};

0 commit comments

Comments
 (0)