@@ -15,6 +15,7 @@ interface MarkdownMenuProps {
1515export function MarkdownMenu ( { url} : MarkdownMenuProps ) {
1616 let mdUrl = ( url ?? '' ) . replace ( / \. h t m l ? $ / i, '' ) + '.md' ;
1717 let [ isCopied , setIsCopied ] = useState ( false ) ;
18+ let [ isPending , setPending ] = useState ( false ) ;
1819 let timeout = useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
1920
2021 let pageUrl = typeof window !== 'undefined' && url ? new URL ( url , window . location . origin ) . href : url ?? '' ;
@@ -38,20 +39,25 @@ export function MarkdownMenu({url}: MarkdownMenuProps) {
3839 }
3940 if ( typeof navigator !== 'undefined' && navigator . clipboard ) {
4041 try {
41- let response = await fetch ( mdUrl ) ;
42- let markdown = await response . text ( ) ;
43- await navigator . clipboard . writeText ( markdown ) ;
42+ setPending ( true ) ;
43+ await navigator . clipboard . write ( [
44+ new ClipboardItem ( {
45+ [ 'text/plain' ] : fetch ( mdUrl ) . then ( res => res . text ( ) )
46+ } )
47+ ] ) ;
4448 setIsCopied ( true ) ;
4549 timeout . current = setTimeout ( ( ) => setIsCopied ( false ) , 2000 ) ;
4650 } catch {
4751 ToastQueue . negative ( 'Failed to copy markdown.' ) ;
52+ } finally {
53+ setPending ( false ) ;
4854 }
4955 }
5056 } , [ mdUrl ] ) ;
5157
5258 return (
5359 < div className = { style ( { display : 'flex' , justifyContent : 'space-between' , paddingX : 4 , paddingBottom : 16 } ) } >
54- < ActionButton isQuiet size = "M" onPress = { handleCopy } >
60+ < ActionButton isQuiet size = "M" onPress = { handleCopy } isPending = { isPending } >
5561 { isCopied ? < CheckmarkCircle /> : < Copy /> }
5662 < Text > Copy for LLM</ Text >
5763 </ ActionButton >
0 commit comments