Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add button to remove call from recents #2618

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/home/CallList.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ Please see LICENSE in the repository root for full details.
justify-content: center;
margin-bottom: 24px;
}

.disabled {
cursor: not-allowed;
opacity: 0.8;
}
63 changes: 49 additions & 14 deletions src/home/CallList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
import { MatrixClient } from "matrix-js-sdk/src/client";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { Room } from "matrix-js-sdk/src/models/room";
import { FC } from "react";
import { FC, useCallback, MouseEvent, useState } from "react";
import { useTranslation } from "react-i18next";
import { IconButton } 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 styles from "./CallList.module.css";
Expand Down Expand Up @@ -55,22 +59,53 @@
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 [isLeaving, setIsLeaving] = useState(false);

const onRemove = useCallback(
(e: MouseEvent) => {
e.stopPropagation();
e.preventDefault();
setIsLeaving(true);
client.leave(room.roomId).catch(() => setIsLeaving(false));
},

Check warning on line 73 in src/home/CallList.tsx

View check run for this annotation

Codecov / codecov/patch

src/home/CallList.tsx#L69-L73

Added lines #L69 - L73 were not covered by tests
[room, client],
);

const body = (
<>
<Avatar id={room.roomId} name={name} size={Size.LG} src={avatarUrl} />
<div className={styles.callInfo}>
<Body overflowEllipsis fontWeight="semiBold">
{name}
</Body>
</div>
<IconButton
onClick={onRemove}
disabled={isLeaving}
aria-label={t("action.remove")}
>
<CloseIcon />
</IconButton>
</>
);

return (
<div className={styles.callTile}>
<Link
to={getRelativeRoomUrl(room.roomId, roomEncryptionSystem, room.name)}
className={styles.callTileLink}
>
<Avatar id={room.roomId} name={name} size={Size.LG} src={avatarUrl} />
<div className={styles.callInfo}>
<Body overflowEllipsis fontWeight="semiBold">
{name}
</Body>
</div>
<div className={styles.copyButtonSpacer} />
</Link>
{isLeaving ? (
<span className={classNames(styles.callTileLink, styles.disabled)}>
{body}
</span>

Check warning on line 100 in src/home/CallList.tsx

View check run for this annotation

Codecov / codecov/patch

src/home/CallList.tsx#L98-L100

Added lines #L98 - L100 were not covered by tests
) : (
<Link
to={getRelativeRoomUrl(room.roomId, roomEncryptionSystem, room.name)}
className={styles.callTileLink}
>
{body}
</Link>
)}
</div>
);
};