Skip to content

Commit 8f20fcf

Browse files
authored
Merge pull request element-hq#3654 from vector-im/matthew/quick-search
Optimise RoomList and implement quick-search functionality on it.
2 parents 751f715 + c1d3066 commit 8f20fcf

6 files changed

Lines changed: 311 additions & 86 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
"favico.js": "^0.3.10",
5959
"filesize": "^3.1.2",
6060
"flux": "~2.0.3",
61-
"gemini-scrollbar": "matrix-org/gemini-scrollbar#b302279",
6261
"gfm.css": "^1.1.1",
6362
"highlight.js": "^9.0.0",
6463
"linkifyjs": "^2.1.3",
@@ -71,7 +70,7 @@
7170
"react-dnd": "^2.1.4",
7271
"react-dnd-html5-backend": "^2.1.2",
7372
"react-dom": "^15.4.0",
74-
"react-gemini-scrollbar": "matrix-org/react-gemini-scrollbar#5e97aef",
73+
"react-gemini-scrollbar": "matrix-org/react-gemini-scrollbar#39d858c",
7574
"sanitize-html": "^1.11.1",
7675
"ua-parser-js": "^0.7.10",
7776
"url": "^0.11.0"

‎src/component-index.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ import structures$RoomDirectory from './components/structures/RoomDirectory';
4040
structures$RoomDirectory && (module.exports.components['structures.RoomDirectory'] = structures$RoomDirectory);
4141
import structures$RoomSubList from './components/structures/RoomSubList';
4242
structures$RoomSubList && (module.exports.components['structures.RoomSubList'] = structures$RoomSubList);
43+
import structures$RoomSubListHeader from './components/structures/RoomSubListHeader';
44+
structures$RoomSubListHeader && (module.exports.components['structures.RoomSubListHeader'] = structures$RoomSubListHeader);
4345
import structures$SearchBox from './components/structures/SearchBox';
4446
structures$SearchBox && (module.exports.components['structures.SearchBox'] = structures$SearchBox);
4547
import structures$ViewSource from './components/structures/ViewSource';

‎src/components/structures/LeftPanel.js‎

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ limitations under the License.
1919
var React = require('react');
2020
var DragDropContext = require('react-dnd').DragDropContext;
2121
var HTML5Backend = require('react-dnd-html5-backend');
22+
var KeyCode = require('matrix-react-sdk/lib/KeyCode');
2223
var sdk = require('matrix-react-sdk')
2324
var dis = require('matrix-react-sdk/lib/dispatcher');
2425

26+
2527
var VectorConferenceHandler = require('../../VectorConferenceHandler');
2628
var CallHandler = require("matrix-react-sdk/lib/CallHandler");
2729

@@ -40,6 +42,10 @@ var LeftPanel = React.createClass({
4042
};
4143
},
4244

45+
componentWillMount: function() {
46+
this.focusedElement = null;
47+
},
48+
4349
componentDidMount: function() {
4450
this.dispatcherRef = dis.register(this.onAction);
4551
},
@@ -62,6 +68,91 @@ var LeftPanel = React.createClass({
6268
}
6369
},
6470

71+
_onFocus: function(ev) {
72+
this.focusedElement = ev.target;
73+
},
74+
75+
_onBlur: function(ev) {
76+
this.focusedElement = null;
77+
},
78+
79+
_onKeyDown: function(ev) {
80+
if (!this.focusedElement) return;
81+
let handled = false;
82+
83+
switch (ev.keyCode) {
84+
case KeyCode.UP:
85+
this._onMoveFocus(true);
86+
handled = true;
87+
break;
88+
case KeyCode.DOWN:
89+
this._onMoveFocus(false);
90+
handled = true;
91+
break;
92+
}
93+
94+
if (handled) {
95+
ev.stopPropagation();
96+
ev.preventDefault();
97+
}
98+
},
99+
100+
_onMoveFocus: function(up) {
101+
var element = this.focusedElement;
102+
103+
// unclear why this isn't needed
104+
// var descending = (up == this.focusDirection) ? this.focusDescending : !this.focusDescending;
105+
// this.focusDirection = up;
106+
107+
var descending = false; // are we currently descending or ascending through the DOM tree?
108+
var classes;
109+
110+
do {
111+
var child = up ? element.lastElementChild : element.firstElementChild;
112+
var sibling = up ? element.previousElementSibling : element.nextElementSibling;
113+
114+
if (descending) {
115+
if (child) {
116+
element = child;
117+
}
118+
else if (sibling) {
119+
element = sibling;
120+
}
121+
else {
122+
descending = false;
123+
element = element.parentElement;
124+
}
125+
}
126+
else {
127+
if (sibling) {
128+
element = sibling;
129+
descending = true;
130+
}
131+
else {
132+
element = element.parentElement;
133+
}
134+
}
135+
136+
if (element) {
137+
classes = element.classList;
138+
if (classes.contains("mx_LeftPanel")) { // we hit the top
139+
element = up ? element.lastElementChild : element.firstElementChild;
140+
descending = true;
141+
}
142+
}
143+
144+
} while(element && !(
145+
classes.contains("mx_RoomTile") ||
146+
classes.contains("mx_SearchBox_search") ||
147+
classes.contains("mx_RoomSubList_ellipsis")));
148+
149+
if (element) {
150+
element.focus();
151+
this.focusedElement = element;
152+
this.focusedDescending = descending;
153+
}
154+
},
155+
65156
_recheckCallElement: function(selectedRoomId) {
66157
// if we aren't viewing a room with an ongoing call, but there is an
67158
// active call, show the call element - we need to do this to make
@@ -120,7 +211,8 @@ var LeftPanel = React.createClass({
120211
}
121212

122213
return (
123-
<aside className={classes} style={{ opacity: this.props.opacity }}>
214+
<aside className={classes} style={{ opacity: this.props.opacity }}
215+
onKeyDown={ this._onKeyDown } onFocus={ this._onFocus } onBlur={ this._onBlur }>
124216
<SearchBox collapsed={ this.props.collapsed } onSearch={ this.onSearch } />
125217
{ collapseButton }
126218
{ callPreview }

0 commit comments

Comments
 (0)