Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redesign: resizer persistence #2321

Merged
merged 2 commits into from Dec 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/components/structures/MainSplit.js
Expand Up @@ -23,6 +23,11 @@ export default class MainSplit extends React.Component {
constructor(props) {
super(props);
this._setResizeContainerRef = this._setResizeContainerRef.bind(this);
this._onResized = this._onResized.bind(this);
}

_onResized(size) {
window.localStorage.setItem("mx_rhs_size", size);
}

_createResizer() {
Expand All @@ -33,7 +38,9 @@ export default class MainSplit extends React.Component {
};
const resizer = new Resizer(
this.resizeContainer,
FixedDistributor);
FixedDistributor,
{onResized: this._onResized},
);
resizer.setClassNames(classNames);
const rhsSize = window.localStorage.getItem("mx_rhs_size");
if (rhsSize !== null) {
Expand Down
25 changes: 22 additions & 3 deletions src/components/views/rooms/RoomList.js
Expand Up @@ -72,8 +72,9 @@ module.exports = React.createClass({
getInitialState: function() {

const sizesJson = window.localStorage.getItem("mx_roomlist_sizes");
const collapsedJson = window.localStorage.getItem("mx_roomlist_collapsed");
this.subListSizes = sizesJson ? JSON.parse(sizesJson) : {};

this.collapsedState = collapsedJson ? JSON.parse(collapsedJson) : {};
return {
isLoadingLeftRooms: false,
totalRoomCount: null,
Expand Down Expand Up @@ -474,6 +475,11 @@ module.exports = React.createClass({
(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) {
const defaultProps = {
collapsed: this.props.collapsed,
Expand All @@ -493,10 +499,23 @@ module.exports = React.createClass({
return subListsProps.reduce((components, props, i) => {
props = Object.assign({}, defaultProps, props);
const isLast = i === subListsProps.length - 1;
const {key, label, ... otherProps} = props;
const {key, label, onHeaderClick, ... otherProps} = props;
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) {
return components.concat(
subList,
Expand Down