Skip to content

Commit 60b709f

Browse files
committed
Change button text when clicked
1 parent 76def43 commit 60b709f

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/components/views/dialogs/ShareDialog.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
77
Please see LICENSE files in the repository root for full details.
88
*/
99

10-
import React, { JSX, useMemo, useState } from "react";
10+
import React, { JSX, useMemo, useRef, useState } from "react";
1111
import { Room, RoomMember, MatrixEvent, User } from "matrix-js-sdk/src/matrix";
1212
import { Checkbox, Button } from "@vector-im/compound-web";
1313
import LinkIcon from "@vector-im/compound-design-tokens/assets/web/icons/link";
14+
import CheckIcon from "@vector-im/compound-design-tokens/assets/web/icons/check";
1415

1516
import { _t } from "../../../languageHandler";
1617
import QRCode from "../elements/QRCode";
@@ -102,6 +103,9 @@ export function ShareDialog({ target, customTitle, onFinished, permalinkCreator
102103
const showQrCode = useSettingValue<boolean>(UIFeature.ShareQRCode);
103104
const showSocials = useSettingValue<boolean>(UIFeature.ShareSocial);
104105

106+
const timeoutIdRef = useRef<number>();
107+
const [isCopied, setIsCopied] = useState(false);
108+
105109
const [linkToSpecificEvent, setLinkToSpecificEvent] = useState(target instanceof MatrixEvent);
106110
const { title, url, checkboxLabel } = useTargetValues(target, linkToSpecificEvent, permalinkCreator);
107111
const newTitle = customTitle ?? title;
@@ -129,13 +133,15 @@ export function ShareDialog({ target, customTitle, onFinished, permalinkCreator
129133
</label>
130134
)}
131135
<Button
132-
Icon={LinkIcon}
136+
Icon={isCopied ? CheckIcon : LinkIcon}
133137
onClick={async () => {
138+
clearTimeout(timeoutIdRef.current);
134139
await copyPlaintext(url);
135-
onFinished();
140+
setIsCopied(true);
141+
timeoutIdRef.current = setTimeout(() => setIsCopied(false), 2000);
136142
}}
137143
>
138-
{_t("action|copy_link")}
144+
{isCopied ? _t("share|link_copied") : _t("action|copy_link")}
139145
</Button>
140146
{showSocials && <SocialLinks url={url} />}
141147
</div>

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2952,6 +2952,7 @@
29522952
"warning": "<w>WARNING:</w> <description/>"
29532953
},
29542954
"share": {
2955+
"link_copied": "Link copied",
29552956
"permalink_message": "Link to selected message",
29562957
"permalink_most_recent": "Link to most recent message",
29572958
"share_call": "Conference invite link",

0 commit comments

Comments
 (0)