From acf419926dc217ba7ac7383ab8e2767acd200154 Mon Sep 17 00:00:00 2001
From: Brendan F <EpicWolverine@users.noreply.github.com>
Date: Mon, 26 Jun 2023 21:48:13 -0700
Subject: Open share menu if available

---
 src/components/Result/index.tsx | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

(limited to 'src/components/Result/index.tsx')

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 (
-- 
cgit v1.2.3

