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

Commit 4079b03

Browse files
committed
Bring back filter all spaces behaviour
1 parent a70be45 commit 4079b03

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

src/components/structures/RoomSearch.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
import * as React from "react";
1818
import { createRef } from "react";
1919
import classNames from "classnames";
20+
import { Room } from "matrix-js-sdk/src/models/room";
2021

2122
import defaultDispatcher from "../../dispatcher/dispatcher";
2223
import { _t } from "../../languageHandler";
@@ -27,7 +28,7 @@ import RoomListStore from "../../stores/room-list/RoomListStore";
2728
import { NameFilterCondition } from "../../stores/room-list/filters/NameFilterCondition";
2829
import { getKeyBindingsManager, RoomListAction } from "../../KeyBindingsManager";
2930
import { replaceableComponent } from "../../utils/replaceableComponent";
30-
import SpaceStore, { UPDATE_SELECTED_SPACE } from "../../stores/SpaceStore";
31+
import SpaceStore, { UPDATE_SELECTED_SPACE, UPDATE_TOP_LEVEL_SPACES } from "../../stores/SpaceStore";
3132

3233
interface IProps {
3334
isMinimized: boolean;
@@ -41,6 +42,7 @@ interface IProps {
4142
interface IState {
4243
query: string;
4344
focused: boolean;
45+
inSpaces: boolean;
4446
}
4547

4648
@replaceableComponent("structures.RoomSearch")
@@ -55,11 +57,13 @@ export default class RoomSearch extends React.PureComponent<IProps, IState> {
5557
this.state = {
5658
query: "",
5759
focused: false,
60+
inSpaces: false,
5861
};
5962

6063
this.dispatcherRef = defaultDispatcher.register(this.onAction);
6164
// clear filter when changing spaces, in future we may wish to maintain a filter per-space
6265
SpaceStore.instance.on(UPDATE_SELECTED_SPACE, this.clearInput);
66+
SpaceStore.instance.on(UPDATE_TOP_LEVEL_SPACES, this.onSpaces);
6367
}
6468

6569
public componentDidUpdate(prevProps: Readonly<IProps>, prevState: Readonly<IState>): void {
@@ -80,8 +84,15 @@ export default class RoomSearch extends React.PureComponent<IProps, IState> {
8084
public componentWillUnmount() {
8185
defaultDispatcher.unregister(this.dispatcherRef);
8286
SpaceStore.instance.off(UPDATE_SELECTED_SPACE, this.clearInput);
87+
SpaceStore.instance.off(UPDATE_TOP_LEVEL_SPACES, this.onSpaces);
8388
}
8489

90+
private onSpaces = (spaces: Room[]) => {
91+
this.setState({
92+
inSpaces: spaces.length > 0,
93+
});
94+
};
95+
8596
private onAction = (payload: ActionPayload) => {
8697
if (payload.action === 'view_room' && payload.clear_search) {
8798
this.clearInput();
@@ -153,6 +164,11 @@ export default class RoomSearch extends React.PureComponent<IProps, IState> {
153164
'mx_RoomSearch_inputExpanded': this.state.query || this.state.focused,
154165
});
155166

167+
let placeholder = _t("Filter");
168+
if (this.state.inSpaces) {
169+
placeholder = _t("Filter all spaces");
170+
}
171+
156172
let icon = (
157173
<div className='mx_RoomSearch_icon' />
158174
);
@@ -166,7 +182,7 @@ export default class RoomSearch extends React.PureComponent<IProps, IState> {
166182
onBlur={this.onBlur}
167183
onChange={this.onChange}
168184
onKeyDown={this.onKeyDown}
169-
placeholder={_t("Filter")}
185+
placeholder={placeholder}
170186
autoComplete="off"
171187
/>
172188
);

src/components/views/rooms/RoomListNumResults.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import React, {useState} from "react";
1919
import { _t } from "../../../languageHandler";
2020
import RoomListStore, { LISTS_UPDATE_EVENT } from "../../../stores/room-list/RoomListStore";
2121
import {useEventEmitter} from "../../../hooks/useEventEmitter";
22+
import SpaceStore from "../../../stores/SpaceStore";
2223

2324
const RoomListNumResults: React.FC = () => {
2425
const [count, setCount] = useState<number>(null);
@@ -34,7 +35,10 @@ const RoomListNumResults: React.FC = () => {
3435
if (typeof count !== "number") return null;
3536

3637
return <div className="mx_LeftPanel_roomListFilterCount">
37-
{ _t("%(count)s results", { count }) }
38+
{ SpaceStore.instance.spacePanelSpaces.length
39+
? _t("%(count)s results in all spaces", { count })
40+
: _t("%(count)s results", { count })
41+
}
3842
</div>;
3943
};
4044

src/stores/room-list/RoomListStore.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,11 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
601601

602602
let rooms = this.matrixClient.getVisibleRooms().filter(r => VisibilityProvider.instance.isRoomVisible(r));
603603

604-
if (this.prefilterConditions.length > 0) {
604+
// if spaces are enabled only consider the prefilter conditions when there are no runtime conditions
605+
// for the search all spaces feature
606+
if (this.prefilterConditions.length > 0
607+
&& (!SettingsStore.getValue("feature_spaces") || !this.filterConditions.length)
608+
) {
605609
rooms = rooms.filter(r => {
606610
for (const filter of this.prefilterConditions) {
607611
if (!filter.isVisible(r)) {
@@ -660,7 +664,7 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
660664
* and thus might not cause an update to the store immediately.
661665
* @param {IFilterCondition} filter The filter condition to add.
662666
*/
663-
public addFilter(filter: IFilterCondition): void {
667+
public async addFilter(filter: IFilterCondition): Promise<void> {
664668
if (SettingsStore.getValue("advancedRoomListLogging")) {
665669
// TODO: Remove debug: https://github.com/vector-im/element-web/issues/14602
666670
console.log("Adding filter condition:", filter);
@@ -672,6 +676,12 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
672676
promise = this.recalculatePrefiltering();
673677
} else {
674678
this.filterConditions.push(filter);
679+
// Runtime filters with spaces disable prefiltering for the search all spaces feature
680+
if (SettingsStore.getValue("feature_spaces")) {
681+
// this has to be awaited so that `setKnownRooms` is called in time for the `addFilterCondition` below
682+
// this way the runtime filters are only evaluated on one dataset and not both.
683+
await this.recalculatePrefiltering();
684+
}
675685
if (this.algorithm) {
676686
this.algorithm.addFilterCondition(filter);
677687
}
@@ -699,6 +709,10 @@ export class RoomListStoreClass extends AsyncStoreWithClient<IState> {
699709
if (this.algorithm) {
700710
this.algorithm.removeFilterCondition(filter);
701711
}
712+
// Runtime filters with spaces disable prefiltering for the search all spaces feature
713+
if (SettingsStore.getValue("feature_spaces")) {
714+
promise = this.recalculatePrefiltering();
715+
}
702716
}
703717
idx = this.prefilterConditions.indexOf(filter);
704718
if (idx >= 0) {

0 commit comments

Comments
 (0)