diff options
| author | Brendan F <EpicWolverine@users.noreply.github.com> | 2023-06-26 21:48:13 -0700 |
|---|---|---|
| committer | Brendan F <EpicWolverine@users.noreply.github.com> | 2023-06-26 21:48:13 -0700 |
| commit | acf419926dc217ba7ac7383ab8e2767acd200154 (patch) | |
| tree | 83fde6f489e0cce1cd720a9e21f8d69efead3207 /src | |
| parent | b2311ae21a10e4fc5a3d8f9bc7fe900c44b22084 (diff) | |
Open share menu if available
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/Result/index.tsx | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/components/Result/index.tsx b/src/components/Result/index.tsx index 9eb6d27..68636d8 100644 --- a/src/components/Result/index.tsx +++ b/src/components/Result/index.tsx @@ -45,11 +45,17 @@ function ShareButton({ guesses, variant }:ShareButtonProps) { - const [buttonText, setButtonText] = useState('Copy Results'); - + const result = scoreToEmoji(guesses); + const [buttonText, setButtonText] = useState('Share Results'); const handleClick = React.useCallback(() => { - navigator.clipboard.writeText(scoreToEmoji(guesses)); - setButtonText('Copied!'); + if (navigator.share !== undefined) { + navigator.share({text: result}) + } else if (navigator.clipboard !== undefined) { + navigator.clipboard.writeText(result) + setButtonText('Copied!'); + } else { + setButtonText('Failed to open share menu or copy'); + } }, [guesses]); return ( |
