From 254819b129a30fdb4fade56556ffec07063c71d1 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 14 Dec 2021 12:16:49 +0000 Subject: [PATCH] Debounce User Info start dm "Message" button --- src/components/views/right_panel/UserInfo.tsx | 32 ++++++++++++++----- src/i18n/strings/en_EN.json | 2 +- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/components/views/right_panel/UserInfo.tsx b/src/components/views/right_panel/UserInfo.tsx index e36ce74ae77..74f0bccb5d9 100644 --- a/src/components/views/right_panel/UserInfo.tsx +++ b/src/components/views/right_panel/UserInfo.tsx @@ -120,7 +120,7 @@ export const getE2EStatus = (cli: MatrixClient, userId: string, devices: IDevice return anyDeviceUnverified ? E2EStatus.Warning : E2EStatus.Verified; }; -async function openDMForUser(matrixClient: MatrixClient, userId: string) { +async function openDMForUser(matrixClient: MatrixClient, userId: string): Promise { const lastActiveRoom = findDMForUser(matrixClient, userId); if (lastActiveRoom) { @@ -149,7 +149,7 @@ async function openDMForUser(matrixClient: MatrixClient, userId: string) { } } - return createRoom(createRoomOptions); + await createRoom(createRoomOptions); } type SetUpdating = (updating: boolean) => void; @@ -318,6 +318,26 @@ function DevicesSection({ devices, userId, loading }: {devices: IDevice[], userI ); } +const MessageButton = ({ userId }: { userId: string }) => { + const cli = useContext(MatrixClientContext); + const [busy, setBusy] = useState(false); + + return ( + { + if (busy) return; + setBusy(true); + await openDMForUser(cli, userId); + setBusy(false); + }} + className="mx_UserInfo_field" + disabled={busy} + > + { _t("Message") } + + ); +}; + const UserOptionsSection: React.FC<{ member: RoomMember; isIgnored: boolean; @@ -432,13 +452,9 @@ const UserOptionsSection: React.FC<{ ); - let directMessageButton; + let directMessageButton: JSX.Element; if (!isMe) { - directMessageButton = ( - { openDMForUser(cli, member.userId); }} className="mx_UserInfo_field"> - { _t("Message") } - - ); + directMessageButton = ; } return ( diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 72dd21e9b26..36a061706ed 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1927,10 +1927,10 @@ "%(count)s sessions|other": "%(count)s sessions", "%(count)s sessions|one": "%(count)s session", "Hide sessions": "Hide sessions", + "Message": "Message", "Jump to read receipt": "Jump to read receipt", "Mention": "Mention", "Share Link to User": "Share Link to User", - "Message": "Message", "Demote yourself?": "Demote yourself?", "You will not be able to undo this change as you are demoting yourself, if you are the last privileged user in the space it will be impossible to regain privileges.": "You will not be able to undo this change as you are demoting yourself, if you are the last privileged user in the space it will be impossible to regain privileges.", "You will not be able to undo this change as you are demoting yourself, if you are the last privileged user in the room it will be impossible to regain privileges.": "You will not be able to undo this change as you are demoting yourself, if you are the last privileged user in the room it will be impossible to regain privileges.",