Add onHeaderClick and alwaysShowHeader props to RoomSubList for archived room clicking

This commit is contained in:
Kegan Dougal 2015-12-18 11:56:22 +00:00
parent 5f3a1cb6e1
commit 869c08a790

View File

@ -64,7 +64,9 @@ var RoomSubList = React.createClass({
bottommost: React.PropTypes.bool, bottommost: React.PropTypes.bool,
selectedRoom: React.PropTypes.string.isRequired, selectedRoom: React.PropTypes.string.isRequired,
activityMap: React.PropTypes.object.isRequired, activityMap: React.PropTypes.object.isRequired,
collapsed: React.PropTypes.bool.isRequired collapsed: React.PropTypes.bool.isRequired,
onHeaderClick: React.PropTypes.func,
alwaysShowHeader: React.PropTypes.bool
}, },
getInitialState: function() { getInitialState: function() {
@ -74,6 +76,12 @@ var RoomSubList = React.createClass({
}; };
}, },
getDefaultProps: function() {
return {
onHeaderClick: function() {} // NOP
};
},
componentWillMount: function() { componentWillMount: function() {
this.sortList(this.props.list, this.props.order); this.sortList(this.props.list, this.props.order);
}, },
@ -85,7 +93,9 @@ var RoomSubList = React.createClass({
}, },
onClick: function(ev) { onClick: function(ev) {
this.setState({ hidden : !this.state.hidden }); var isHidden = !this.state.hidden;
this.setState({ hidden : isHidden });
this.props.onHeaderClick(isHidden);
}, },
tsOfNewestEvent: function(room) { tsOfNewestEvent: function(room) {
@ -244,6 +254,17 @@ var RoomSubList = React.createClass({
}); });
}, },
_getHeaderJsx: function() {
return (
<h2 onClick={ this.onClick } className="mx_RoomSubList_label">
{ this.props.collapsed ? '' : this.props.label }
<img className="mx_RoomSubList_chevron"
src={ this.state.hidden ? "img/list-open.svg" : "img/list-close.svg" }
width="10" height="10" />
</h2>
);
},
render: function() { render: function() {
var connectDropTarget = this.props.connectDropTarget; var connectDropTarget = this.props.connectDropTarget;
var RoomDropTarget = sdk.getComponent('rooms.RoomDropTarget'); var RoomDropTarget = sdk.getComponent('rooms.RoomDropTarget');
@ -275,9 +296,7 @@ var RoomSubList = React.createClass({
return connectDropTarget( return connectDropTarget(
<div> <div>
<h2 onClick={ this.onClick } className="mx_RoomSubList_label">{ this.props.collapsed ? '' : this.props.label } { this._getHeaderJsx() }
<img className="mx_RoomSubList_chevron" src={ this.state.hidden ? "img/list-open.svg" : "img/list-close.svg" } width="10" height="10"/>
</h2>
{ subList } { subList }
</div> </div>
); );
@ -285,6 +304,7 @@ var RoomSubList = React.createClass({
else { else {
return ( return (
<div className="mx_RoomSubList"> <div className="mx_RoomSubList">
{ this.props.alwaysShowHeader ? this._getHeaderJsx() : undefined }
</div> </div>
); );
} }