Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions src/components/common/CreatorProfileHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,37 @@ const CreatorProfileHeader: React.FC<CreatorProfileHeaderProps> = ({
}) => {
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 (
<div
className={cn(
Expand All @@ -59,28 +78,23 @@ const CreatorProfileHeader: React.FC<CreatorProfileHeaderProps> = ({

<div className="flex items-center gap-3">
<Button
onClick={handleCopy}
onClick={handleShare}
variant="outline"
className="h-11 rounded-xl border-white/10 bg-white/5 px-4 font-bold text-white transition-all hover:border-amber-500/30 hover:bg-amber-500/10 active:scale-95"
>
{copied ? (
<Check className="mr-2 size-4 text-emerald-400" />
) : canNativeShare ? (
<Share2 className="mr-2 size-4 text-amber-500" />
) : (
<Copy className="mr-2 size-4 text-amber-500" />
)}
<span className="hidden sm:inline">
{copied ? 'Copied!' : 'Copy Profile Link'}
{copied ? 'Copied!' : canNativeShare ? 'Share Profile' : 'Copy Profile Link'}
</span>
<span className="sm:hidden">
{copied ? 'Copied' : canNativeShare ? 'Share' : 'Copy'}
</span>
<span className="sm:hidden">{copied ? 'Copied' : 'Copy'}</span>
</Button>
<Button
variant="outline"
size="icon"
className="h-11 w-11 rounded-xl border-white/10 bg-white/5 text-white transition-all hover:border-amber-500/30 hover:bg-amber-500/10 md:hidden active:scale-95"
onClick={handleCopy}
aria-label="Share profile"
>
<Share2 className="size-4" />
</Button>
</div>
</div>
Expand Down
Loading