Skip to content

Commit 26d12be

Browse files
committed
wire up searchbox filtering, and some minor overall tweaks
1 parent 90ae024 commit 26d12be

5 files changed

Lines changed: 92 additions & 24 deletions

File tree

‎src/components/structures/LeftPanel.js‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var LeftPanel = React.createClass({
3131
getInitialState: function() {
3232
return {
3333
showCallElement: null,
34+
searchFilter: '',
3435
};
3536
},
3637

@@ -84,6 +85,10 @@ var LeftPanel = React.createClass({
8485
}
8586
},
8687

88+
onSearch: function(term) {
89+
this.setState({ searchFilter: term });
90+
},
91+
8792
render: function() {
8893
var RoomList = sdk.getComponent('rooms.RoomList');
8994
var BottomLeftMenu = sdk.getComponent('structures.BottomLeftMenu');
@@ -111,12 +116,13 @@ var LeftPanel = React.createClass({
111116

112117
return (
113118
<aside className={classes} style={{ opacity: this.props.opacity }}>
114-
<SearchBox collapsed={ this.props.collapsed } />
119+
<SearchBox collapsed={ this.props.collapsed } onSearch={ this.onSearch } />
115120
{ collapseButton }
116121
{ callPreview }
117122
<RoomList
118123
selectedRoom={this.props.selectedRoom}
119124
collapsed={this.props.collapsed}
125+
searchFilter={this.state.searchFilter}
120126
ConferenceHandler={VectorConferenceHandler} />
121127
<BottomLeftMenu collapsed={this.props.collapsed}/>
122128
</aside>

‎src/components/structures/RoomSubList.js‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,12 @@ var RoomSubList = React.createClass({
6565
selectedRoom: React.PropTypes.string.isRequired,
6666
startAsHidden: React.PropTypes.bool,
6767
showSpinner: React.PropTypes.bool, // true to show a spinner if 0 elements when expanded
68-
69-
// TODO: Fix the name of this. This is too easily confused with the
70-
// "hidden" state which is the expanded (or not) view of the list of rooms.
71-
// What this prop *really* does is control whether the room name is displayed
72-
// so it should be named as such.
73-
collapsed: React.PropTypes.bool.isRequired,
68+
collapsed: React.PropTypes.bool.isRequired, // is LeftPanel collapsed?
7469
onHeaderClick: React.PropTypes.func,
7570
alwaysShowHeader: React.PropTypes.bool,
7671
incomingCall: React.PropTypes.object,
77-
onShowMoreRooms: React.PropTypes.func
72+
onShowMoreRooms: React.PropTypes.func,
73+
searchFilter: React.PropTypes.string,
7874
},
7975

8076
getInitialState: function() {
@@ -93,13 +89,20 @@ var RoomSubList = React.createClass({
9389
},
9490

9591
componentWillMount: function() {
96-
this.sortList(this.props.list, this.props.order);
92+
this.sortList(this.applySearchFilter(this.props.list, this.props.searchFilter), this.props.order);
9793
},
9894

9995
componentWillReceiveProps: function(newProps) {
10096
// order the room list appropriately before we re-render
10197
//if (debug) console.log("received new props, list = " + newProps.list);
102-
this.sortList(newProps.list, newProps.order);
98+
this.sortList(this.applySearchFilter(newProps.list, newProps.searchFilter), newProps.order);
99+
},
100+
101+
applySearchFilter: function(list, filter) {
102+
if (filter === "") return list;
103+
return list.filter((room) => {
104+
return room.name && room.name.toLowerCase().indexOf(filter.toLowerCase()) >= 0
105+
});
103106
},
104107

105108
onClick: function(ev) {

‎src/components/structures/SearchBox.js‎

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,78 @@ limitations under the License.
1919
var React = require('react');
2020
var sdk = require('matrix-react-sdk')
2121
var dis = require('matrix-react-sdk/lib/dispatcher');
22+
var rate_limited_func = require('matrix-react-sdk/lib/ratelimitedfunc');
2223

2324
module.exports = React.createClass({
2425
displayName: 'SearchBox',
2526

27+
propTypes: {
28+
collapsed: React.PropTypes.bool,
29+
onSearch: React.PropTypes.func,
30+
},
31+
32+
onChange: new rate_limited_func(
33+
function() {
34+
if (this.refs.search) {
35+
this.props.onSearch(this.refs.search.value);
36+
}
37+
},
38+
100
39+
),
40+
41+
onToggleCollapse: function(show) {
42+
if (show) {
43+
dis.dispatch({
44+
action: 'show_left_panel',
45+
});
46+
}
47+
else {
48+
dis.dispatch({
49+
action: 'hide_left_panel',
50+
});
51+
}
52+
},
53+
2654
render: function() {
2755
var TintableSvg = sdk.getComponent('elements.TintableSvg');
2856

2957
var toggleCollapse;
3058
if (this.props.collapsed) {
31-
toggleCollapse = <img className="mx_SearchBox_maximise" src="img/maximise.svg" width="10" height="16" alt="&lt;"/>;
59+
toggleCollapse =
60+
<div className="mx_SearchBox_maximise" onClick={ this.onToggleCollapse.bind(this, true) }>
61+
<TintableSvg src="img/maximise.svg" width="10" height="16" alt="&lt;"/>
62+
</div>
3263
}
3364
else {
34-
toggleCollapse = <img className="mx_SearchBox_minimise" src="img/minimise.svg" width="10" height="16" alt="&lt;"/>;
65+
toggleCollapse =
66+
<div className="mx_SearchBox_minimise" onClick={ this.onToggleCollapse.bind(this, false) }>
67+
<TintableSvg src="img/minimise.svg" width="10" height="16" alt="&lt;"/>
68+
</div>
69+
}
70+
71+
var searchControls;
72+
if (!this.props.collapsed) {
73+
searchControls = [
74+
<TintableSvg
75+
key="button"
76+
className="mx_SearchBox_searchButton"
77+
src="img/search.svg" width="21" height="19"
78+
/>,
79+
<input
80+
key="searchfield"
81+
type="text"
82+
ref="search"
83+
className="mx_SearchBox_search"
84+
onChange={ this.onChange }
85+
placeholder="Search room names"
86+
/>
87+
];
3588
}
3689

90+
var self = this;
3791
return (
3892
<div className="mx_SearchBox">
39-
<TintableSvg
40-
className="mx_SearchBox_searchButton"
41-
src="img/search.svg" width="21" height="19"
42-
/>
43-
<input
44-
type="text"
45-
className="mx_SearchBox_search"
46-
placeholder="Search Vector"
47-
/>
93+
{ searchControls }
4894
{ toggleCollapse }
4995
</div>
5096
);

‎src/skins/vector/css/matrix-react-sdk/structures/RoomStatusBar.css‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ limitations under the License.
1515
*/
1616

1717
.mx_RoomStatusBar {
18-
margin-top: 12px;
18+
margin-top: 15px;
1919
margin-left: 65px;
20-
min-height: 37px;
20+
min-height: 34px;
2121
}
2222

2323
/* position the indicator in the same place horizontally as .mx_EventTile_avatar. */
@@ -33,8 +33,9 @@ limitations under the License.
3333
.mx_RoomStatusBar_placeholderIndicator span {
3434
color: #4a4a4a;
3535
opacity: 0.5;
36-
/*
3736
position: relative;
37+
top: -4px;
38+
/*
3839
animation-duration: 1s;
3940
animation-name: bounce;
4041
animation-direction: alternate;

‎src/skins/vector/css/matrix-react-sdk/structures/SearchBox.css‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,17 @@ limitations under the License.
4545

4646
.mx_SearchBox_minimise,
4747
.mx_SearchBox_maximise {
48+
cursor: pointer;
49+
}
50+
51+
.mx_SearchBox_minimise {
4852
margin-left: 10px;
4953
}
54+
55+
.mx_SearchBox_maximise {
56+
margin-left: 6px;
57+
}
58+
59+
.mx_SearchBox object {
60+
pointer-events: none;
61+
}

0 commit comments

Comments
 (0)