@@ -178,46 +178,61 @@ export default class RoomSublist2 extends React.Component<IProps, IState> {
178
178
179
179
let content = null ;
180
180
if ( tiles . length > 0 ) {
181
+ const layout = this . props . layout ; // to shorten calls
182
+
181
183
// TODO: Lazy list rendering
182
184
// TODO: Whatever scrolling magic needs to happen here
183
- const layout = this . props . layout ; // to shorten calls
184
- const minTilesPx = layout . tilesToPixels ( Math . min ( tiles . length , layout . minVisibleTiles ) ) ;
185
- const maxTilesPx = layout . tilesToPixels ( tiles . length ) ;
186
- const tilesPx = layout . tilesToPixels ( Math . min ( tiles . length , layout . visibleTiles ) ) ;
187
- let handles = [ 's' ] ;
188
- if ( layout . visibleTiles >= tiles . length && tiles . length <= layout . minVisibleTiles ) {
189
- handles = [ ] ; // no handles, we're at a minimum
190
- }
191
185
192
- // TODO: This might need adjustment, however for now it is fine as a round.
193
- const nVisible = Math . round ( layout . visibleTiles ) ;
186
+ const nVisible = Math . floor ( layout . visibleTiles ) ;
194
187
const visibleTiles = tiles . slice ( 0 , nVisible ) ;
195
188
196
189
// If we're hiding rooms, show a 'show more' button to the user. This button
197
- // replaces the last visible tile, so will always show 2+ rooms. We do this
198
- // because if it said "show 1 more room" we had might as well show that room
199
- // instead. We also replace the last item so we don't have to adjust our math
200
- // on pixel heights, etc. It's much easier to pretend the button is a tile.
190
+ // floats above the resize handle, if we have one present
191
+ let showMoreButton = null ;
201
192
if ( tiles . length > nVisible ) {
202
193
// we have a cutoff condition - add the button to show all
203
-
204
- // we +1 to account for the room we're about to hide with our 'show more' button
205
- // this results in the button always being 1+, and not needing an i18n `count`.
206
- const numMissing = ( tiles . length - visibleTiles . length ) + 1 ;
207
-
208
- // TODO: CSS TBD
209
- // TODO: Make this an actual tile
210
- // TODO: This is likely to pop out of the list, consider that.
211
- visibleTiles . splice ( visibleTiles . length - 1 , 1 , (
212
- < div
213
- onClick = { this . onShowAllClick }
214
- className = 'mx_RoomSublist2_showMoreButton'
215
- key = 'showall'
216
- >
217
- { _t ( "Show %(n)s more" , { n : numMissing } ) }
194
+ const numMissing = tiles . length - visibleTiles . length ;
195
+ showMoreButton = (
196
+ < div onClick = { this . onShowAllClick } className = 'mx_RoomSublist2_showMoreButton' >
197
+ < span className = 'mx_RoomSublist2_showMoreButtonChevron' >
198
+ { /* set by CSS masking */ }
199
+ </ span >
200
+ < span className = 'mx_RoomSublist2_showMoreButtonText' >
201
+ { _t ( "Show %(count)s more" , { count : numMissing } ) }
202
+ </ span >
218
203
</ div >
219
- ) ) ;
204
+ ) ;
205
+ }
206
+
207
+ // Figure out if we need a handle
208
+ let handles = [ 's' ] ;
209
+ if ( layout . visibleTiles >= tiles . length && tiles . length <= layout . minVisibleTiles ) {
210
+ handles = [ ] ; // no handles, we're at a minimum
220
211
}
212
+
213
+ // We have to account for padding so we can accommodate a 'show more' button and
214
+ // the resize handle, which are pinned to the bottom of the container. This is the
215
+ // easiest way to have a resize handle below the button as otherwise we're writing
216
+ // our own resize handling and that doesn't sound fun.
217
+ //
218
+ // The layout class has some helpers for dealing with padding, as we don't want to
219
+ // apply it in all cases. If we apply it in all cases, the resizing feels like it
220
+ // goes backwards and can become wildly incorrect (visibleTiles says 18 when there's
221
+ // only mathematically 7 possible).
222
+
223
+ const showMoreHeight = 32 ; // As defined by CSS
224
+ const resizeHandleHeight = 4 ; // As defined by CSS
225
+
226
+ // The padding is variable though, so figure out what we need padding for.
227
+ let padding = 0 ;
228
+ if ( showMoreButton ) padding += showMoreHeight ;
229
+ if ( handles . length > 0 ) padding += resizeHandleHeight ;
230
+
231
+ const minTilesPx = layout . calculateTilesToPixelsMin ( tiles . length , layout . minVisibleTiles , padding ) ;
232
+ const maxTilesPx = layout . tilesToPixelsWithPadding ( tiles . length , padding ) ;
233
+ const tilesWithoutPadding = Math . min ( tiles . length , layout . visibleTiles ) ;
234
+ const tilesPx = layout . calculateTilesToPixelsMin ( tiles . length , tilesWithoutPadding , padding ) ;
235
+
221
236
content = (
222
237
< ResizableBox
223
238
width = { - 1 }
@@ -230,6 +245,7 @@ export default class RoomSublist2 extends React.Component<IProps, IState> {
230
245
className = "mx_RoomSublist2_resizeBox"
231
246
>
232
247
{ visibleTiles }
248
+ { showMoreButton }
233
249
</ ResizableBox >
234
250
)
235
251
}
0 commit comments