2018-04-12 01:58:04 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2019-10-23 14:12:11 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2018-04-12 01:58:04 +03: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 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';
|
2019-10-23 14:12:11 +03:00
|
|
|
import { Key } from '../../Keyboard';
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../../index';
|
2018-04-13 02:43:44 +03:00
|
|
|
import dis from '../../dispatcher';
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as VectorConferenceHandler from '../../VectorConferenceHandler';
|
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,
|
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-10-04 01:21:32 +03:00
|
|
|
this._breadcrumbsWatcherRef = SettingsStore.watchSetting(
|
2019-06-03 09:15:33 +03:00
|
|
|
"breadcrumbs", null, this._onBreadcrumbsChanged);
|
2019-10-04 01:21:32 +03:00
|
|
|
this._tagPanelWatcherRef = SettingsStore.watchSetting(
|
2019-10-04 00:13:10 +03:00
|
|
|
"TagPanel.enableTagPanel", null, () => this.forceUpdate());
|
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() {
|
2019-10-04 01:21:32 +03:00
|
|
|
SettingsStore.unwatchSetting(this._breadcrumbsWatcherRef);
|
|
|
|
SettingsStore.unwatchSetting(this._tagPanelWatcherRef);
|
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;
|
|
|
|
},
|
|
|
|
|
2019-10-23 20:31:00 +03:00
|
|
|
_onFilterKeyDown: function(ev) {
|
|
|
|
if (!this.focusedElement) return;
|
|
|
|
|
|
|
|
switch (ev.key) {
|
2019-10-23 20:45:04 +03:00
|
|
|
// On enter of rooms filter select and activate first room if such one exists
|
2019-10-23 20:31:00 +03:00
|
|
|
case Key.ENTER: {
|
|
|
|
const firstRoom = ev.target.closest(".mx_LeftPanel").querySelector(".mx_RoomTile");
|
|
|
|
if (firstRoom) {
|
|
|
|
firstRoom.click();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-04-12 01:58:04 +03:00
|
|
|
_onKeyDown: function(ev) {
|
|
|
|
if (!this.focusedElement) return;
|
|
|
|
|
2019-10-23 14:12:11 +03:00
|
|
|
switch (ev.key) {
|
|
|
|
case Key.ARROW_UP:
|
|
|
|
this._onMoveFocus(ev, true, true);
|
2018-04-12 01:58:04 +03:00
|
|
|
break;
|
2019-10-23 14:12:11 +03:00
|
|
|
case Key.ARROW_DOWN:
|
|
|
|
this._onMoveFocus(ev, false, true);
|
2018-04-12 01:58:04 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-10-23 14:12:11 +03:00
|
|
|
_onMoveFocus: function(ev, up, trap) {
|
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;
|
|
|
|
}
|
2018-06-16 10:42:40 +03:00
|
|
|
} while (element && !(
|
2018-04-12 01:58:04 +03:00
|
|
|
classes.contains("mx_RoomTile") ||
|
2019-10-17 17:53:39 +03:00
|
|
|
classes.contains("mx_RoomSubList_label") ||
|
2019-10-23 14:12:11 +03:00
|
|
|
classes.contains("mx_LeftPanel_filterRooms")));
|
2018-04-12 01:58:04 +03:00
|
|
|
|
|
|
|
if (element) {
|
2019-10-23 14:12:11 +03:00
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
2018-04-12 01:58:04 +03:00
|
|
|
element.focus();
|
|
|
|
this.focusedElement = element;
|
2019-10-23 14:12:11 +03: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-12 01:58:04 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
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
|
|
|
</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-10-23 14:12:11 +03:00
|
|
|
className="mx_LeftPanel_filterRooms"
|
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-10-23 20:31:00 +03:00
|
|
|
onKeyDown={this._onFilterKeyDown}
|
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 }
|
2019-10-23 14:12:11 +03:00
|
|
|
<aside className="mx_LeftPanel dark-panel">
|
|
|
|
<TopLeftMenuButton collapsed={this.props.collapsed} />
|
2019-02-12 13:41:24 +03:00
|
|
|
{ breadcrumbs }
|
2019-10-23 15:05:02 +03:00
|
|
|
<CallPreview ConferenceHandler={VectorConferenceHandler} />
|
2019-10-23 20:31:00 +03:00
|
|
|
<div className="mx_LeftPanel_exploreAndFilterRow" onKeyDown={this._onKeyDown} onFocus={this._onFocus} onBlur={this._onBlur}>
|
|
|
|
{ exploreButton }
|
|
|
|
{ searchBox }
|
2019-09-10 11:53:55 +03:00
|
|
|
</div>
|
2019-10-23 20:31:00 +03: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-12 01:58:04 +03:00
|
|
|
</aside>
|
|
|
|
</div>
|
|
|
|
);
|
2018-10-27 06:50:35 +03:00
|
|
|
},
|
2018-04-12 01:58:04 +03:00
|
|
|
});
|
|
|
|
|
2019-12-20 03:45:24 +03:00
|
|
|
export default LeftPanel;
|