2018-04-11 22:58:04 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2019-10-23 11:12:11 +00:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2018-04-11 22:58:04 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
2019-08-30 09:34:59 +00:00
|
|
|
import createReactClass from 'create-react-class';
|
2018-04-11 22:58:04 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classNames from 'classnames';
|
2019-10-23 11:12:11 +00:00
|
|
|
import { Key } from '../../Keyboard';
|
2019-12-20 01:19:56 +00:00
|
|
|
import * as sdk from '../../index';
|
2018-04-12 23:43:44 +00:00
|
|
|
import dis from '../../dispatcher';
|
2019-12-20 01:19:56 +00:00
|
|
|
import * as VectorConferenceHandler from '../../VectorConferenceHandler';
|
2018-04-12 23:43:44 +00:00
|
|
|
import SettingsStore from '../../settings/SettingsStore';
|
2019-02-24 04:42:04 +00:00
|
|
|
import {_t} from "../../languageHandler";
|
2019-04-04 20:17:15 +00:00
|
|
|
import Analytics from "../../Analytics";
|
2018-04-11 22:58:04 +00:00
|
|
|
|
|
|
|
|
2019-08-30 09:34:59 +00:00
|
|
|
const LeftPanel = createReactClass({
|
2018-04-11 22:58:04 +00:00
|
|
|
displayName: 'LeftPanel',
|
|
|
|
|
|
|
|
// NB. If you add props, don't forget to update
|
|
|
|
// shouldComponentUpdate!
|
|
|
|
propTypes: {
|
|
|
|
collapsed: PropTypes.bool.isRequired,
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
searchFilter: '',
|
2019-04-01 17:49:29 +00:00
|
|
|
breadcrumbs: false,
|
2018-04-11 22:58:04 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
|
|
|
this.focusedElement = null;
|
2019-04-01 17:49:29 +00:00
|
|
|
|
2019-10-03 22:21:32 +00:00
|
|
|
this._breadcrumbsWatcherRef = SettingsStore.watchSetting(
|
2019-06-03 06:15:33 +00:00
|
|
|
"breadcrumbs", null, this._onBreadcrumbsChanged);
|
2019-10-03 22:21:32 +00:00
|
|
|
this._tagPanelWatcherRef = SettingsStore.watchSetting(
|
2019-10-03 21:13:10 +00:00
|
|
|
"TagPanel.enableTagPanel", null, () => this.forceUpdate());
|
2019-04-01 17:49:29 +00:00
|
|
|
|
2019-06-03 06:15:33 +00:00
|
|
|
const useBreadcrumbs = !!SettingsStore.getValue("breadcrumbs");
|
2019-04-04 20:17:15 +00:00
|
|
|
Analytics.setBreadcrumbs(useBreadcrumbs);
|
|
|
|
this.setState({breadcrumbs: useBreadcrumbs});
|
2019-04-01 17:49:29 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
2019-10-03 22:21:32 +00:00
|
|
|
SettingsStore.unwatchSetting(this._breadcrumbsWatcherRef);
|
|
|
|
SettingsStore.unwatchSetting(this._tagPanelWatcherRef);
|
2018-04-11 22:58:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
shouldComponentUpdate: function(nextProps, nextState) {
|
|
|
|
// MatrixChat will update whenever the user switches
|
|
|
|
// rooms, but propagating this change all the way down
|
|
|
|
// the react tree is quite slow, so we cut this off
|
|
|
|
// here. The RoomTiles listen for the room change
|
|
|
|
// events themselves to know when to update.
|
|
|
|
// We just need to update if any of these things change.
|
|
|
|
if (
|
|
|
|
this.props.collapsed !== nextProps.collapsed ||
|
|
|
|
this.props.disabled !== nextProps.disabled
|
|
|
|
) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state.searchFilter !== nextState.searchFilter) {
|
|
|
|
return true;
|
|
|
|
}
|
2019-09-11 11:46:18 +00:00
|
|
|
if (this.state.searchExpanded !== nextState.searchExpanded) {
|
2019-09-10 08:57:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
2018-04-11 22:58:04 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2019-04-05 15:40:21 +00:00
|
|
|
componentDidUpdate(prevProps, prevState) {
|
|
|
|
if (prevState.breadcrumbs !== this.state.breadcrumbs) {
|
|
|
|
Analytics.setBreadcrumbs(this.state.breadcrumbs);
|
|
|
|
}
|
2019-04-04 20:17:15 +00:00
|
|
|
},
|
|
|
|
|
2019-04-01 17:49:29 +00:00
|
|
|
_onBreadcrumbsChanged: function(settingName, roomId, level, valueAtLevel, value) {
|
|
|
|
// Features are only possible at a single level, so we can get away with using valueAtLevel.
|
|
|
|
// The SettingsStore runs on the same tick as the update, so `value` will be wrong.
|
|
|
|
this.setState({breadcrumbs: valueAtLevel});
|
|
|
|
|
|
|
|
// For some reason the setState doesn't trigger a render of the component, so force one.
|
|
|
|
// Probably has to do with the change happening outside of a change detector cycle.
|
|
|
|
this.forceUpdate();
|
|
|
|
},
|
|
|
|
|
2018-04-11 22:58:04 +00:00
|
|
|
_onFocus: function(ev) {
|
|
|
|
this.focusedElement = ev.target;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onBlur: function(ev) {
|
|
|
|
this.focusedElement = null;
|
|
|
|
},
|
|
|
|
|
2019-10-23 17:31:00 +00:00
|
|
|
_onFilterKeyDown: function(ev) {
|
|
|
|
if (!this.focusedElement) return;
|
|
|
|
|
|
|
|
switch (ev.key) {
|
2019-10-23 17:45:04 +00:00
|
|
|
// On enter of rooms filter select and activate first room if such one exists
|
2019-10-23 17:31:00 +00:00
|
|
|
case Key.ENTER: {
|
|
|
|
const firstRoom = ev.target.closest(".mx_LeftPanel").querySelector(".mx_RoomTile");
|
|
|
|
if (firstRoom) {
|
|
|
|
firstRoom.click();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-04-11 22:58:04 +00:00
|
|
|
_onKeyDown: function(ev) {
|
|
|
|
if (!this.focusedElement) return;
|
|
|
|
|
2019-10-23 11:12:11 +00:00
|
|
|
switch (ev.key) {
|
|
|
|
case Key.ARROW_UP:
|
|
|
|
this._onMoveFocus(ev, true, true);
|
2018-04-11 22:58:04 +00:00
|
|
|
break;
|
2019-10-23 11:12:11 +00:00
|
|
|
case Key.ARROW_DOWN:
|
|
|
|
this._onMoveFocus(ev, false, true);
|
2018-04-11 22:58:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-10-23 11:12:11 +00:00
|
|
|
_onMoveFocus: function(ev, up, trap) {
|
2018-06-16 07:42:40 +00:00
|
|
|
let element = this.focusedElement;
|
2018-04-11 22:58:04 +00:00
|
|
|
|
|
|
|
// unclear why this isn't needed
|
|
|
|
// var descending = (up == this.focusDirection) ? this.focusDescending : !this.focusDescending;
|
|
|
|
// this.focusDirection = up;
|
|
|
|
|
2018-06-16 07:42:40 +00:00
|
|
|
let descending = false; // are we currently descending or ascending through the DOM tree?
|
|
|
|
let classes;
|
2018-04-11 22:58:04 +00:00
|
|
|
|
|
|
|
do {
|
2018-06-16 07:42:40 +00:00
|
|
|
const child = up ? element.lastElementChild : element.firstElementChild;
|
|
|
|
const sibling = up ? element.previousElementSibling : element.nextElementSibling;
|
2018-04-11 22:58:04 +00:00
|
|
|
|
|
|
|
if (descending) {
|
|
|
|
if (child) {
|
|
|
|
element = child;
|
2018-06-16 07:42:40 +00:00
|
|
|
} else if (sibling) {
|
2018-04-11 22:58:04 +00:00
|
|
|
element = sibling;
|
2018-06-16 07:42:40 +00:00
|
|
|
} else {
|
2018-04-11 22:58:04 +00:00
|
|
|
descending = false;
|
|
|
|
element = element.parentElement;
|
|
|
|
}
|
2018-06-16 07:42:40 +00:00
|
|
|
} else {
|
2018-04-11 22:58:04 +00:00
|
|
|
if (sibling) {
|
|
|
|
element = sibling;
|
|
|
|
descending = true;
|
2018-06-16 07:42:40 +00:00
|
|
|
} else {
|
2018-04-11 22:58:04 +00:00
|
|
|
element = element.parentElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (element) {
|
|
|
|
classes = element.classList;
|
|
|
|
}
|
2018-06-16 07:42:40 +00:00
|
|
|
} while (element && !(
|
2018-04-11 22:58:04 +00:00
|
|
|
classes.contains("mx_RoomTile") ||
|
2019-10-17 14:53:39 +00:00
|
|
|
classes.contains("mx_RoomSubList_label") ||
|
2019-10-23 11:12:11 +00:00
|
|
|
classes.contains("mx_LeftPanel_filterRooms")));
|
2018-04-11 22:58:04 +00:00
|
|
|
|
|
|
|
if (element) {
|
2019-10-23 11:12:11 +00:00
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
2018-04-11 22:58:04 +00:00
|
|
|
element.focus();
|
|
|
|
this.focusedElement = element;
|
2019-10-23 11:12:11 +00:00
|
|
|
} else if (trap) {
|
|
|
|
// if navigation is via up/down arrow-keys, trap in the widget so it doesn't send to composer
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
2018-04-11 22:58:04 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onSearch: function(term) {
|
|
|
|
this.setState({ searchFilter: term });
|
|
|
|
},
|
|
|
|
|
2018-11-05 08:35:44 +00:00
|
|
|
onSearchCleared: function(source) {
|
|
|
|
if (source === "keyboard") {
|
|
|
|
dis.dispatch({action: 'focus_composer'});
|
|
|
|
}
|
2019-09-11 11:46:18 +00:00
|
|
|
this.setState({searchExpanded: false});
|
2018-11-05 08:35:44 +00:00
|
|
|
},
|
|
|
|
|
2018-04-11 22:58:04 +00:00
|
|
|
collectRoomList: function(ref) {
|
|
|
|
this._roomList = ref;
|
|
|
|
},
|
|
|
|
|
2019-09-10 08:57:25 +00:00
|
|
|
_onSearchFocus: function() {
|
2019-09-11 11:46:18 +00:00
|
|
|
this.setState({searchExpanded: true});
|
2019-09-10 08:57:25 +00:00
|
|
|
},
|
|
|
|
|
2019-09-11 11:46:18 +00:00
|
|
|
_onSearchBlur: function(event) {
|
|
|
|
if (event.target.value.length === 0) {
|
|
|
|
this.setState({searchExpanded: false});
|
|
|
|
}
|
2019-09-10 08:57:25 +00:00
|
|
|
},
|
|
|
|
|
2018-04-11 22:58:04 +00:00
|
|
|
render: function() {
|
|
|
|
const RoomList = sdk.getComponent('rooms.RoomList');
|
2019-02-12 10:04:25 +00:00
|
|
|
const RoomBreadcrumbs = sdk.getComponent('rooms.RoomBreadcrumbs');
|
2018-04-11 22:58:04 +00:00
|
|
|
const TagPanel = sdk.getComponent('structures.TagPanel');
|
2019-02-05 17:39:02 +00:00
|
|
|
const CustomRoomTagPanel = sdk.getComponent('structures.CustomRoomTagPanel');
|
2018-10-23 11:29:44 +00:00
|
|
|
const TopLeftMenuButton = sdk.getComponent('structures.TopLeftMenuButton');
|
2018-11-02 14:27:17 +00:00
|
|
|
const SearchBox = sdk.getComponent('structures.SearchBox');
|
2018-04-11 22:58:04 +00:00
|
|
|
const CallPreview = sdk.getComponent('voip.CallPreview');
|
2019-09-10 08:53:55 +00:00
|
|
|
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
|
2018-10-26 13:57:57 +00:00
|
|
|
|
2019-01-25 03:57:40 +00:00
|
|
|
const tagPanelEnabled = SettingsStore.getValue("TagPanel.enableTagPanel");
|
2019-02-05 17:36:33 +00:00
|
|
|
let tagPanelContainer;
|
2019-02-07 18:04:30 +00:00
|
|
|
|
|
|
|
const isCustomTagsEnabled = SettingsStore.isFeatureEnabled("feature_custom_tags");
|
|
|
|
|
2019-02-05 17:36:33 +00:00
|
|
|
if (tagPanelEnabled) {
|
|
|
|
tagPanelContainer = (<div className="mx_LeftPanel_tagPanelContainer">
|
|
|
|
<TagPanel />
|
2019-02-07 18:04:30 +00:00
|
|
|
{ isCustomTagsEnabled ? <CustomRoomTagPanel /> : undefined }
|
2019-02-05 17:36:33 +00:00
|
|
|
</div>);
|
|
|
|
}
|
2018-04-11 22:58:04 +00:00
|
|
|
|
|
|
|
const containerClasses = classNames(
|
|
|
|
"mx_LeftPanel_container", "mx_fadable",
|
|
|
|
{
|
2018-10-16 15:38:34 +00:00
|
|
|
"collapsed": this.props.collapsed,
|
2018-04-11 22:58:04 +00:00
|
|
|
"mx_LeftPanel_container_hasTagPanel": tagPanelEnabled,
|
|
|
|
"mx_fadable_faded": this.props.disabled,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2019-09-10 08:53:55 +00:00
|
|
|
let exploreButton;
|
|
|
|
if (!this.props.collapsed) {
|
|
|
|
exploreButton = (
|
2019-09-11 11:46:18 +00:00
|
|
|
<div className={classNames("mx_LeftPanel_explore", {"mx_LeftPanel_explore_hidden": this.state.searchExpanded})}>
|
2019-09-10 08:53:55 +00:00
|
|
|
<AccessibleButton onClick={() => dis.dispatch({action: 'view_room_directory'})}>{_t("Explore")}</AccessibleButton>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-04 18:51:41 +00:00
|
|
|
const searchBox = (<SearchBox
|
2019-10-23 11:12:11 +00:00
|
|
|
className="mx_LeftPanel_filterRooms"
|
2019-03-06 14:53:52 +00:00
|
|
|
enableRoomSearchFocus={true}
|
2019-09-10 08:58:11 +00:00
|
|
|
blurredPlaceholder={ _t('Filter') }
|
|
|
|
placeholder={ _t('Filter rooms…') }
|
2019-10-23 17:31:00 +00:00
|
|
|
onKeyDown={this._onFilterKeyDown}
|
2019-02-04 18:51:41 +00:00
|
|
|
onSearch={ this.onSearch }
|
|
|
|
onCleared={ this.onSearchCleared }
|
2019-09-10 08:57:25 +00:00
|
|
|
onFocus={this._onSearchFocus}
|
|
|
|
onBlur={this._onSearchBlur}
|
2019-02-04 18:51:41 +00:00
|
|
|
collapsed={this.props.collapsed} />);
|
2018-11-02 14:29:18 +00:00
|
|
|
|
2019-02-12 10:41:24 +00:00
|
|
|
let breadcrumbs;
|
2019-04-01 17:49:29 +00:00
|
|
|
if (this.state.breadcrumbs) {
|
2019-02-12 10:41:24 +00:00
|
|
|
breadcrumbs = (<RoomBreadcrumbs collapsed={this.props.collapsed} />);
|
|
|
|
}
|
|
|
|
|
2018-04-11 22:58:04 +00:00
|
|
|
return (
|
|
|
|
<div className={containerClasses}>
|
2019-02-05 17:36:33 +00:00
|
|
|
{ tagPanelContainer }
|
2019-10-23 11:12:11 +00:00
|
|
|
<aside className="mx_LeftPanel dark-panel">
|
|
|
|
<TopLeftMenuButton collapsed={this.props.collapsed} />
|
2019-02-12 10:41:24 +00:00
|
|
|
{ breadcrumbs }
|
2019-10-23 12:05:02 +00:00
|
|
|
<CallPreview ConferenceHandler={VectorConferenceHandler} />
|
2019-10-23 17:31:00 +00:00
|
|
|
<div className="mx_LeftPanel_exploreAndFilterRow" onKeyDown={this._onKeyDown} onFocus={this._onFocus} onBlur={this._onBlur}>
|
|
|
|
{ exploreButton }
|
|
|
|
{ searchBox }
|
2019-09-10 08:53:55 +00:00
|
|
|
</div>
|
2019-10-23 17:31:00 +00:00
|
|
|
<RoomList
|
|
|
|
onKeyDown={this._onKeyDown}
|
|
|
|
onFocus={this._onFocus}
|
|
|
|
onBlur={this._onBlur}
|
|
|
|
ref={this.collectRoomList}
|
|
|
|
resizeNotifier={this.props.resizeNotifier}
|
|
|
|
collapsed={this.props.collapsed}
|
|
|
|
searchFilter={this.state.searchFilter}
|
|
|
|
ConferenceHandler={VectorConferenceHandler} />
|
2018-04-11 22:58:04 +00:00
|
|
|
</aside>
|
|
|
|
</div>
|
|
|
|
);
|
2018-10-27 03:50:35 +00:00
|
|
|
},
|
2018-04-11 22:58:04 +00:00
|
|
|
});
|
|
|
|
|
2019-12-20 00:45:24 +00:00
|
|
|
export default LeftPanel;
|