2018-04-12 01:58:04 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
|
|
|
|
|
|
|
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 12:34:59 +03:00
|
|
|
import createReactClass from 'create-react-class';
|
2018-04-12 01:58:04 +03:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
import { MatrixClient } from 'matrix-js-sdk';
|
2018-04-13 02:43:44 +03:00
|
|
|
import { KeyCode } from '../../Keyboard';
|
|
|
|
import sdk from '../../index';
|
|
|
|
import dis from '../../dispatcher';
|
2018-04-12 01:58:04 +03:00
|
|
|
import VectorConferenceHandler from '../../VectorConferenceHandler';
|
2019-02-05 20:36:33 +03:00
|
|
|
import TagPanelButtons from './TagPanelButtons';
|
2018-04-13 02:43:44 +03:00
|
|
|
import SettingsStore from '../../settings/SettingsStore';
|
2019-02-24 07:42:04 +03:00
|
|
|
import {_t} from "../../languageHandler";
|
2019-04-04 23:17:15 +03:00
|
|
|
import Analytics from "../../Analytics";
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
|
2019-08-30 12:34:59 +03:00
|
|
|
const LeftPanel = createReactClass({
|
2018-04-12 01:58:04 +03:00
|
|
|
displayName: 'LeftPanel',
|
|
|
|
|
|
|
|
// NB. If you add props, don't forget to update
|
|
|
|
// shouldComponentUpdate!
|
|
|
|
propTypes: {
|
|
|
|
collapsed: PropTypes.bool.isRequired,
|
|
|
|
},
|
|
|
|
|
|
|
|
contextTypes: {
|
|
|
|
matrixClient: PropTypes.instanceOf(MatrixClient),
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
searchFilter: '',
|
2019-04-01 20:49:29 +03:00
|
|
|
breadcrumbs: false,
|
2018-04-12 01:58:04 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
|
|
|
this.focusedElement = null;
|
2019-04-01 20:49:29 +03:00
|
|
|
|
|
|
|
this._settingWatchRef = SettingsStore.watchSetting(
|
2019-06-03 09:15:33 +03:00
|
|
|
"breadcrumbs", null, this._onBreadcrumbsChanged);
|
2019-04-01 20:49:29 +03:00
|
|
|
|
2019-06-03 09:15:33 +03:00
|
|
|
const useBreadcrumbs = !!SettingsStore.getValue("breadcrumbs");
|
2019-04-04 23:17:15 +03:00
|
|
|
Analytics.setBreadcrumbs(useBreadcrumbs);
|
|
|
|
this.setState({breadcrumbs: useBreadcrumbs});
|
2019-04-01 20:49:29 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
SettingsStore.unwatchSetting(this._settingWatchRef);
|
2018-04-12 01:58:04 +03: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 14:46:18 +03:00
|
|
|
if (this.state.searchExpanded !== nextState.searchExpanded) {
|
2019-09-10 11:57:25 +03:00
|
|
|
return true;
|
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
2019-04-05 18:40:21 +03:00
|
|
|
componentDidUpdate(prevProps, prevState) {
|
|
|
|
if (prevState.breadcrumbs !== this.state.breadcrumbs) {
|
|
|
|
Analytics.setBreadcrumbs(this.state.breadcrumbs);
|
|
|
|
}
|
2019-04-04 23:17:15 +03:00
|
|
|
},
|
|
|
|
|
2019-04-01 20:49:29 +03: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-12 01:58:04 +03:00
|
|
|
_onFocus: function(ev) {
|
|
|
|
this.focusedElement = ev.target;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onBlur: function(ev) {
|
|
|
|
this.focusedElement = null;
|
|
|
|
},
|
|
|
|
|
|
|
|
_onKeyDown: function(ev) {
|
|
|
|
if (!this.focusedElement) return;
|
2018-06-16 10:52:14 +03:00
|
|
|
let handled = true;
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
switch (ev.keyCode) {
|
2018-06-16 10:50:53 +03:00
|
|
|
case KeyCode.TAB:
|
|
|
|
this._onMoveFocus(ev.shiftKey);
|
|
|
|
break;
|
2018-04-12 01:58:04 +03:00
|
|
|
case KeyCode.UP:
|
|
|
|
this._onMoveFocus(true);
|
|
|
|
break;
|
|
|
|
case KeyCode.DOWN:
|
|
|
|
this._onMoveFocus(false);
|
|
|
|
break;
|
2018-06-16 10:42:28 +03:00
|
|
|
case KeyCode.ENTER:
|
|
|
|
this._onMoveFocus(false);
|
2018-06-16 10:44:57 +03:00
|
|
|
if (this.focusedElement) {
|
|
|
|
this.focusedElement.click();
|
|
|
|
}
|
2018-06-16 10:42:28 +03:00
|
|
|
break;
|
2018-06-16 10:52:14 +03:00
|
|
|
default:
|
|
|
|
handled = false;
|
2018-04-12 01:58:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (handled) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onMoveFocus: function(up) {
|
2018-06-16 10:42:40 +03:00
|
|
|
let element = this.focusedElement;
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
// unclear why this isn't needed
|
|
|
|
// var descending = (up == this.focusDirection) ? this.focusDescending : !this.focusDescending;
|
|
|
|
// this.focusDirection = up;
|
|
|
|
|
2018-06-16 10:42:40 +03:00
|
|
|
let descending = false; // are we currently descending or ascending through the DOM tree?
|
|
|
|
let classes;
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
do {
|
2018-06-16 10:42:40 +03:00
|
|
|
const child = up ? element.lastElementChild : element.firstElementChild;
|
|
|
|
const sibling = up ? element.previousElementSibling : element.nextElementSibling;
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
if (descending) {
|
|
|
|
if (child) {
|
|
|
|
element = child;
|
2018-06-16 10:42:40 +03:00
|
|
|
} else if (sibling) {
|
2018-04-12 01:58:04 +03:00
|
|
|
element = sibling;
|
2018-06-16 10:42:40 +03:00
|
|
|
} else {
|
2018-04-12 01:58:04 +03:00
|
|
|
descending = false;
|
|
|
|
element = element.parentElement;
|
|
|
|
}
|
2018-06-16 10:42:40 +03:00
|
|
|
} else {
|
2018-04-12 01:58:04 +03:00
|
|
|
if (sibling) {
|
|
|
|
element = sibling;
|
|
|
|
descending = true;
|
2018-06-16 10:42:40 +03:00
|
|
|
} else {
|
2018-04-12 01:58:04 +03:00
|
|
|
element = element.parentElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (element) {
|
|
|
|
classes = element.classList;
|
|
|
|
if (classes.contains("mx_LeftPanel")) { // we hit the top
|
|
|
|
element = up ? element.lastElementChild : element.firstElementChild;
|
|
|
|
descending = true;
|
|
|
|
}
|
|
|
|
}
|
2018-06-16 10:42:40 +03:00
|
|
|
} while (element && !(
|
2018-04-12 01:58:04 +03:00
|
|
|
classes.contains("mx_RoomTile") ||
|
2018-12-20 23:23:06 +03:00
|
|
|
classes.contains("mx_textinput_search")));
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
if (element) {
|
|
|
|
element.focus();
|
|
|
|
this.focusedElement = element;
|
|
|
|
this.focusedDescending = descending;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onHideClick: function() {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'hide_left_panel',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
onSearch: function(term) {
|
|
|
|
this.setState({ searchFilter: term });
|
|
|
|
},
|
|
|
|
|
2018-11-05 11:35:44 +03:00
|
|
|
onSearchCleared: function(source) {
|
|
|
|
if (source === "keyboard") {
|
|
|
|
dis.dispatch({action: 'focus_composer'});
|
|
|
|
}
|
2019-09-11 14:46:18 +03:00
|
|
|
this.setState({searchExpanded: false});
|
2018-11-05 11:35:44 +03:00
|
|
|
},
|
|
|
|
|
2018-04-12 01:58:04 +03:00
|
|
|
collectRoomList: function(ref) {
|
|
|
|
this._roomList = ref;
|
|
|
|
},
|
|
|
|
|
2019-09-10 11:57:25 +03:00
|
|
|
_onSearchFocus: function() {
|
2019-09-11 14:46:18 +03:00
|
|
|
this.setState({searchExpanded: true});
|
2019-09-10 11:57:25 +03:00
|
|
|
},
|
|
|
|
|
2019-09-11 14:46:18 +03:00
|
|
|
_onSearchBlur: function(event) {
|
|
|
|
if (event.target.value.length === 0) {
|
|
|
|
this.setState({searchExpanded: false});
|
|
|
|
}
|
2019-09-10 11:57:25 +03:00
|
|
|
},
|
|
|
|
|
2018-04-12 01:58:04 +03:00
|
|
|
render: function() {
|
|
|
|
const RoomList = sdk.getComponent('rooms.RoomList');
|
2019-02-12 13:04:25 +03:00
|
|
|
const RoomBreadcrumbs = sdk.getComponent('rooms.RoomBreadcrumbs');
|
2018-04-12 01:58:04 +03:00
|
|
|
const TagPanel = sdk.getComponent('structures.TagPanel');
|
2019-02-05 20:39:02 +03:00
|
|
|
const CustomRoomTagPanel = sdk.getComponent('structures.CustomRoomTagPanel');
|
2018-10-23 14:29:44 +03:00
|
|
|
const TopLeftMenuButton = sdk.getComponent('structures.TopLeftMenuButton');
|
2018-11-02 17:27:17 +03:00
|
|
|
const SearchBox = sdk.getComponent('structures.SearchBox');
|
2018-04-12 01:58:04 +03:00
|
|
|
const CallPreview = sdk.getComponent('voip.CallPreview');
|
2019-09-10 11:53:55 +03:00
|
|
|
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
|
2018-10-26 16:57:57 +03:00
|
|
|
|
2019-01-25 06:57:40 +03:00
|
|
|
const tagPanelEnabled = SettingsStore.getValue("TagPanel.enableTagPanel");
|
2019-02-05 20:36:33 +03:00
|
|
|
let tagPanelContainer;
|
2019-02-07 21:04:30 +03:00
|
|
|
|
|
|
|
const isCustomTagsEnabled = SettingsStore.isFeatureEnabled("feature_custom_tags");
|
|
|
|
|
2019-02-05 20:36:33 +03:00
|
|
|
if (tagPanelEnabled) {
|
|
|
|
tagPanelContainer = (<div className="mx_LeftPanel_tagPanelContainer">
|
|
|
|
<TagPanel />
|
2019-02-07 21:04:30 +03:00
|
|
|
{ isCustomTagsEnabled ? <CustomRoomTagPanel /> : undefined }
|
2019-02-05 20:36:33 +03:00
|
|
|
<TagPanelButtons />
|
|
|
|
</div>);
|
|
|
|
}
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
const containerClasses = classNames(
|
|
|
|
"mx_LeftPanel_container", "mx_fadable",
|
|
|
|
{
|
2018-10-16 18:38:34 +03:00
|
|
|
"collapsed": this.props.collapsed,
|
2018-04-12 01:58:04 +03:00
|
|
|
"mx_LeftPanel_container_hasTagPanel": tagPanelEnabled,
|
|
|
|
"mx_fadable_faded": this.props.disabled,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
2019-09-10 11:53:55 +03:00
|
|
|
let exploreButton;
|
|
|
|
if (!this.props.collapsed) {
|
|
|
|
exploreButton = (
|
2019-09-11 14:46:18 +03:00
|
|
|
<div className={classNames("mx_LeftPanel_explore", {"mx_LeftPanel_explore_hidden": this.state.searchExpanded})}>
|
2019-09-10 11:53:55 +03:00
|
|
|
<AccessibleButton onClick={() => dis.dispatch({action: 'view_room_directory'})}>{_t("Explore")}</AccessibleButton>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-04 21:51:41 +03:00
|
|
|
const searchBox = (<SearchBox
|
2019-03-06 17:53:52 +03:00
|
|
|
enableRoomSearchFocus={true}
|
2019-09-10 11:58:11 +03:00
|
|
|
blurredPlaceholder={ _t('Filter') }
|
|
|
|
placeholder={ _t('Filter rooms…') }
|
2019-02-04 21:51:41 +03:00
|
|
|
onSearch={ this.onSearch }
|
|
|
|
onCleared={ this.onSearchCleared }
|
2019-09-10 11:57:25 +03:00
|
|
|
onFocus={this._onSearchFocus}
|
|
|
|
onBlur={this._onSearchBlur}
|
2019-02-04 21:51:41 +03:00
|
|
|
collapsed={this.props.collapsed} />);
|
2018-11-02 17:29:18 +03:00
|
|
|
|
2019-02-12 13:41:24 +03:00
|
|
|
let breadcrumbs;
|
2019-04-01 20:49:29 +03:00
|
|
|
if (this.state.breadcrumbs) {
|
2019-02-12 13:41:24 +03:00
|
|
|
breadcrumbs = (<RoomBreadcrumbs collapsed={this.props.collapsed} />);
|
|
|
|
}
|
|
|
|
|
2018-04-12 01:58:04 +03:00
|
|
|
return (
|
|
|
|
<div className={containerClasses}>
|
2019-02-05 20:36:33 +03:00
|
|
|
{ tagPanelContainer }
|
2018-11-05 11:32:37 +03:00
|
|
|
<aside className={"mx_LeftPanel dark-panel"} onKeyDown={ this._onKeyDown } onFocus={ this._onFocus } onBlur={ this._onBlur }>
|
2018-11-05 14:15:03 +03:00
|
|
|
<TopLeftMenuButton collapsed={ this.props.collapsed } />
|
2019-02-12 13:41:24 +03:00
|
|
|
{ breadcrumbs }
|
2019-09-10 11:53:55 +03:00
|
|
|
<div className="mx_LeftPanel_exploreAndFilterRow">
|
|
|
|
{ exploreButton }
|
|
|
|
{ searchBox }
|
|
|
|
</div>
|
2018-04-12 01:58:04 +03:00
|
|
|
<CallPreview ConferenceHandler={VectorConferenceHandler} />
|
|
|
|
<RoomList
|
|
|
|
ref={this.collectRoomList}
|
2019-03-12 20:00:05 +03:00
|
|
|
resizeNotifier={this.props.resizeNotifier}
|
2018-04-12 01:58:04 +03:00
|
|
|
collapsed={this.props.collapsed}
|
|
|
|
searchFilter={this.state.searchFilter}
|
|
|
|
ConferenceHandler={VectorConferenceHandler} />
|
|
|
|
</aside>
|
|
|
|
</div>
|
|
|
|
);
|
2018-10-27 06:50:35 +03:00
|
|
|
},
|
2018-04-12 01:58:04 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = LeftPanel;
|