Iterate EntityTile

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
pull/21833/head
Šimon Brandner 2021-06-24 14:29:24 +02:00
parent e25940cbdd
commit 298e505381
No known key found for this signature in database
GPG Key ID: 9760693FDD98A790
1 changed files with 10 additions and 9 deletions

View File

@ -16,7 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import React, { createRef } from 'react'; import React from 'react';
import AccessibleButton from '../elements/AccessibleButton'; import AccessibleButton from '../elements/AccessibleButton';
import { _td } from '../../../languageHandler'; import { _td } from '../../../languageHandler';
import classNames from "classnames"; import classNames from "classnames";
@ -25,7 +25,12 @@ import { replaceableComponent } from "../../../utils/replaceableComponent";
import BaseAvatar from '../avatars/BaseAvatar'; import BaseAvatar from '../avatars/BaseAvatar';
import PresenceLabel from "./PresenceLabel"; import PresenceLabel from "./PresenceLabel";
const PowerLabel: Record<string, string> = { enum PowerStatus {
Admin = "admin",
Moderator = "moderator",
}
const PowerLabel: Record<PowerStatus, string> = {
"admin": _td("Admin"), "admin": _td("Admin"),
"moderator": _td("Mod"), "moderator": _td("Mod"),
} }
@ -36,7 +41,7 @@ const PRESENCE_CLASS = {
"unavailable": "mx_EntityTile_unavailable", "unavailable": "mx_EntityTile_unavailable",
}; };
function presenceClassForMember(presenceState: string, lastActiveAgo: number, showPresence: boolean) { function presenceClassForMember(presenceState: string, lastActiveAgo: number, showPresence: boolean): string {
if (showPresence === false) { if (showPresence === false) {
return 'mx_EntityTile_online_beenactive'; return 'mx_EntityTile_online_beenactive';
} }
@ -66,13 +71,12 @@ interface IProps {
presenceLastTs?: number, presenceLastTs?: number,
presenceCurrentlyActive?: boolean, presenceCurrentlyActive?: boolean,
showInviteButton?: boolean, showInviteButton?: boolean,
shouldComponentUpdate?(nextProps: IProps, nextState: IState): boolean,
onClick?(): void, onClick?(): void,
suppressOnHover?: boolean, suppressOnHover?: boolean,
showPresence?: boolean, showPresence?: boolean,
subtextLabel?: string, subtextLabel?: string,
e2eStatus?: string, e2eStatus?: string,
powerStatus?: string, powerStatus?: PowerStatus,
} }
interface IState { interface IState {
@ -82,7 +86,6 @@ interface IState {
@replaceableComponent("views.rooms.EntityTile") @replaceableComponent("views.rooms.EntityTile")
export default class EntityTile extends React.Component<IProps, IState> { export default class EntityTile extends React.Component<IProps, IState> {
static defaultProps = { static defaultProps = {
shouldComponentUpdate: (nextProps: IProps, nextState: IState) => { return true; },
onClick: () => {}, onClick: () => {},
presenceState: "offline", presenceState: "offline",
presenceLastActiveAgo: 0, presenceLastActiveAgo: 0,
@ -91,7 +94,6 @@ export default class EntityTile extends React.Component<IProps, IState> {
suppressOnHover: false, suppressOnHover: false,
showPresence: true, showPresence: true,
}; };
private container = createRef<HTMLDivElement>();
constructor(props: IProps) { constructor(props: IProps) {
super(props); super(props);
@ -103,7 +105,6 @@ export default class EntityTile extends React.Component<IProps, IState> {
shouldComponentUpdate(nextProps: IProps, nextState: IState) { shouldComponentUpdate(nextProps: IProps, nextState: IState) {
if (this.state.hover !== nextState.hover) return true; if (this.state.hover !== nextState.hover) return true;
return this.props.shouldComponentUpdate(nextProps, nextState);
} }
render() { render() {
@ -184,7 +185,7 @@ export default class EntityTile extends React.Component<IProps, IState> {
// The wrapping div is required to make the magic mouse listener work, for some reason. // The wrapping div is required to make the magic mouse listener work, for some reason.
return ( return (
<div ref={this.container} > <div>
<AccessibleButton <AccessibleButton
className={classNames(mainClassNames)} className={classNames(mainClassNames)}
title={this.props.title} title={this.props.title}