diff --git a/app/src/tasks/TaskDetail/ClientConfig.tsx b/app/src/tasks/TaskDetail/ClientConfig.tsx index 9c652234..7438f495 100644 --- a/app/src/tasks/TaskDetail/ClientConfig.tsx +++ b/app/src/tasks/TaskDetail/ClientConfig.tsx @@ -83,7 +83,11 @@ await task.sendMeasurement(...); // your measurement here`; {(copy) => ( -
+
void, copied: boolean): React.ReactElement; + children(copy: undefined | (() => void), copied: boolean): React.ReactElement; clipboardContents: string; }) { - const [copied, setCopied] = React.useState(false); - const copy = React.useCallback(() => { - navigator.clipboard.writeText(clipboardContents).then(() => { - setCopied(true); - }); - }, [setCopied, clipboardContents]); + if ("clipboard" in navigator) { + const [copied, setCopied] = React.useState(false); + const copy = React.useCallback(() => { + navigator.clipboard.writeText(clipboardContents).then(() => { + setCopied(true); + }); + }, [setCopied, clipboardContents]); - return ( - {copied ? "Copied!" : "Click to copy"}} - > - {children(copy, copied)} - - ); + return ( + {copied ? "Copied!" : "Click to copy"}} + > + {children(copy, copied)} + + ); + } else { + return children(undefined, false); + } } export function CopyCode({ code }: { code: string }) { return ( - {(copy, copied) => ( - - {code}{" "} - - - )} + {(copy, copied) => + copy ? ( + + {code}{" "} + + + ) : ( + {code} + ) + } ); }