From b1b226d79bf15bf359cd53d827ac036b8b7fa85d Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Thu, 12 Sep 2024 09:32:24 +0200 Subject: [PATCH] Disable link and button while leaving --- src/home/CallList.module.css | 5 ++++ src/home/CallList.tsx | 53 +++++++++++++++++++++++++----------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/home/CallList.module.css b/src/home/CallList.module.css index 8e988d03..c7441b4a 100644 --- a/src/home/CallList.module.css +++ b/src/home/CallList.module.css @@ -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; +} diff --git a/src/home/CallList.tsx b/src/home/CallList.tsx index a136c086..de0e1f51 100644 --- a/src/home/CallList.tsx +++ b/src/home/CallList.tsx @@ -9,10 +9,11 @@ import { Link } from "react-router-dom"; 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, useCallback, MouseEvent } from "react"; +import { FC, useCallback, MouseEvent, useState } from "react"; import { t } from "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"; @@ -60,30 +61,50 @@ interface CallTileProps { const CallTile: FC = ({ name, avatarUrl, room, client }) => { const roomEncryptionSystem = useRoomEncryptionSystem(room.roomId); + const [isLeaving, setIsLeaving] = useState(false); + const onRemove = useCallback( (e: MouseEvent) => { e.stopPropagation(); e.preventDefault(); - void client.leave(room.roomId); + setIsLeaving(true); + client.leave(room.roomId).catch(() => setIsLeaving(false)); }, [room, client], ); + + const body = ( + <> + +
+ + {name} + +
+ + + + + ); + return (
- - -
- - {name} - -
- - - - + {isLeaving ? ( + + {body} + + ) : ( + + {body} + + )}
); };