| 30 | |
| 31 | /** copies the page's Markdown, reporting the result for a moment after */ |
| 32 | export const useCopyMarkdown = (markdownUrl: string) => { |
| 33 | const [result, setResult] = useState<CopyResult>() |
| 34 | const timeout = useRef<ReturnType<typeof setTimeout>>(undefined) |
| 35 | |
| 36 | useEffect(() => () => clearTimeout(timeout.current), []) |
| 37 | |
| 38 | const copy = async () => { |
| 39 | const next = await writeMarkdown(markdownUrl).then( |
| 40 | () => "copied" as const, |
| 41 | () => "failed" as const |
| 42 | ) |
| 43 | setResult(next) |
| 44 | clearTimeout(timeout.current) |
| 45 | timeout.current = setTimeout(() => setResult(undefined), resultFor) |
| 46 | } |
| 47 | |
| 48 | return { result, copy } |
| 49 | } |
| 50 | |
| 51 | /** every state of "Copy page" in one grid cell, so the button never resizes */ |
| 52 | export const CopyFace = ({ result }: { result: CopyResult }) => ( |