mirror of
https://github.com/element-hq/element-web
synced 2024-11-24 18:25:49 +03:00
Merge pull request #2321 from matrix-org/bwindels/persistcollapsedandrhssize
Redesign: resizer persistence
This commit is contained in:
commit
7936e1a0b7
2 changed files with 30 additions and 4 deletions
|
@ -23,6 +23,11 @@ export default class MainSplit extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this._setResizeContainerRef = this._setResizeContainerRef.bind(this);
|
this._setResizeContainerRef = this._setResizeContainerRef.bind(this);
|
||||||
|
this._onResized = this._onResized.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
_onResized(size) {
|
||||||
|
window.localStorage.setItem("mx_rhs_size", size);
|
||||||
}
|
}
|
||||||
|
|
||||||
_createResizer() {
|
_createResizer() {
|
||||||
|
@ -33,7 +38,9 @@ export default class MainSplit extends React.Component {
|
||||||
};
|
};
|
||||||
const resizer = new Resizer(
|
const resizer = new Resizer(
|
||||||
this.resizeContainer,
|
this.resizeContainer,
|
||||||
FixedDistributor);
|
FixedDistributor,
|
||||||
|
{onResized: this._onResized},
|
||||||
|
);
|
||||||
resizer.setClassNames(classNames);
|
resizer.setClassNames(classNames);
|
||||||
const rhsSize = window.localStorage.getItem("mx_rhs_size");
|
const rhsSize = window.localStorage.getItem("mx_rhs_size");
|
||||||
if (rhsSize !== null) {
|
if (rhsSize !== null) {
|
||||||
|
|
|
@ -72,8 +72,9 @@ module.exports = React.createClass({
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
|
|
||||||
const sizesJson = window.localStorage.getItem("mx_roomlist_sizes");
|
const sizesJson = window.localStorage.getItem("mx_roomlist_sizes");
|
||||||
|
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) : {};
|
||||||
return {
|
return {
|
||||||
isLoadingLeftRooms: false,
|
isLoadingLeftRooms: false,
|
||||||
totalRoomCount: null,
|
totalRoomCount: null,
|
||||||
|
@ -474,6 +475,11 @@ module.exports = React.createClass({
|
||||||
(filter[0] === '#' && room.getAliases().some((alias) => alias.toLowerCase().startsWith(lcFilter))));
|
(filter[0] === '#' && room.getAliases().some((alias) => alias.toLowerCase().startsWith(lcFilter))));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_persistCollapsedState: function(key, collapsed) {
|
||||||
|
this.collapsedState[key] = collapsed;
|
||||||
|
window.localStorage.setItem("mx_roomlist_collapsed", JSON.stringify(this.collapsedState));
|
||||||
|
},
|
||||||
|
|
||||||
_mapSubListProps: function(subListsProps) {
|
_mapSubListProps: function(subListsProps) {
|
||||||
const defaultProps = {
|
const defaultProps = {
|
||||||
collapsed: this.props.collapsed,
|
collapsed: this.props.collapsed,
|
||||||
|
@ -493,10 +499,23 @@ 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 {key, label, ... otherProps} = props;
|
const {key, label, onHeaderClick, ... otherProps} = props;
|
||||||
const chosenKey = key || label;
|
const chosenKey = key || label;
|
||||||
|
const onSubListHeaderClick = (collapsed) => {
|
||||||
|
this._persistCollapsedState(chosenKey, collapsed);
|
||||||
|
if (onHeaderClick) {
|
||||||
|
onHeaderClick(collapsed);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const startAsHidden = props.startAsHidden || this.collapsedState[chosenKey];
|
||||||
|
|
||||||
|
let subList = (<RoomSubList
|
||||||
|
startAsHidden={startAsHidden}
|
||||||
|
onHeaderClick={onSubListHeaderClick}
|
||||||
|
key={chosenKey}
|
||||||
|
label={label}
|
||||||
|
{...otherProps} />);
|
||||||
|
|
||||||
let subList = <RoomSubList key={chosenKey} label={label} {...otherProps} />;
|
|
||||||
if (!isLast) {
|
if (!isLast) {
|
||||||
return components.concat(
|
return components.concat(
|
||||||
subList,
|
subList,
|
||||||
|
|
Loading…
Reference in a new issue