2020-06-03 04:26:07 +03:00
|
|
|
/*
|
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
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 * as React from "react";
|
2020-06-24 05:59:26 +03:00
|
|
|
import { createRef } from "react";
|
2021-03-24 22:43:09 +03:00
|
|
|
import classNames from "classnames";
|
|
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
|
|
|
|
2020-10-10 15:30:06 +03:00
|
|
|
import GroupFilterPanel from "./GroupFilterPanel";
|
2020-07-21 01:51:16 +03:00
|
|
|
import CustomRoomTagPanel from "./CustomRoomTagPanel";
|
2020-06-03 04:26:07 +03:00
|
|
|
import dis from "../../dispatcher/dispatcher";
|
|
|
|
import { _t } from "../../languageHandler";
|
2020-07-18 00:27:49 +03:00
|
|
|
import RoomList from "../views/rooms/RoomList";
|
2020-07-18 00:46:46 +03:00
|
|
|
import { HEADER_HEIGHT } from "../views/rooms/RoomSublist";
|
2020-06-03 04:26:07 +03:00
|
|
|
import { Action } from "../../dispatcher/actions";
|
2020-06-26 04:38:11 +03:00
|
|
|
import UserMenu from "./UserMenu";
|
2020-06-09 05:33:21 +03:00
|
|
|
import RoomSearch from "./RoomSearch";
|
2020-07-18 00:32:06 +03:00
|
|
|
import RoomBreadcrumbs from "../views/rooms/RoomBreadcrumbs";
|
2020-06-09 02:11:58 +03:00
|
|
|
import { BreadcrumbsStore } from "../../stores/BreadcrumbsStore";
|
|
|
|
import { UPDATE_EVENT } from "../../stores/AsyncStore";
|
2020-06-22 22:09:42 +03:00
|
|
|
import ResizeNotifier from "../../utils/ResizeNotifier";
|
2020-06-26 05:35:40 +03:00
|
|
|
import SettingsStore from "../../settings/SettingsStore";
|
2020-07-18 00:11:34 +03:00
|
|
|
import RoomListStore, { LISTS_UPDATE_EVENT } from "../../stores/room-list/RoomListStore";
|
2020-07-06 23:32:46 +03:00
|
|
|
import IndicatorScrollbar from "../structures/IndicatorScrollbar";
|
2020-07-17 20:57:38 +03:00
|
|
|
import AccessibleTooltipButton from "../views/elements/AccessibleTooltipButton";
|
2020-07-22 00:02:59 +03:00
|
|
|
import { OwnProfileStore } from "../../stores/OwnProfileStore";
|
2020-08-17 20:20:00 +03:00
|
|
|
import RoomListNumResults from "../views/rooms/RoomListNumResults";
|
2020-09-24 11:28:49 +03:00
|
|
|
import LeftPanelWidget from "./LeftPanelWidget";
|
2021-03-09 05:35:10 +03:00
|
|
|
import {replaceableComponent} from "../../utils/replaceableComponent";
|
2021-03-04 05:06:46 +03:00
|
|
|
import {mediaFromMxc} from "../../customisations/Media";
|
2021-03-24 22:43:09 +03:00
|
|
|
import SpaceStore, {UPDATE_SELECTED_SPACE} from "../../stores/SpaceStore";
|
2021-03-28 09:28:48 +03:00
|
|
|
import { getKeyBindingsManager, RoomListAction } from "../../KeyBindingsManager";
|
2021-05-25 12:25:36 +03:00
|
|
|
import UIStore from "../../stores/UIStore";
|
2020-06-03 04:26:07 +03:00
|
|
|
|
|
|
|
interface IProps {
|
2020-06-11 23:39:28 +03:00
|
|
|
isMinimized: boolean;
|
2020-06-22 22:09:42 +03:00
|
|
|
resizeNotifier: ResizeNotifier;
|
2020-06-03 04:26:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
interface IState {
|
2020-06-09 02:11:58 +03:00
|
|
|
showBreadcrumbs: boolean;
|
2020-10-10 15:30:06 +03:00
|
|
|
showGroupFilterPanel: boolean;
|
2021-03-24 22:43:09 +03:00
|
|
|
activeSpace?: Room;
|
2020-06-03 04:26:07 +03:00
|
|
|
}
|
|
|
|
|
2020-07-06 03:14:02 +03:00
|
|
|
// List of CSS classes which should be included in keyboard navigation within the room list
|
|
|
|
const cssClasses = [
|
|
|
|
"mx_RoomSearch_input",
|
2020-09-18 19:13:45 +03:00
|
|
|
"mx_RoomSearch_minimizedHandle", // minimized <RoomSearch />
|
2020-07-18 00:46:46 +03:00
|
|
|
"mx_RoomSublist_headerText",
|
2020-07-18 00:43:29 +03:00
|
|
|
"mx_RoomTile",
|
2020-07-18 00:46:46 +03:00
|
|
|
"mx_RoomSublist_showNButton",
|
2020-07-06 03:14:02 +03:00
|
|
|
];
|
|
|
|
|
2021-03-09 05:35:10 +03:00
|
|
|
@replaceableComponent("structures.LeftPanel")
|
2020-07-18 00:22:18 +03:00
|
|
|
export default class LeftPanel extends React.Component<IProps, IState> {
|
2021-05-27 14:36:16 +03:00
|
|
|
private ref: React.RefObject<HTMLDivElement> = createRef();
|
2020-06-22 22:09:42 +03:00
|
|
|
private listContainerRef: React.RefObject<HTMLDivElement> = createRef();
|
2020-10-13 18:26:28 +03:00
|
|
|
private groupFilterPanelWatcherRef: string;
|
2020-07-22 00:02:59 +03:00
|
|
|
private bgImageWatcherRef: string;
|
2020-07-03 00:21:10 +03:00
|
|
|
private focusedElement = null;
|
2020-07-07 20:33:32 +03:00
|
|
|
private isDoingStickyHeaders = false;
|
2020-06-22 22:09:42 +03:00
|
|
|
|
2020-06-03 04:26:07 +03:00
|
|
|
constructor(props: IProps) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2020-06-09 02:11:58 +03:00
|
|
|
showBreadcrumbs: BreadcrumbsStore.instance.visible,
|
2020-10-13 18:26:28 +03:00
|
|
|
showGroupFilterPanel: SettingsStore.getValue('TagPanel.enableTagPanel'),
|
2021-03-24 22:43:09 +03:00
|
|
|
activeSpace: SpaceStore.instance.activeSpace,
|
2020-06-03 04:26:07 +03:00
|
|
|
};
|
2020-06-09 02:11:58 +03:00
|
|
|
|
|
|
|
BreadcrumbsStore.instance.on(UPDATE_EVENT, this.onBreadcrumbsUpdate);
|
2020-07-01 18:05:27 +03:00
|
|
|
RoomListStore.instance.on(LISTS_UPDATE_EVENT, this.onBreadcrumbsUpdate);
|
2020-07-22 00:02:59 +03:00
|
|
|
OwnProfileStore.instance.on(UPDATE_EVENT, this.onBackgroundImageUpdate);
|
2021-03-24 22:43:09 +03:00
|
|
|
SpaceStore.instance.on(UPDATE_SELECTED_SPACE, this.updateActiveSpace);
|
2020-07-22 00:02:59 +03:00
|
|
|
this.bgImageWatcherRef = SettingsStore.watchSetting(
|
|
|
|
"RoomList.backgroundImage", null, this.onBackgroundImageUpdate);
|
2020-10-13 18:26:28 +03:00
|
|
|
this.groupFilterPanelWatcherRef = SettingsStore.watchSetting("TagPanel.enableTagPanel", null, () => {
|
2020-10-13 18:37:18 +03:00
|
|
|
this.setState({showGroupFilterPanel: SettingsStore.getValue("TagPanel.enableTagPanel")});
|
2020-06-26 05:35:40 +03:00
|
|
|
});
|
2020-06-09 02:11:58 +03:00
|
|
|
}
|
|
|
|
|
2021-05-27 14:36:16 +03:00
|
|
|
public componentDidMount() {
|
2021-05-27 14:44:53 +03:00
|
|
|
UIStore.instance.trackElementDimensions("ListContainer", this.listContainerRef.current);
|
|
|
|
UIStore.instance.on("ListContainer", this.refreshStickyHeaders);
|
2021-05-28 16:59:14 +03:00
|
|
|
// Using the passive option to not block the main thread
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#improving_scrolling_performance_with_passive_listeners
|
2021-05-28 19:37:29 +03:00
|
|
|
this.listContainerRef.current?.addEventListener("scroll", this.onScroll, { passive: true });
|
2021-05-27 14:36:16 +03:00
|
|
|
}
|
|
|
|
|
2020-06-09 02:11:58 +03:00
|
|
|
public componentWillUnmount() {
|
2020-10-13 18:26:28 +03:00
|
|
|
SettingsStore.unwatchSetting(this.groupFilterPanelWatcherRef);
|
2020-07-22 00:02:59 +03:00
|
|
|
SettingsStore.unwatchSetting(this.bgImageWatcherRef);
|
2020-06-09 02:11:58 +03:00
|
|
|
BreadcrumbsStore.instance.off(UPDATE_EVENT, this.onBreadcrumbsUpdate);
|
2020-07-01 18:05:27 +03:00
|
|
|
RoomListStore.instance.off(LISTS_UPDATE_EVENT, this.onBreadcrumbsUpdate);
|
2020-07-22 00:02:59 +03:00
|
|
|
OwnProfileStore.instance.off(UPDATE_EVENT, this.onBackgroundImageUpdate);
|
2021-03-24 22:43:09 +03:00
|
|
|
SpaceStore.instance.off(UPDATE_SELECTED_SPACE, this.updateActiveSpace);
|
2021-05-27 14:44:53 +03:00
|
|
|
UIStore.instance.stopTrackingElementDimensions("ListContainer");
|
|
|
|
UIStore.instance.removeListener("ListContainer", this.refreshStickyHeaders);
|
2021-05-28 19:37:29 +03:00
|
|
|
this.listContainerRef.current?.removeEventListener("scroll", this.onScroll);
|
2020-06-03 04:26:07 +03:00
|
|
|
}
|
|
|
|
|
2021-05-28 12:31:42 +03:00
|
|
|
public componentDidUpdate(prevProps: IProps, prevState: IState): void {
|
|
|
|
if (prevState.activeSpace !== this.state.activeSpace) {
|
|
|
|
this.refreshStickyHeaders();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-24 22:43:09 +03:00
|
|
|
private updateActiveSpace = (activeSpace: Room) => {
|
|
|
|
this.setState({ activeSpace });
|
|
|
|
};
|
|
|
|
|
2020-06-09 05:33:21 +03:00
|
|
|
private onExplore = () => {
|
|
|
|
dis.fire(Action.ViewRoomDirectory);
|
2020-06-03 04:26:07 +03:00
|
|
|
};
|
|
|
|
|
2021-05-25 15:53:20 +03:00
|
|
|
private refreshStickyHeaders = () => {
|
|
|
|
if (!this.listContainerRef.current) return; // ignore: no headers to sticky
|
|
|
|
this.handleStickyHeaders(this.listContainerRef.current);
|
|
|
|
}
|
|
|
|
|
2020-06-09 02:11:58 +03:00
|
|
|
private onBreadcrumbsUpdate = () => {
|
|
|
|
const newVal = BreadcrumbsStore.instance.visible;
|
|
|
|
if (newVal !== this.state.showBreadcrumbs) {
|
|
|
|
this.setState({showBreadcrumbs: newVal});
|
2020-07-14 05:08:12 +03:00
|
|
|
|
|
|
|
// Update the sticky headers too as the breadcrumbs will be popping in or out.
|
|
|
|
if (!this.listContainerRef.current) return; // ignore: no headers to sticky
|
|
|
|
this.handleStickyHeaders(this.listContainerRef.current);
|
2020-06-09 02:11:58 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-22 00:02:59 +03:00
|
|
|
private onBackgroundImageUpdate = () => {
|
|
|
|
// Note: we do this in the LeftPanel as it uses this variable most prominently.
|
|
|
|
const avatarSize = 32; // arbitrary
|
|
|
|
let avatarUrl = OwnProfileStore.instance.getHttpAvatarUrl(avatarSize);
|
|
|
|
const settingBgMxc = SettingsStore.getValue("RoomList.backgroundImage");
|
|
|
|
if (settingBgMxc) {
|
2021-03-04 05:06:46 +03:00
|
|
|
avatarUrl = mediaFromMxc(settingBgMxc).getSquareThumbnailHttp(avatarSize);
|
2020-07-22 00:02:59 +03:00
|
|
|
}
|
2020-10-14 13:41:24 +03:00
|
|
|
|
2020-07-22 00:02:59 +03:00
|
|
|
const avatarUrlProp = `url(${avatarUrl})`;
|
2020-10-15 18:57:07 +03:00
|
|
|
if (!avatarUrl) {
|
2020-10-14 13:41:24 +03:00
|
|
|
document.body.style.removeProperty("--avatar-url");
|
2020-10-15 19:15:01 +03:00
|
|
|
} else if (document.body.style.getPropertyValue("--avatar-url") !== avatarUrlProp) {
|
2020-07-22 00:02:59 +03:00
|
|
|
document.body.style.setProperty("--avatar-url", avatarUrlProp);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-22 22:09:42 +03:00
|
|
|
private handleStickyHeaders(list: HTMLDivElement) {
|
2020-07-07 20:33:32 +03:00
|
|
|
if (this.isDoingStickyHeaders) return;
|
|
|
|
this.isDoingStickyHeaders = true;
|
2020-07-08 21:17:51 +03:00
|
|
|
window.requestAnimationFrame(() => {
|
2020-07-07 20:33:32 +03:00
|
|
|
this.doStickyHeaders(list);
|
|
|
|
this.isDoingStickyHeaders = false;
|
2020-07-08 21:17:51 +03:00
|
|
|
});
|
2020-07-07 20:33:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private doStickyHeaders(list: HTMLDivElement) {
|
2020-07-08 23:36:55 +03:00
|
|
|
const topEdge = list.scrollTop;
|
|
|
|
const bottomEdge = list.offsetHeight + list.scrollTop;
|
2021-04-21 12:44:20 +03:00
|
|
|
const sublists = list.querySelectorAll<HTMLDivElement>(".mx_RoomSublist:not(.mx_RoomSublist_hidden)");
|
2020-06-13 20:54:40 +03:00
|
|
|
|
2020-07-08 23:53:52 +03:00
|
|
|
// We track which styles we want on a target before making the changes to avoid
|
|
|
|
// excessive layout updates.
|
|
|
|
const targetStyles = new Map<HTMLDivElement, {
|
|
|
|
stickyTop?: boolean;
|
|
|
|
stickyBottom?: boolean;
|
|
|
|
makeInvisible?: boolean;
|
|
|
|
}>();
|
|
|
|
|
2020-07-03 13:17:54 +03:00
|
|
|
let lastTopHeader;
|
2020-07-08 23:36:55 +03:00
|
|
|
let firstBottomHeader;
|
2020-06-13 20:54:40 +03:00
|
|
|
for (const sublist of sublists) {
|
2020-07-18 00:46:46 +03:00
|
|
|
const header = sublist.querySelector<HTMLDivElement>(".mx_RoomSublist_stickable");
|
2020-07-08 11:21:33 +03:00
|
|
|
header.style.removeProperty("display"); // always clear display:none first
|
2020-06-13 20:54:40 +03:00
|
|
|
|
2020-07-08 23:36:55 +03:00
|
|
|
// When an element is <=40% off screen, make it take over
|
|
|
|
const offScreenFactor = 0.4;
|
|
|
|
const isOffTop = (sublist.offsetTop + (offScreenFactor * HEADER_HEIGHT)) <= topEdge;
|
|
|
|
const isOffBottom = (sublist.offsetTop + (offScreenFactor * HEADER_HEIGHT)) >= bottomEdge;
|
|
|
|
|
|
|
|
if (isOffTop || sublist === sublists[0]) {
|
2020-07-08 23:53:52 +03:00
|
|
|
targetStyles.set(header, { stickyTop: true });
|
2020-07-03 13:17:54 +03:00
|
|
|
if (lastTopHeader) {
|
|
|
|
lastTopHeader.style.display = "none";
|
2020-07-08 23:53:52 +03:00
|
|
|
targetStyles.set(lastTopHeader, { makeInvisible: true });
|
2020-07-03 13:17:54 +03:00
|
|
|
}
|
|
|
|
lastTopHeader = header;
|
2020-07-08 23:36:55 +03:00
|
|
|
} else if (isOffBottom && !firstBottomHeader) {
|
2020-07-08 23:53:52 +03:00
|
|
|
targetStyles.set(header, { stickyBottom: true });
|
2020-07-08 23:36:55 +03:00
|
|
|
firstBottomHeader = header;
|
2020-06-13 20:54:40 +03:00
|
|
|
} else {
|
2020-07-08 23:53:52 +03:00
|
|
|
targetStyles.set(header, {}); // nothing == clear
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run over the style changes and make them reality. We check to see if we're about to
|
|
|
|
// cause a no-op update, as adding/removing properties that are/aren't there cause
|
|
|
|
// layout updates.
|
|
|
|
for (const header of targetStyles.keys()) {
|
|
|
|
const style = targetStyles.get(header);
|
|
|
|
|
|
|
|
if (style.makeInvisible) {
|
|
|
|
// we will have already removed the 'display: none', so add it back.
|
|
|
|
header.style.display = "none";
|
|
|
|
continue; // nothing else to do, even if sticky somehow
|
|
|
|
}
|
|
|
|
|
|
|
|
if (style.stickyTop) {
|
2020-07-18 00:46:46 +03:00
|
|
|
if (!header.classList.contains("mx_RoomSublist_headerContainer_stickyTop")) {
|
|
|
|
header.classList.add("mx_RoomSublist_headerContainer_stickyTop");
|
2020-07-08 23:53:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const newTop = `${list.parentElement.offsetTop}px`;
|
|
|
|
if (header.style.top !== newTop) {
|
|
|
|
header.style.top = newTop;
|
|
|
|
}
|
2020-07-13 23:24:43 +03:00
|
|
|
} else {
|
2020-07-18 00:46:46 +03:00
|
|
|
if (header.classList.contains("mx_RoomSublist_headerContainer_stickyTop")) {
|
|
|
|
header.classList.remove("mx_RoomSublist_headerContainer_stickyTop");
|
2020-07-13 23:24:43 +03:00
|
|
|
}
|
|
|
|
if (header.style.top) {
|
|
|
|
header.style.removeProperty('top');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (style.stickyBottom) {
|
2020-07-18 00:46:46 +03:00
|
|
|
if (!header.classList.contains("mx_RoomSublist_headerContainer_stickyBottom")) {
|
|
|
|
header.classList.add("mx_RoomSublist_headerContainer_stickyBottom");
|
2020-07-08 23:53:52 +03:00
|
|
|
}
|
2020-09-23 13:00:19 +03:00
|
|
|
|
2021-05-25 12:25:36 +03:00
|
|
|
const offset = UIStore.instance.windowHeight -
|
|
|
|
(list.parentElement.offsetTop + list.parentElement.offsetHeight);
|
2020-09-23 13:00:19 +03:00
|
|
|
const newBottom = `${offset}px`;
|
|
|
|
if (header.style.bottom !== newBottom) {
|
|
|
|
header.style.bottom = newBottom;
|
|
|
|
}
|
2020-07-13 23:24:43 +03:00
|
|
|
} else {
|
2020-07-18 00:46:46 +03:00
|
|
|
if (header.classList.contains("mx_RoomSublist_headerContainer_stickyBottom")) {
|
|
|
|
header.classList.remove("mx_RoomSublist_headerContainer_stickyBottom");
|
2020-07-13 23:24:43 +03:00
|
|
|
}
|
2020-09-23 13:00:19 +03:00
|
|
|
if (header.style.bottom) {
|
|
|
|
header.style.removeProperty('bottom');
|
|
|
|
}
|
2020-07-08 23:53:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (style.stickyTop || style.stickyBottom) {
|
2020-07-18 00:46:46 +03:00
|
|
|
if (!header.classList.contains("mx_RoomSublist_headerContainer_sticky")) {
|
|
|
|
header.classList.add("mx_RoomSublist_headerContainer_sticky");
|
2020-07-08 23:53:52 +03:00
|
|
|
}
|
2021-05-27 14:44:53 +03:00
|
|
|
|
|
|
|
const listDimensions = UIStore.instance.getElementDimensions("ListContainer");
|
|
|
|
if (listDimensions) {
|
|
|
|
const headerRightMargin = 15; // calculated from margins and widths to align with non-sticky tiles
|
|
|
|
const headerStickyWidth = listDimensions.width - headerRightMargin;
|
|
|
|
const newWidth = `${headerStickyWidth}px`;
|
|
|
|
if (header.style.width !== newWidth) {
|
|
|
|
header.style.width = newWidth;
|
|
|
|
}
|
|
|
|
}
|
2020-07-08 23:53:52 +03:00
|
|
|
} else if (!style.stickyTop && !style.stickyBottom) {
|
2020-07-18 00:46:46 +03:00
|
|
|
if (header.classList.contains("mx_RoomSublist_headerContainer_sticky")) {
|
|
|
|
header.classList.remove("mx_RoomSublist_headerContainer_sticky");
|
2020-07-08 23:53:52 +03:00
|
|
|
}
|
2021-05-27 14:44:53 +03:00
|
|
|
|
|
|
|
if (header.style.width) {
|
|
|
|
header.style.removeProperty('width');
|
|
|
|
}
|
2020-06-13 20:54:40 +03:00
|
|
|
}
|
|
|
|
}
|
2020-07-08 15:49:38 +03:00
|
|
|
|
|
|
|
// add appropriate sticky classes to wrapper so it has
|
|
|
|
// the necessary top/bottom padding to put the sticky header in
|
2020-07-18 00:22:18 +03:00
|
|
|
const listWrapper = list.parentElement; // .mx_LeftPanel_roomListWrapper
|
2020-07-08 15:49:38 +03:00
|
|
|
if (lastTopHeader) {
|
2020-07-18 00:22:18 +03:00
|
|
|
listWrapper.classList.add("mx_LeftPanel_roomListWrapper_stickyTop");
|
2020-07-08 15:49:38 +03:00
|
|
|
} else {
|
2020-07-18 00:22:18 +03:00
|
|
|
listWrapper.classList.remove("mx_LeftPanel_roomListWrapper_stickyTop");
|
2020-07-08 15:49:38 +03:00
|
|
|
}
|
2020-07-08 23:36:55 +03:00
|
|
|
if (firstBottomHeader) {
|
2020-07-18 00:22:18 +03:00
|
|
|
listWrapper.classList.add("mx_LeftPanel_roomListWrapper_stickyBottom");
|
2020-07-08 23:36:55 +03:00
|
|
|
} else {
|
2020-07-18 00:22:18 +03:00
|
|
|
listWrapper.classList.remove("mx_LeftPanel_roomListWrapper_stickyBottom");
|
2020-07-08 15:49:38 +03:00
|
|
|
}
|
2020-06-22 22:09:42 +03:00
|
|
|
}
|
|
|
|
|
2021-05-28 16:59:14 +03:00
|
|
|
private onScroll = (ev: Event) => {
|
2020-06-22 22:09:42 +03:00
|
|
|
const list = ev.target as HTMLDivElement;
|
|
|
|
this.handleStickyHeaders(list);
|
|
|
|
};
|
|
|
|
|
2020-07-03 00:21:10 +03:00
|
|
|
private onFocus = (ev: React.FocusEvent) => {
|
|
|
|
this.focusedElement = ev.target;
|
|
|
|
};
|
|
|
|
|
|
|
|
private onBlur = () => {
|
|
|
|
this.focusedElement = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
private onKeyDown = (ev: React.KeyboardEvent) => {
|
|
|
|
if (!this.focusedElement) return;
|
|
|
|
|
2021-03-28 09:28:48 +03:00
|
|
|
const action = getKeyBindingsManager().getRoomListAction(ev);
|
|
|
|
switch (action) {
|
|
|
|
case RoomListAction.NextRoom:
|
|
|
|
case RoomListAction.PrevRoom:
|
2020-07-03 16:49:25 +03:00
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
2021-03-28 09:28:48 +03:00
|
|
|
this.onMoveFocus(action === RoomListAction.PrevRoom);
|
2020-07-03 00:21:10 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-03-28 09:28:48 +03:00
|
|
|
private selectRoom = () => {
|
2020-07-18 00:43:29 +03:00
|
|
|
const firstRoom = this.listContainerRef.current.querySelector<HTMLDivElement>(".mx_RoomTile");
|
2020-07-12 21:06:47 +03:00
|
|
|
if (firstRoom) {
|
|
|
|
firstRoom.click();
|
2020-07-16 08:31:06 +03:00
|
|
|
return true; // to get the field to clear
|
2020-07-12 21:06:47 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-03 16:49:25 +03:00
|
|
|
private onMoveFocus = (up: boolean) => {
|
2020-07-03 00:21:10 +03:00
|
|
|
let element = this.focusedElement;
|
|
|
|
|
|
|
|
let descending = false; // are we currently descending or ascending through the DOM tree?
|
2020-07-03 16:49:25 +03:00
|
|
|
let classes: DOMTokenList;
|
2020-07-03 00:21:10 +03:00
|
|
|
|
|
|
|
do {
|
|
|
|
const child = up ? element.lastElementChild : element.firstElementChild;
|
|
|
|
const sibling = up ? element.previousElementSibling : element.nextElementSibling;
|
|
|
|
|
|
|
|
if (descending) {
|
|
|
|
if (child) {
|
|
|
|
element = child;
|
|
|
|
} else if (sibling) {
|
|
|
|
element = sibling;
|
|
|
|
} else {
|
|
|
|
descending = false;
|
|
|
|
element = element.parentElement;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sibling) {
|
|
|
|
element = sibling;
|
|
|
|
descending = true;
|
|
|
|
} else {
|
|
|
|
element = element.parentElement;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (element) {
|
|
|
|
classes = element.classList;
|
|
|
|
}
|
2021-04-30 13:53:56 +03:00
|
|
|
} while (element && (!cssClasses.some(c => classes.contains(c)) || element.offsetParent === null));
|
2020-07-03 00:21:10 +03:00
|
|
|
|
|
|
|
if (element) {
|
|
|
|
element.focus();
|
|
|
|
this.focusedElement = element;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-05 01:34:04 +03:00
|
|
|
private renderHeader(): React.ReactNode {
|
2020-07-13 15:52:50 +03:00
|
|
|
return (
|
2020-07-18 00:22:18 +03:00
|
|
|
<div className="mx_LeftPanel_userHeader">
|
2020-07-13 15:52:50 +03:00
|
|
|
<UserMenu isMinimized={this.props.isMinimized} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private renderBreadcrumbs(): React.ReactNode {
|
2020-07-06 23:32:46 +03:00
|
|
|
if (this.state.showBreadcrumbs && !this.props.isMinimized) {
|
2020-07-13 15:52:50 +03:00
|
|
|
return (
|
2020-07-06 23:32:46 +03:00
|
|
|
<IndicatorScrollbar
|
2020-07-18 00:22:18 +03:00
|
|
|
className="mx_LeftPanel_breadcrumbsContainer mx_AutoHideScrollbar"
|
2020-07-06 23:32:46 +03:00
|
|
|
verticalScrollsHorizontally={true}
|
2020-07-18 14:19:03 +03:00
|
|
|
// Firefox sometimes makes this element focusable due to
|
|
|
|
// overflow:scroll;, so force it out of tab order.
|
|
|
|
tabIndex={-1}
|
2020-07-06 23:32:46 +03:00
|
|
|
>
|
2020-07-18 00:32:06 +03:00
|
|
|
<RoomBreadcrumbs />
|
2020-07-06 23:32:46 +03:00
|
|
|
</IndicatorScrollbar>
|
2020-06-09 02:11:58 +03:00
|
|
|
);
|
|
|
|
}
|
2020-06-05 01:34:04 +03:00
|
|
|
}
|
2020-06-03 04:26:07 +03:00
|
|
|
|
2020-06-09 05:33:21 +03:00
|
|
|
private renderSearchExplore(): React.ReactNode {
|
|
|
|
return (
|
2020-07-05 03:07:46 +03:00
|
|
|
<div
|
2020-07-18 00:22:18 +03:00
|
|
|
className="mx_LeftPanel_filterContainer"
|
2020-07-05 03:07:46 +03:00
|
|
|
onFocus={this.onFocus}
|
|
|
|
onBlur={this.onBlur}
|
|
|
|
onKeyDown={this.onKeyDown}
|
|
|
|
>
|
2020-07-03 00:21:10 +03:00
|
|
|
<RoomSearch
|
|
|
|
isMinimized={this.props.isMinimized}
|
2021-03-28 09:28:48 +03:00
|
|
|
onKeyDown={this.onKeyDown}
|
|
|
|
onSelectRoom={this.selectRoom}
|
2020-07-03 00:21:10 +03:00
|
|
|
/>
|
2020-07-17 20:57:38 +03:00
|
|
|
<AccessibleTooltipButton
|
2021-03-24 22:43:33 +03:00
|
|
|
className={classNames("mx_LeftPanel_exploreButton", {
|
|
|
|
mx_LeftPanel_exploreButton_space: !!this.state.activeSpace,
|
|
|
|
})}
|
2020-06-09 05:33:21 +03:00
|
|
|
onClick={this.onExplore}
|
2020-07-05 03:07:46 +03:00
|
|
|
title={_t("Explore rooms")}
|
2020-06-09 05:33:21 +03:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-06-05 01:34:04 +03:00
|
|
|
public render(): React.ReactNode {
|
2021-02-26 13:23:09 +03:00
|
|
|
let leftLeftPanel;
|
2021-03-16 13:53:27 +03:00
|
|
|
if (this.state.showGroupFilterPanel) {
|
2021-02-26 13:23:09 +03:00
|
|
|
leftLeftPanel = (
|
|
|
|
<div className="mx_LeftPanel_GroupFilterPanelContainer">
|
|
|
|
<GroupFilterPanel />
|
|
|
|
{SettingsStore.getValue("feature_custom_tags") ? <CustomRoomTagPanel /> : null}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2020-06-03 04:26:07 +03:00
|
|
|
|
2020-07-18 00:27:49 +03:00
|
|
|
const roomList = <RoomList
|
2020-07-03 00:21:10 +03:00
|
|
|
onKeyDown={this.onKeyDown}
|
2021-05-03 19:32:33 +03:00
|
|
|
resizeNotifier={this.props.resizeNotifier}
|
2020-07-03 00:21:10 +03:00
|
|
|
onFocus={this.onFocus}
|
|
|
|
onBlur={this.onBlur}
|
2020-06-11 23:39:28 +03:00
|
|
|
isMinimized={this.props.isMinimized}
|
2021-03-24 22:43:09 +03:00
|
|
|
activeSpace={this.state.activeSpace}
|
2021-06-09 16:59:55 +03:00
|
|
|
onResize={this.refreshStickyHeaders}
|
2021-05-28 12:31:42 +03:00
|
|
|
onListCollapse={this.refreshStickyHeaders}
|
2020-06-03 04:26:07 +03:00
|
|
|
/>;
|
|
|
|
|
|
|
|
const containerClasses = classNames({
|
2020-07-18 00:22:18 +03:00
|
|
|
"mx_LeftPanel": true,
|
|
|
|
"mx_LeftPanel_minimized": this.props.isMinimized,
|
2020-06-03 04:26:07 +03:00
|
|
|
});
|
|
|
|
|
2020-07-01 17:15:18 +03:00
|
|
|
const roomListClasses = classNames(
|
2020-07-18 00:22:18 +03:00
|
|
|
"mx_LeftPanel_actualRoomListContainer",
|
2020-07-01 01:52:13 +03:00
|
|
|
"mx_AutoHideScrollbar",
|
|
|
|
);
|
|
|
|
|
2020-06-03 04:26:07 +03:00
|
|
|
return (
|
2021-05-27 14:36:16 +03:00
|
|
|
<div className={containerClasses} ref={this.ref}>
|
2021-02-26 13:23:09 +03:00
|
|
|
{leftLeftPanel}
|
2020-07-18 00:22:18 +03:00
|
|
|
<aside className="mx_LeftPanel_roomListContainer">
|
2020-06-05 01:34:04 +03:00
|
|
|
{this.renderHeader()}
|
2020-06-09 05:33:21 +03:00
|
|
|
{this.renderSearchExplore()}
|
2020-07-13 15:52:50 +03:00
|
|
|
{this.renderBreadcrumbs()}
|
2021-05-25 15:53:20 +03:00
|
|
|
<RoomListNumResults onVisibilityChange={this.refreshStickyHeaders} />
|
2020-07-18 00:22:18 +03:00
|
|
|
<div className="mx_LeftPanel_roomListWrapper">
|
2020-07-08 15:49:04 +03:00
|
|
|
<div
|
|
|
|
className={roomListClasses}
|
|
|
|
ref={this.listContainerRef}
|
|
|
|
// Firefox sometimes makes this element focusable due to
|
|
|
|
// overflow:scroll;, so force it out of tab order.
|
|
|
|
tabIndex={-1}
|
|
|
|
>
|
|
|
|
{roomList}
|
|
|
|
</div>
|
2020-07-03 00:21:10 +03:00
|
|
|
</div>
|
2021-05-25 11:50:09 +03:00
|
|
|
{ !this.props.isMinimized && <LeftPanelWidget /> }
|
2020-06-03 04:26:07 +03:00
|
|
|
</aside>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|