2017-10-13 16:46:33 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2017 New Vector 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-08-14 10:36:04 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import { Room } from 'matrix-js-sdk/src';
|
|
|
|
|
import classNames from 'classnames';
|
2021-10-22 17:23:32 -05:00
|
|
|
|
2020-05-13 20:41:41 -06:00
|
|
|
import dis from '../../../dispatcher/dispatcher';
|
2021-11-25 17:49:43 -03:00
|
|
|
import { Action } from '../../../dispatcher/actions';
|
2017-10-13 16:46:33 +01:00
|
|
|
import { _t } from '../../../languageHandler';
|
2021-06-29 13:11:58 +01:00
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
2021-08-17 18:05:10 +01:00
|
|
|
import RoomDetailRow from "./RoomDetailRow";
|
2022-02-10 14:29:55 +00:00
|
|
|
import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
|
2017-10-13 16:46:33 +01:00
|
|
|
|
2021-08-14 10:36:04 +02:00
|
|
|
interface IProps {
|
|
|
|
|
rooms?: Room[];
|
|
|
|
|
className?: string;
|
|
|
|
|
}
|
2017-10-13 16:46:33 +01:00
|
|
|
|
2021-08-14 10:36:04 +02:00
|
|
|
@replaceableComponent("views.rooms.RoomDetailList")
|
|
|
|
|
export default class RoomDetailList extends React.Component<IProps> {
|
2021-08-26 08:02:36 +01:00
|
|
|
private getRows(): JSX.Element[] {
|
2021-08-25 09:34:16 +01:00
|
|
|
if (!this.props.rooms) return [];
|
2017-10-13 16:46:33 +01:00
|
|
|
return this.props.rooms.map((room, index) => {
|
2017-11-19 12:49:26 +00:00
|
|
|
return <RoomDetailRow key={index} room={room} onClick={this.onDetailsClick} />;
|
|
|
|
|
});
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
2017-11-19 12:49:26 +00:00
|
|
|
|
2021-08-26 08:02:36 +01:00
|
|
|
private onDetailsClick = (ev: React.MouseEvent, room: Room): void => {
|
2022-02-10 14:29:55 +00:00
|
|
|
dis.dispatch<ViewRoomPayload>({
|
2021-11-25 17:49:43 -03:00
|
|
|
action: Action.ViewRoom,
|
2017-11-19 12:49:26 +00:00
|
|
|
room_id: room.roomId,
|
2021-08-14 10:36:04 +02:00
|
|
|
room_alias: room.getCanonicalAlias() || (room.getAltAliases() || [])[0],
|
2022-02-17 18:03:27 +00:00
|
|
|
metricsTrigger: undefined, // Deprecated groups
|
2017-10-13 16:46:33 +01:00
|
|
|
});
|
2020-08-29 12:14:16 +01:00
|
|
|
};
|
2017-10-13 16:46:33 +01:00
|
|
|
|
2021-08-14 10:36:04 +02:00
|
|
|
public render(): JSX.Element {
|
2017-10-13 16:46:33 +01:00
|
|
|
const rows = this.getRows();
|
|
|
|
|
let rooms;
|
2017-11-19 12:49:26 +00:00
|
|
|
if (rows.length === 0) {
|
2017-10-13 16:46:33 +01:00
|
|
|
rooms = <i>{ _t('No rooms to show') }</i>;
|
|
|
|
|
} else {
|
2019-12-08 12:12:06 +00:00
|
|
|
rooms = <table className="mx_RoomDirectory_table">
|
2017-10-13 16:46:33 +01:00
|
|
|
<tbody>
|
|
|
|
|
{ this.getRows() }
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>;
|
|
|
|
|
}
|
2017-11-07 16:54:28 +00:00
|
|
|
return <div className={classNames("mx_RoomDetailList", this.props.className)}>
|
2017-10-13 16:46:33 +01:00
|
|
|
{ rooms }
|
|
|
|
|
</div>;
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
|
|
|
|
}
|