Merge pull request #2618 from Johennes/johannes/remove-call

Add button to remove call from recents
This commit is contained in:
fkwp 2024-09-13 13:24:05 +02:00 committed by GitHub
commit eb6719d32e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 54 additions and 15 deletions

View File

@ -70,3 +70,8 @@ Please see LICENSE in the repository root for full details.
justify-content: center; justify-content: center;
margin-bottom: 24px; margin-bottom: 24px;
} }
.disabled {
cursor: not-allowed;
opacity: 0.8;
}

View File

@ -9,8 +9,11 @@ import { Link } from "react-router-dom";
import { MatrixClient } from "matrix-js-sdk/src/client"; import { MatrixClient } from "matrix-js-sdk/src/client";
import { RoomMember } from "matrix-js-sdk/src/models/room-member"; import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { Room } from "matrix-js-sdk/src/models/room"; import { Room } from "matrix-js-sdk/src/models/room";
import { FC } from "react"; import { FC, useCallback, MouseEvent, useState } from "react";
import { Text } from "@vector-im/compound-web"; import { useTranslation } from "react-i18next";
import { IconButton, Text } from "@vector-im/compound-web";
import { CloseIcon } from "@vector-im/compound-design-tokens/assets/web/icons";
import classNames from "classnames";
import { Avatar, Size } from "../Avatar"; import { Avatar, Size } from "../Avatar";
import styles from "./CallList.module.css"; import styles from "./CallList.module.css";
@ -55,22 +58,53 @@ interface CallTileProps {
client: MatrixClient; client: MatrixClient;
} }
const CallTile: FC<CallTileProps> = ({ name, avatarUrl, room }) => { const CallTile: FC<CallTileProps> = ({ name, avatarUrl, room, client }) => {
const { t } = useTranslation();
const roomEncryptionSystem = useRoomEncryptionSystem(room.roomId); const roomEncryptionSystem = useRoomEncryptionSystem(room.roomId);
return ( const [isLeaving, setIsLeaving] = useState(false);
<div className={styles.callTile}>
<Link const onRemove = useCallback(
to={getRelativeRoomUrl(room.roomId, roomEncryptionSystem, room.name)} (e: MouseEvent) => {
className={styles.callTileLink} e.stopPropagation();
> e.preventDefault();
setIsLeaving(true);
client.leave(room.roomId).catch(() => setIsLeaving(false));
},
[room, client],
);
const body = (
<>
<Avatar id={room.roomId} name={name} size={Size.LG} src={avatarUrl} /> <Avatar id={room.roomId} name={name} size={Size.LG} src={avatarUrl} />
<div className={styles.callInfo}> <div className={styles.callInfo}>
<Text weight="semibold" className={styles.callName}> <Text weight="semibold" className={styles.callName}>
{name} {name}
</Text> </Text>
</div> </div>
<div className={styles.copyButtonSpacer} /> <IconButton
onClick={onRemove}
disabled={isLeaving}
aria-label={t("action.remove")}
>
<CloseIcon />
</IconButton>
</>
);
return (
<div className={styles.callTile}>
{isLeaving ? (
<span className={classNames(styles.callTileLink, styles.disabled)}>
{body}
</span>
) : (
<Link
to={getRelativeRoomUrl(room.roomId, roomEncryptionSystem, room.name)}
className={styles.callTileLink}
>
{body}
</Link> </Link>
)}
</div> </div>
); );
}; };