()
| 11 | ); |
| 12 | |
| 13 | export function Share() { |
| 14 | useEffect(() => { |
| 15 | setLink(window.location.href); |
| 16 | }, []); |
| 17 | const [link, setLink] = useState(""); |
| 18 | |
| 19 | const [copyText, setCopyText] = useState<React.ReactNode>(buttonDefault); |
| 20 | |
| 21 | const [copied, setCopied] = useState(false); |
| 22 | |
| 23 | useEffect(() => { |
| 24 | if (copied) { |
| 25 | const timeout = setTimeout(() => { |
| 26 | setCopyText(buttonDefault); |
| 27 | setCopied(false); |
| 28 | }, 1800); |
| 29 | |
| 30 | return () => clearTimeout(timeout); |
| 31 | } |
| 32 | }, [copied]); |
| 33 | |
| 34 | const handleCopy = useCallback(() => { |
| 35 | navigator.clipboard.writeText(link).then( |
| 36 | function () { |
| 37 | setCopyText(<span>Copied!</span>); |
| 38 | setCopied(true); |
| 39 | }, |
| 40 | function (err) { |
| 41 | setCopyText(<span>Failed to copy</span>); |
| 42 | setCopied(true); |
| 43 | } |
| 44 | ); |
| 45 | }, [link, setCopyText]); |
| 46 | |
| 47 | const { selectedNodeId } = useJsonColumnViewState(); |
| 48 | |
| 49 | const handleIncludesPath = useCallback( |
| 50 | (includesPath: boolean) => { |
| 51 | if (!selectedNodeId) { |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | if (includesPath) { |
| 56 | const url = new URL(window.location.href); |
| 57 | for (const [key] of url.searchParams) { |
| 58 | url.searchParams.delete(key); |
| 59 | } |
| 60 | |
| 61 | url.searchParams.append("path", selectedNodeId); |
| 62 | |
| 63 | setLink(url.href); |
| 64 | } else { |
| 65 | setLink(window.location.href); |
| 66 | } |
| 67 | }, |
| 68 | [link, selectedNodeId] |
| 69 | ); |
| 70 |
nothing calls this directly
no test coverage detected