From f10941e30aa90ed387b638554ec5f3ed4fef4b81 Mon Sep 17 00:00:00 2001 From: victorEdeh Date: Sat, 25 Apr 2026 10:40:47 -0700 Subject: [PATCH] feat: add creator profile share action with Web Share API fallback (#115) - Replace copy-only button with unified share action - Use navigator.share() when available (mobile/supported browsers) - Fall back to navigator.clipboard.writeText() on unsupported environments - Silently swallow AbortError when user dismisses native share sheet - Show success toast on clipboard copy, error toast on failure - Adapt button label and icon based on Web Share API availability - Remove redundant mobile-only icon button --- .../common/CreatorProfileHeader.tsx | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/components/common/CreatorProfileHeader.tsx b/src/components/common/CreatorProfileHeader.tsx index 21d93255..045a0362 100644 --- a/src/components/common/CreatorProfileHeader.tsx +++ b/src/components/common/CreatorProfileHeader.tsx @@ -23,18 +23,37 @@ const CreatorProfileHeader: React.FC = ({ }) => { const [copied, setCopied] = useState(false); - const handleCopy = async () => { + const handleShare = async () => { + const url = window.location.href; + + if (navigator.share) { + try { + await navigator.share({ + title: `${name} (@${handle}) on Access Layer`, + url, + }); + } catch (err) { + // User cancelled the share dialog — not an error worth surfacing + if (err instanceof Error && err.name !== 'AbortError') { + showToast.error('Failed to share profile'); + } + } + return; + } + + // Fallback: copy to clipboard try { - await navigator.clipboard.writeText(window.location.href); + await navigator.clipboard.writeText(url); setCopied(true); showToast.success('Profile link copied to clipboard!'); setTimeout(() => setCopied(false), 2000); - } catch (err) { - console.error('Failed to copy profile link:', err); + } catch { showToast.error('Failed to copy link'); } }; + const canNativeShare = typeof navigator !== 'undefined' && !!navigator.share; + return (
= ({
-