@@ -7,10 +7,11 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
7
7
Please see LICENSE files in the repository root for full details.
8
8
*/
9
9
10
- import React , { JSX , useMemo , useState } from "react" ;
10
+ import React , { JSX , useMemo , useRef , useState } from "react" ;
11
11
import { Room , RoomMember , MatrixEvent , User } from "matrix-js-sdk/src/matrix" ;
12
12
import { Checkbox , Button } from "@vector-im/compound-web" ;
13
13
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" ;
14
15
15
16
import { _t } from "../../../languageHandler" ;
16
17
import QRCode from "../elements/QRCode" ;
@@ -102,6 +103,9 @@ export function ShareDialog({ target, customTitle, onFinished, permalinkCreator
102
103
const showQrCode = useSettingValue < boolean > ( UIFeature . ShareQRCode ) ;
103
104
const showSocials = useSettingValue < boolean > ( UIFeature . ShareSocial ) ;
104
105
106
+ const timeoutIdRef = useRef < number > ( ) ;
107
+ const [ isCopied , setIsCopied ] = useState ( false ) ;
108
+
105
109
const [ linkToSpecificEvent , setLinkToSpecificEvent ] = useState ( target instanceof MatrixEvent ) ;
106
110
const { title, url, checkboxLabel } = useTargetValues ( target , linkToSpecificEvent , permalinkCreator ) ;
107
111
const newTitle = customTitle ?? title ;
@@ -129,13 +133,15 @@ export function ShareDialog({ target, customTitle, onFinished, permalinkCreator
129
133
</ label >
130
134
) }
131
135
< Button
132
- Icon = { LinkIcon }
136
+ Icon = { isCopied ? CheckIcon : LinkIcon }
133
137
onClick = { async ( ) => {
138
+ clearTimeout ( timeoutIdRef . current ) ;
134
139
await copyPlaintext ( url ) ;
135
- onFinished ( ) ;
140
+ setIsCopied ( true ) ;
141
+ timeoutIdRef . current = setTimeout ( ( ) => setIsCopied ( false ) , 2000 ) ;
136
142
} }
137
143
>
138
- { _t ( "action|copy_link" ) }
144
+ { isCopied ? _t ( "share|link_copied" ) : _t ( "action|copy_link" ) }
139
145
</ Button >
140
146
{ showSocials && < SocialLinks url = { url } /> }
141
147
</ div >
0 commit comments