integrate layout/distributor with RoomList

This commit is contained in:
Bruno Windels 2019-01-24 15:43:49 +01:00
parent 1092244bbf
commit 067a861f80
2 changed files with 43 additions and 15 deletions

View file

@ -313,6 +313,12 @@ const RoomSubList = React.createClass({
} }
}, },
setHeight: function(height) {
if (this.refs.subList) {
this.refs.subList.style.height = `${height}px`;
}
},
render: function() { render: function() {
const len = this.props.list.length + this.props.extraTiles.length; const len = this.props.list.length + this.props.extraTiles.length;
if (len) { if (len) {
@ -322,13 +328,13 @@ const RoomSubList = React.createClass({
"mx_RoomSubList_nonEmpty": len && !this.state.hidden, "mx_RoomSubList_nonEmpty": len && !this.state.hidden,
}); });
if (this.state.hidden) { if (this.state.hidden) {
return <div className={subListClasses}> return <div ref="subList" className={subListClasses}>
{this._getHeaderJsx()} {this._getHeaderJsx()}
</div>; </div>;
} else { } else {
const tiles = this.makeRoomTiles(); const tiles = this.makeRoomTiles();
tiles.push(...this.props.extraTiles); tiles.push(...this.props.extraTiles);
return <div className={subListClasses}> return <div ref="subList" className={subListClasses}>
{this._getHeaderJsx()} {this._getHeaderJsx()}
<IndicatorScrollbar ref="scroller" className="mx_RoomSubList_scroll"> <IndicatorScrollbar ref="scroller" className="mx_RoomSubList_scroll">
{ tiles } { tiles }
@ -343,7 +349,7 @@ const RoomSubList = React.createClass({
} }
return ( return (
<div className="mx_RoomSubList"> <div ref="subList" className="mx_RoomSubList">
{ this._getHeaderJsx() } { this._getHeaderJsx() }
{ content } { content }
</div> </div>

View file

@ -36,7 +36,8 @@ import GroupStore from '../../../stores/GroupStore';
import RoomSubList from '../../structures/RoomSubList'; import RoomSubList from '../../structures/RoomSubList';
import ResizeHandle from '../elements/ResizeHandle'; import ResizeHandle from '../elements/ResizeHandle';
import {Resizer, RoomSubListDistributor} from '../../../resizer' import {Resizer} from '../../../resizer'
import {Layout, Distributor} from '../../../resizer/distributors/roomsublist2';
const HIDE_CONFERENCE_CHANS = true; const HIDE_CONFERENCE_CHANS = true;
const STANDARD_TAGS_REGEX = /^(m\.(favourite|lowpriority|server_notice)|im\.vector\.fake\.(invite|recent|direct|archived))$/; const STANDARD_TAGS_REGEX = /^(m\.(favourite|lowpriority|server_notice)|im\.vector\.fake\.(invite|recent|direct|archived))$/;
@ -79,6 +80,20 @@ module.exports = React.createClass({
const collapsedJson = window.localStorage.getItem("mx_roomlist_collapsed"); const collapsedJson = window.localStorage.getItem("mx_roomlist_collapsed");
this.subListSizes = sizesJson ? JSON.parse(sizesJson) : {}; this.subListSizes = sizesJson ? JSON.parse(sizesJson) : {};
this.collapsedState = collapsedJson ? JSON.parse(collapsedJson) : {}; this.collapsedState = collapsedJson ? JSON.parse(collapsedJson) : {};
this._layoutSections = [];
this._layout = new Layout((key, size) => {
const subList = this._subListRefs[key];
if (subList) {
subList.setHeight(size);
}
this.subListSizes[key] = size;
window.localStorage.setItem("mx_roomlist_sizes",
JSON.stringify(this.subListSizes));
// update overflow indicators
this._checkSubListsOverflow();
}, this.subListSizes, this.collapsedState);
return { return {
isLoadingLeftRooms: false, isLoadingLeftRooms: false,
totalRoomCount: null, totalRoomCount: null,
@ -166,19 +181,18 @@ module.exports = React.createClass({
componentDidMount: function() { componentDidMount: function() {
this.dispatcherRef = dis.register(this.onAction); this.dispatcherRef = dis.register(this.onAction);
const cfg = { const cfg = {
onResized: this._onSubListResize, layout: this._layout,
}; };
this.resizer = new Resizer(this.resizeContainer, RoomSubListDistributor, cfg); this.resizer = new Resizer(this.resizeContainer, Distributor, cfg);
this.resizer.setClassNames({ this.resizer.setClassNames({
handle: "mx_ResizeHandle", handle: "mx_ResizeHandle",
vertical: "mx_ResizeHandle_vertical", vertical: "mx_ResizeHandle_vertical",
reverse: "mx_ResizeHandle_reverse" reverse: "mx_ResizeHandle_reverse"
}); });
this._layout.update(
// load stored sizes this._layoutSections,
Object.keys(this.subListSizes).forEach((key) => { this.resizeContainer && this.resizeContainer.clientHeight,
this._restoreSubListSize(key); );
});
this._checkSubListsOverflow(); this._checkSubListsOverflow();
this.resizer.attach(); this.resizer.attach();
@ -194,6 +208,11 @@ module.exports = React.createClass({
}); });
this._checkSubListsOverflow(); this._checkSubListsOverflow();
} }
this._layout.update(
this._layoutSections,
this.resizeContainer && this.resizeContainer.clientHeight,
);
// TODO: call layout.setAvailableHeight, window height was changed when bannerShown prop was changed
}, },
onAction: function(payload) { onAction: function(payload) {
@ -551,9 +570,7 @@ module.exports = React.createClass({
this.collapsedState[key] = collapsed; this.collapsedState[key] = collapsed;
window.localStorage.setItem("mx_roomlist_collapsed", JSON.stringify(this.collapsedState)); window.localStorage.setItem("mx_roomlist_collapsed", JSON.stringify(this.collapsedState));
// load the persisted size configuration of the expanded sub list // load the persisted size configuration of the expanded sub list
if (!collapsed) { this._layout.setCollapsed(key, collapsed);
this._restoreSubListSize(key);
}
// check overflow, as sub lists sizes have changed // check overflow, as sub lists sizes have changed
// important this happens after calling resize above // important this happens after calling resize above
this._checkSubListsOverflow(); this._checkSubListsOverflow();
@ -581,6 +598,7 @@ module.exports = React.createClass({
}, },
_mapSubListProps: function(subListsProps) { _mapSubListProps: function(subListsProps) {
this._layoutSections = [];
const defaultProps = { const defaultProps = {
collapsed: this.props.collapsed, collapsed: this.props.collapsed,
isFiltered: !!this.props.searchFilter, isFiltered: !!this.props.searchFilter,
@ -599,6 +617,7 @@ module.exports = React.createClass({
return subListsProps.reduce((components, props, i) => { return subListsProps.reduce((components, props, i) => {
props = Object.assign({}, defaultProps, props); props = Object.assign({}, defaultProps, props);
const isLast = i === subListsProps.length - 1; const isLast = i === subListsProps.length - 1;
const len = props.list.length + (props.extraTiles ? props.extraTiles.length : 0);
const {key, label, onHeaderClick, ... otherProps} = props; const {key, label, onHeaderClick, ... otherProps} = props;
const chosenKey = key || label; const chosenKey = key || label;
const onSubListHeaderClick = (collapsed) => { const onSubListHeaderClick = (collapsed) => {
@ -608,7 +627,10 @@ module.exports = React.createClass({
} }
}; };
const startAsHidden = props.startAsHidden || this.collapsedState[chosenKey]; const startAsHidden = props.startAsHidden || this.collapsedState[chosenKey];
this._layoutSections.push({
id: chosenKey,
count: len,
});
let subList = (<RoomSubList let subList = (<RoomSubList
ref={this._subListRef.bind(this, chosenKey)} ref={this._subListRef.bind(this, chosenKey)}
startAsHidden={startAsHidden} startAsHidden={startAsHidden}