@@ -18,18 +18,17 @@ limitations under the License.
18
18
19
19
import * as React from "react" ;
20
20
import { _t , _td } from "../../../languageHandler" ;
21
- import { Layout } from '../../../resizer/distributors/roomsublist2' ;
22
21
import { RovingTabIndexProvider } from "../../../accessibility/RovingTabIndex" ;
23
22
import { ResizeNotifier } from "../../../utils/ResizeNotifier" ;
24
- import RoomListStore , { LISTS_UPDATE_EVENT } from "../../../stores/room-list/RoomListStore2" ;
23
+ import RoomListStore , { LISTS_UPDATE_EVENT , RoomListStore2 } from "../../../stores/room-list/RoomListStore2" ;
25
24
import { ITagMap } from "../../../stores/room-list/algorithms/models" ;
26
25
import { DefaultTagID , TagID } from "../../../stores/room-list/models" ;
27
26
import { Dispatcher } from "flux" ;
28
27
import dis from "../../../dispatcher/dispatcher" ;
29
28
import RoomSublist2 from "./RoomSublist2" ;
30
29
import { ActionPayload } from "../../../dispatcher/payloads" ;
31
- import { IFilterCondition } from "../../../stores/room-list/filters/IFilterCondition" ;
32
30
import { NameFilterCondition } from "../../../stores/room-list/filters/NameFilterCondition" ;
31
+ import { ListLayout } from "../../../stores/room-list/ListLayout" ;
33
32
34
33
/*******************************************************************
35
34
* CAUTION *
@@ -50,6 +49,7 @@ interface IProps {
50
49
51
50
interface IState {
52
51
sublists : ITagMap ;
52
+ layouts : Map < TagID , ListLayout > ;
53
53
}
54
54
55
55
const TAG_ORDER : TagID [ ] = [
@@ -127,19 +127,15 @@ const TAG_AESTHETICS: {
127
127
} ;
128
128
129
129
export default class RoomList2 extends React . Component < IProps , IState > {
130
- private sublistRefs : { [ tagId : string ] : React . RefObject < RoomSublist2 > } = { } ;
131
- private sublistSizes : { [ tagId : string ] : number } = { } ;
132
- private sublistCollapseStates : { [ tagId : string ] : boolean } = { } ;
133
- private unfilteredLayout : Layout ;
134
- private filteredLayout : Layout ;
135
130
private searchFilter : NameFilterCondition = new NameFilterCondition ( ) ;
136
131
137
132
constructor ( props : IProps ) {
138
133
super ( props ) ;
139
134
140
- this . state = { sublists : { } } ;
141
- this . loadSublistSizes ( ) ;
142
- this . prepareLayouts ( ) ;
135
+ this . state = {
136
+ sublists : { } ,
137
+ layouts : new Map < TagID , ListLayout > ( ) ,
138
+ } ;
143
139
}
144
140
145
141
public componentDidUpdate ( prevProps : Readonly < IProps > ) : void {
@@ -158,49 +154,16 @@ export default class RoomList2 extends React.Component<IProps, IState> {
158
154
}
159
155
160
156
public componentDidMount ( ) : void {
161
- RoomListStore . instance . on ( LISTS_UPDATE_EVENT , ( store ) => {
162
- console . log ( "new lists" , store . orderedLists ) ;
163
- this . setState ( { sublists : store . orderedLists } ) ;
164
- } ) ;
165
- }
166
-
167
- private loadSublistSizes ( ) {
168
- const sizesJson = window . localStorage . getItem ( "mx_roomlist_sizes" ) ;
169
- if ( sizesJson ) this . sublistSizes = JSON . parse ( sizesJson ) ;
170
-
171
- const collapsedJson = window . localStorage . getItem ( "mx_roomlist_collapsed" ) ;
172
- if ( collapsedJson ) this . sublistCollapseStates = JSON . parse ( collapsedJson ) ;
173
- }
157
+ RoomListStore . instance . on ( LISTS_UPDATE_EVENT , ( store : RoomListStore2 ) => {
158
+ const newLists = store . orderedLists ;
159
+ console . log ( "new lists" , newLists ) ;
174
160
175
- private saveSublistSizes ( ) {
176
- window . localStorage . setItem ( "mx_roomlist_sizes" , JSON . stringify ( this . sublistSizes ) ) ;
177
- window . localStorage . setItem ( "mx_roomlist_collapsed" , JSON . stringify ( this . sublistCollapseStates ) ) ;
178
- }
179
-
180
- private prepareLayouts ( ) {
181
- // TODO: Change layout engine for FTUE support
182
- this . unfilteredLayout = new Layout ( ( tagId : string , height : number ) => {
183
- const sublist = this . sublistRefs [ tagId ] ;
184
- if ( sublist ) sublist . current . setHeight ( height ) ;
185
-
186
- // TODO: Check overflow (see old impl)
187
-
188
- // Don't store a height for collapsed sublists
189
- if ( ! this . sublistCollapseStates [ tagId ] ) {
190
- this . sublistSizes [ tagId ] = height ;
191
- this . saveSublistSizes ( ) ;
161
+ const layoutMap = new Map < TagID , ListLayout > ( ) ;
162
+ for ( const tagId of Object . keys ( newLists ) ) {
163
+ layoutMap . set ( tagId , new ListLayout ( tagId ) ) ;
192
164
}
193
- } , this . sublistSizes , this . sublistCollapseStates , {
194
- allowWhitespace : false ,
195
- handleHeight : 1 ,
196
- } ) ;
197
165
198
- this . filteredLayout = new Layout ( ( tagId : string , height : number ) => {
199
- const sublist = this . sublistRefs [ tagId ] ;
200
- if ( sublist ) sublist . current . setHeight ( height ) ;
201
- } , null , null , {
202
- allowWhitespace : false ,
203
- handleHeight : 0 ,
166
+ this . setState ( { sublists : newLists , layouts : layoutMap } ) ;
204
167
} ) ;
205
168
}
206
169
@@ -226,16 +189,19 @@ export default class RoomList2 extends React.Component<IProps, IState> {
226
189
if ( ! aesthetics ) throw new Error ( `Tag ${ orderedTagId } does not have aesthetics` ) ;
227
190
228
191
const onAddRoomFn = aesthetics . onAddRoom ? ( ) => aesthetics . onAddRoom ( dis ) : null ;
229
- components . push ( < RoomSublist2
230
- key = { `sublist-${ orderedTagId } ` }
231
- forRooms = { true }
232
- rooms = { orderedRooms }
233
- startAsHidden = { aesthetics . defaultHidden }
234
- label = { _t ( aesthetics . sectionLabel ) }
235
- onAddRoom = { onAddRoomFn }
236
- addRoomLabel = { aesthetics . addRoomLabel }
237
- isInvite = { aesthetics . isInvite }
238
- /> ) ;
192
+ components . push (
193
+ < RoomSublist2
194
+ key = { `sublist-${ orderedTagId } ` }
195
+ forRooms = { true }
196
+ rooms = { orderedRooms }
197
+ startAsHidden = { aesthetics . defaultHidden }
198
+ label = { _t ( aesthetics . sectionLabel ) }
199
+ onAddRoom = { onAddRoomFn }
200
+ addRoomLabel = { aesthetics . addRoomLabel }
201
+ isInvite = { aesthetics . isInvite }
202
+ layout = { this . state . layouts . get ( orderedTagId ) }
203
+ />
204
+ ) ;
239
205
}
240
206
241
207
return components ;
@@ -250,7 +216,7 @@ export default class RoomList2 extends React.Component<IProps, IState> {
250
216
onFocus = { this . props . onFocus }
251
217
onBlur = { this . props . onBlur }
252
218
onKeyDown = { onKeyDownHandler }
253
- className = "mx_RoomList"
219
+ className = "mx_RoomList mx_RoomList2 "
254
220
role = "tree"
255
221
aria-label = { _t ( "Rooms" ) }
256
222
// Firefox sometimes makes this element focusable due to
0 commit comments