@@ -17,6 +17,7 @@ limitations under the License.
1717import * as React from "react" ;
1818import { createRef } from "react" ;
1919import classNames from "classnames" ;
20+ import { Room } from "matrix-js-sdk/src/models/room" ;
2021
2122import defaultDispatcher from "../../dispatcher/dispatcher" ;
2223import { _t } from "../../languageHandler" ;
@@ -27,7 +28,7 @@ import RoomListStore from "../../stores/room-list/RoomListStore";
2728import { NameFilterCondition } from "../../stores/room-list/filters/NameFilterCondition" ;
2829import { getKeyBindingsManager , RoomListAction } from "../../KeyBindingsManager" ;
2930import { 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
3233interface IProps {
3334 isMinimized : boolean ;
@@ -41,6 +42,7 @@ interface IProps {
4142interface 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 ) ;
0 commit comments