@@ -14,35 +14,30 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- import React , { ComponentType , createRef , ReactComponentElement , RefObject } from "react" ;
18- import { Room } from "matrix-js-sdk/src/models/room" ;
19- import { RoomType , EventType } from "matrix-js-sdk/src/@types/event" ;
2017import * as fbEmitter from "fbemitter" ;
18+ import { EventType , RoomType } from "matrix-js-sdk/src/@types/event" ;
19+ import { Room } from "matrix-js-sdk/src/models/room" ;
20+ import React , { ComponentType , createRef , ReactComponentElement , RefObject } from "react" ;
2121
22- import { _t , _td } from "../../../languageHandler" ;
2322import { IState as IRovingTabIndexState , RovingTabIndexProvider } from "../../../accessibility/RovingTabIndex" ;
24- import ResizeNotifier from "../../../utils/ResizeNotifier" ;
25- import RoomListStore , { LISTS_UPDATE_EVENT } from "../../../stores/room-list/RoomListStore" ;
26- import { RoomViewStore } from "../../../stores/RoomViewStore" ;
27- import { ITagMap } from "../../../stores/room-list/algorithms/models" ;
28- import { DefaultTagID , TagID } from "../../../stores/room-list/models" ;
23+ import MatrixClientContext from "../../../contexts/MatrixClientContext" ;
24+ import { shouldShowComponent } from "../../../customisations/helpers/UIComponents" ;
25+ import { Action } from "../../../dispatcher/actions" ;
2926import defaultDispatcher from "../../../dispatcher/dispatcher" ;
30- import RoomSublist , { IAuxButtonProps } from "./RoomSublist" ;
3127import { ActionPayload } from "../../../dispatcher/payloads" ;
32- import { MatrixClientPeg } from "../../../MatrixClientPeg" ;
33- import ExtraTile from "./ExtraTile" ;
34- import { Action } from "../../../dispatcher/actions" ;
3528import { ViewRoomDeltaPayload } from "../../../dispatcher/payloads/ViewRoomDeltaPayload" ;
29+ import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload" ;
30+ import { useEventEmitterState } from "../../../hooks/useEventEmitter" ;
31+ import { _t , _td } from "../../../languageHandler" ;
32+ import { MatrixClientPeg } from "../../../MatrixClientPeg" ;
33+ import PosthogTrackers from "../../../PosthogTrackers" ;
34+ import SettingsStore from "../../../settings/SettingsStore" ;
35+ import { UIComponent } from "../../../settings/UIFeature" ;
3636import { RoomNotificationStateStore } from "../../../stores/notifications/RoomNotificationStateStore" ;
37- import { arrayFastClone , arrayHasDiff } from "../../../utils/arrays" ;
38- import { objectShallowClone , objectWithOnly } from "../../../utils/objects" ;
39- import IconizedContextMenu , {
40- IconizedContextMenuOption ,
41- IconizedContextMenuOptionList ,
42- } from "../context_menus/IconizedContextMenu" ;
43- import AccessibleButton , { ButtonEvent } from "../elements/AccessibleButton" ;
44- import { BetaPill } from "../beta/BetaCard" ;
45- import SpaceStore from "../../../stores/spaces/SpaceStore" ;
37+ import { ITagMap } from "../../../stores/room-list/algorithms/models" ;
38+ import { DefaultTagID , TagID } from "../../../stores/room-list/models" ;
39+ import RoomListStore , { LISTS_UPDATE_EVENT } from "../../../stores/room-list/RoomListStore" ;
40+ import { RoomViewStore } from "../../../stores/RoomViewStore" ;
4641import {
4742 isMetaSpace ,
4843 ISuggestedRoom ,
@@ -51,17 +46,21 @@ import {
5146 UPDATE_SELECTED_SPACE ,
5247 UPDATE_SUGGESTED_ROOMS ,
5348} from "../../../stores/spaces" ;
49+ import SpaceStore from "../../../stores/spaces/SpaceStore" ;
50+ import { arrayFastClone , arrayHasDiff } from "../../../utils/arrays" ;
51+ import { objectShallowClone , objectWithOnly } from "../../../utils/objects" ;
52+ import ResizeNotifier from "../../../utils/ResizeNotifier" ;
5453import { shouldShowSpaceInvite , showAddExistingRooms , showCreateNewRoom , showSpaceInvite } from "../../../utils/space" ;
54+ import { ChevronFace , ContextMenuTooltipButton , useContextMenu } from "../../structures/ContextMenu" ;
5555import RoomAvatar from "../avatars/RoomAvatar" ;
56- import { shouldShowComponent } from "../../../customisations/helpers/UIComponents" ;
57- import { UIComponent } from "../../../settings/UIFeature" ;
56+ import { BetaPill } from "../beta/BetaCard" ;
57+ import IconizedContextMenu , {
58+ IconizedContextMenuOption ,
59+ IconizedContextMenuOptionList ,
60+ } from "../context_menus/IconizedContextMenu" ;
5861import AccessibleTooltipButton from "../elements/AccessibleTooltipButton" ;
59- import { useEventEmitterState } from "../../../hooks/useEventEmitter" ;
60- import { ChevronFace , ContextMenuTooltipButton , useContextMenu } from "../../structures/ContextMenu" ;
61- import MatrixClientContext from "../../../contexts/MatrixClientContext" ;
62- import SettingsStore from "../../../settings/SettingsStore" ;
63- import PosthogTrackers from "../../../PosthogTrackers" ;
64- import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload" ;
62+ import ExtraTile from "./ExtraTile" ;
63+ import RoomSublist , { IAuxButtonProps } from "./RoomSublist" ;
6564
6665interface IProps {
6766 onKeyDown : ( ev : React . KeyboardEvent , state : IRovingTabIndexState ) => void ;
@@ -76,7 +75,6 @@ interface IProps {
7675
7776interface IState {
7877 sublists : ITagMap ;
79- isNameFiltering : boolean ;
8078 currentRoomId ?: string ;
8179 suggestedRooms : ISuggestedRoom [ ] ;
8280}
@@ -403,7 +401,6 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
403401
404402 this . state = {
405403 sublists : { } ,
406- isNameFiltering : ! ! RoomListStore . instance . getFirstNameFilterCondition ( ) ,
407404 suggestedRooms : SpaceStore . instance . suggestedRooms ,
408405 } ;
409406 }
@@ -480,8 +477,7 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
480477 const previousListIds = Object . keys ( this . state . sublists ) ;
481478 const newListIds = Object . keys ( newLists ) ;
482479
483- const isNameFiltering = ! ! RoomListStore . instance . getFirstNameFilterCondition ( ) ;
484- let doUpdate = this . state . isNameFiltering !== isNameFiltering || arrayHasDiff ( previousListIds , newListIds ) ;
480+ let doUpdate = arrayHasDiff ( previousListIds , newListIds ) ;
485481 if ( ! doUpdate ) {
486482 // so we didn't have the visible sublists change, but did the contents of those
487483 // sublists change significantly enough to break the sticky headers? Probably, so
@@ -503,33 +499,12 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
503499 const newSublists = objectWithOnly ( newLists , newListIds ) ;
504500 const sublists = objectShallowClone ( newSublists , ( k , v ) => arrayFastClone ( v ) ) ;
505501
506- this . setState ( { sublists, isNameFiltering } , ( ) => {
502+ this . setState ( { sublists } , ( ) => {
507503 this . props . onResize ( ) ;
508504 } ) ;
509505 }
510506 } ;
511507
512- private onStartChat = ( ev : ButtonEvent ) => {
513- const initialText = RoomListStore . instance . getFirstNameFilterCondition ( ) ?. search ;
514- defaultDispatcher . dispatch ( { action : "view_create_chat" , initialText } ) ;
515- PosthogTrackers . trackInteraction ( "WebRoomListRoomsSublistPlusMenuCreateChatItem" , ev ) ;
516- } ;
517-
518- private onExplore = ( ev : ButtonEvent ) => {
519- if ( ! isMetaSpace ( this . props . activeSpace ) ) {
520- defaultDispatcher . dispatch < ViewRoomPayload > ( {
521- action : Action . ViewRoom ,
522- room_id : this . props . activeSpace ,
523- metricsTrigger : undefined , // other
524- } ) ;
525- PosthogTrackers . trackInteraction ( "WebRoomListRoomsSublistPlusMenuExploreRoomsItem" , ev ) ;
526- } else {
527- const initialText = RoomListStore . instance . getFirstNameFilterCondition ( ) ?. search ;
528- defaultDispatcher . dispatch ( { action : Action . ViewRoomDirectory , initialText } ) ;
529- PosthogTrackers . trackInteraction ( "WebRoomListRoomsSublistPlusMenuExploreRoomsItem" , ev ) ;
530- }
531- } ;
532-
533508 private renderSuggestedRooms ( ) : ReactComponentElement < typeof ExtraTile > [ ] {
534509 return this . state . suggestedRooms . map ( room => {
535510 const name = room . name || room . canonical_alias || room . aliases ?. [ 0 ] || _t ( "Empty room" ) ;
@@ -573,8 +548,8 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
573548
574549 private renderSublists ( ) : React . ReactElement [ ] {
575550 // show a skeleton UI if the user is in no rooms and they are not filtering and have no suggested rooms
576- const showSkeleton = ! this . state . isNameFiltering && ! this . state . suggestedRooms ?. length &&
577- Object . values ( RoomListStore . instance . unfilteredLists ) . every ( list => ! list ?. length ) ;
551+ const showSkeleton = ! this . state . suggestedRooms ?. length &&
552+ Object . values ( RoomListStore . instance . orderedLists ) . every ( list => ! list ?. length ) ;
578553
579554 return TAG_ORDER
580555 . map ( orderedTagId => {
@@ -636,29 +611,6 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
636611 }
637612
638613 public render ( ) {
639- let explorePrompt : JSX . Element ;
640- if ( ! this . props . isMinimized ) {
641- if ( this . state . isNameFiltering ) {
642- explorePrompt = < div className = "mx_RoomList_explorePrompt" >
643- < div > { _t ( "Can't see what you're looking for?" ) } </ div >
644- < AccessibleButton
645- className = "mx_RoomList_explorePrompt_startChat"
646- kind = "link"
647- onClick = { this . onStartChat }
648- >
649- { _t ( "Start a new chat" ) }
650- </ AccessibleButton >
651- < AccessibleButton
652- className = "mx_RoomList_explorePrompt_explore"
653- kind = "link"
654- onClick = { this . onExplore }
655- >
656- { ! isMetaSpace ( this . props . activeSpace ) ? _t ( "Explore rooms" ) : _t ( "Explore all public rooms" ) }
657- </ AccessibleButton >
658- </ div > ;
659- }
660- }
661-
662614 const sublists = this . renderSublists ( ) ;
663615 return (
664616 < RovingTabIndexProvider handleHomeEnd handleUpDown onKeyDown = { this . props . onKeyDown } >
@@ -673,7 +625,6 @@ export default class RoomList extends React.PureComponent<IProps, IState> {
673625 ref = { this . treeRef }
674626 >
675627 { sublists }
676- { explorePrompt }
677628 </ div >
678629 ) }
679630 </ RovingTabIndexProvider >
0 commit comments