Skip to content

Commit 84e60ee

Browse files
committed
Add a 'show less' button to the new room list
1 parent 94f52c4 commit 84e60ee

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

res/css/views/rooms/_RoomSublist2.scss

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ limitations under the License.
100100
flex-direction: column;
101101
overflow: hidden;
102102

103-
.mx_RoomSublist2_showMoreButton {
103+
.mx_RoomSublist2_showNButton {
104104
cursor: pointer;
105105
font-size: $font-13px;
106106
line-height: $font-18px;
@@ -129,18 +129,25 @@ limitations under the License.
129129
display: flex;
130130
align-items: center;
131131

132-
.mx_RoomSublist2_showMoreButtonChevron {
132+
.mx_RoomSublist2_showNButtonChevron {
133133
position: relative;
134134
width: 16px;
135135
height: 16px;
136136
margin-left: 12px;
137137
margin-right: 18px;
138-
mask-image: url('$(res)/img/feather-customised/chevron-down.svg');
139138
mask-position: center;
140139
mask-size: contain;
141140
mask-repeat: no-repeat;
142141
background: $roomtile2-preview-color;
143142
}
143+
144+
.mx_RoomSublist2_showMoreButtonChevron {
145+
mask-image: url('$(res)/img/feather-customised/chevron-down.svg');
146+
}
147+
148+
.mx_RoomSublist2_showLessButtonChevron {
149+
mask-image: url('$(res)/img/feather-customised/chevron-up.svg');
150+
}
144151
}
145152

146153
// Class name comes from the ResizableBox component
@@ -239,10 +246,10 @@ limitations under the License.
239246
.mx_RoomSublist2_resizeBox {
240247
align-items: center;
241248

242-
.mx_RoomSublist2_showMoreButton {
249+
.mx_RoomSublist2_showNButton {
243250
flex-direction: column;
244251

245-
.mx_RoomSublist2_showMoreButtonChevron {
252+
.mx_RoomSublist2_showNButtonChevron {
246253
margin-right: 12px; // to center
247254
}
248255
}
Lines changed: 1 addition & 0 deletions
Loading

src/components/views/rooms/RoomSublist2.tsx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ export default class RoomSublist2 extends React.Component<IProps, IState> {
109109
this.forceUpdate(); // because the layout doesn't trigger a re-render
110110
};
111111

112+
private onShowLessClick = () => {
113+
this.props.layout.visibleTiles = this.props.layout.minVisibleTiles;
114+
this.forceUpdate(); // because the layout doesn't trigger a re-render
115+
};
116+
112117
private onOpenMenuClick = (ev: InputEvent) => {
113118
ev.preventDefault();
114119
ev.stopPropagation();
@@ -303,25 +308,42 @@ export default class RoomSublist2 extends React.Component<IProps, IState> {
303308
const visibleTiles = tiles.slice(0, nVisible);
304309

305310
// If we're hiding rooms, show a 'show more' button to the user. This button
306-
// floats above the resize handle, if we have one present
307-
let showMoreButton = null;
311+
// floats above the resize handle, if we have one present. If the user has all
312+
// tiles visible, it becomes 'show less'.
313+
let showNButton = null;
308314
if (tiles.length > nVisible) {
309315
// we have a cutoff condition - add the button to show all
310316
const numMissing = tiles.length - visibleTiles.length;
311317
let showMoreText = (
312-
<span className='mx_RoomSublist2_showMoreButtonText'>
318+
<span className='mx_RoomSublist2_showNButtonText'>
313319
{_t("Show %(count)s more", {count: numMissing})}
314320
</span>
315321
);
316322
if (this.props.isMinimized) showMoreText = null;
317-
showMoreButton = (
318-
<div onClick={this.onShowAllClick} className='mx_RoomSublist2_showMoreButton'>
319-
<span className='mx_RoomSublist2_showMoreButtonChevron'>
323+
showNButton = (
324+
<div onClick={this.onShowAllClick} className='mx_RoomSublist2_showNButton'>
325+
<span className='mx_RoomSublist2_showMoreButtonChevron mx_RoomSublist2_showNButtonChevron'>
320326
{/* set by CSS masking */}
321327
</span>
322328
{showMoreText}
323329
</div>
324330
);
331+
} else if (tiles.length <= nVisible) {
332+
// we have all tiles visible - add a button to show less
333+
let showLessText = (
334+
<span className='mx_RoomSublist2_showNButtonText'>
335+
{_t("Show less")}
336+
</span>
337+
);
338+
if (this.props.isMinimized) showLessText = null;
339+
showNButton = (
340+
<div onClick={this.onShowLessClick} className='mx_RoomSublist2_showNButton'>
341+
<span className='mx_RoomSublist2_showLessButtonChevron mx_RoomSublist2_showNButtonChevron'>
342+
{/* set by CSS masking */}
343+
</span>
344+
{showLessText}
345+
</div>
346+
);
325347
}
326348

327349
// Figure out if we need a handle
@@ -345,7 +367,7 @@ export default class RoomSublist2 extends React.Component<IProps, IState> {
345367

346368
// The padding is variable though, so figure out what we need padding for.
347369
let padding = 0;
348-
if (showMoreButton) padding += showMoreHeight;
370+
if (showNButton) padding += showMoreHeight;
349371
if (handles.length > 0) padding += resizeHandleHeight;
350372

351373
const minTilesPx = layout.calculateTilesToPixelsMin(tiles.length, layout.minVisibleTiles, padding);
@@ -365,7 +387,7 @@ export default class RoomSublist2 extends React.Component<IProps, IState> {
365387
className="mx_RoomSublist2_resizeBox"
366388
>
367389
{visibleTiles}
368-
{showMoreButton}
390+
{showNButton}
369391
</ResizableBox>
370392
)
371393
}

0 commit comments

Comments
 (0)