Skip to content

Commit

Permalink
Change button text when clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
florianduros committed Dec 2, 2024
1 parent 76def43 commit 60b709f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/components/views/dialogs/ShareDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
Please see LICENSE files in the repository root for full details.
*/

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

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

const timeoutIdRef = useRef<number>();
const [isCopied, setIsCopied] = useState(false);

const [linkToSpecificEvent, setLinkToSpecificEvent] = useState(target instanceof MatrixEvent);
const { title, url, checkboxLabel } = useTargetValues(target, linkToSpecificEvent, permalinkCreator);
const newTitle = customTitle ?? title;
Expand Down Expand Up @@ -129,13 +133,15 @@ export function ShareDialog({ target, customTitle, onFinished, permalinkCreator
</label>
)}
<Button
Icon={LinkIcon}
Icon={isCopied ? CheckIcon : LinkIcon}
onClick={async () => {
clearTimeout(timeoutIdRef.current);
await copyPlaintext(url);
onFinished();
setIsCopied(true);
timeoutIdRef.current = setTimeout(() => setIsCopied(false), 2000);
}}
>
{_t("action|copy_link")}
{isCopied ? _t("share|link_copied") : _t("action|copy_link")}
</Button>
{showSocials && <SocialLinks url={url} />}
</div>
Expand Down
1 change: 1 addition & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2952,6 +2952,7 @@
"warning": "<w>WARNING:</w> <description/>"
},
"share": {
"link_copied": "Link copied",
"permalink_message": "Link to selected message",
"permalink_most_recent": "Link to most recent message",
"share_call": "Conference invite link",
Expand Down

0 comments on commit 60b709f

Please sign in to comment.