11import { FunctionalComponent } from "preact" ;
22import { useAtomValue } from "jotai" ;
33import { chainThemeAtom , ChainTheme } from "../../states/atoms" ;
4+ import { useState } from "preact/hooks" ;
45
56export interface ReplayHeaderProp {
67 blockHash : string ;
@@ -13,6 +14,29 @@ export const ReplayHeader: FunctionalComponent<ReplayHeaderProp> = ({
1314 chainTheme === ChainTheme . mainnet
1415 ? "text-brand-mainnet"
1516 : "text-brand-testnet" ;
17+ const [ copyNotification , setCopyNotification ] = useState < string | null > (
18+ null ,
19+ ) ;
20+
21+ const handleCopyClick = ( ) => {
22+ const link = `${ window . location . origin } /replay/${ blockHash } ` ;
23+ navigator . clipboard
24+ . writeText ( link )
25+ . then ( ( ) => {
26+ setCopyNotification ( "Link copied!" ) ;
27+ setTimeout ( ( ) => {
28+ setCopyNotification ( null ) ;
29+ } , 2000 ) ; // Clear notification after 2 seconds
30+ } )
31+ . catch ( ( err ) => {
32+ console . error ( "Failed to copy: " , err ) ;
33+ setCopyNotification ( "Failed to copy link." ) ; //Optional, error message.
34+ setTimeout ( ( ) => {
35+ setCopyNotification ( null ) ;
36+ } , 2000 ) ;
37+ } ) ;
38+ } ;
39+
1640 return (
1741 < div >
1842 < div
@@ -22,14 +46,17 @@ export const ReplayHeader: FunctionalComponent<ReplayHeaderProp> = ({
2246 >
2347 < h1 > Elevator Block Replay </ h1 >
2448 < div >
25- < a
26- className = { `${ textColor } ` }
27- href = "http://"
28- target = "_blank"
29- rel = "noopener noreferrer"
49+ < button
50+ className = { `${ textColor } border border-black rounded-md px-4 py-2` }
51+ onClick = { handleCopyClick }
3052 >
31- Copy the Share Link
32- </ a >
53+ Share this block with your friends!
54+ </ button >
55+ { copyNotification && (
56+ < div className = "text-text-secondary text-sm italic" >
57+ { copyNotification }
58+ </ div >
59+ ) }
3360 </ div >
3461 </ div >
3562 </ div >
0 commit comments