Skip to content

Commit e042842

Browse files
committed
fix(useShareActions): add use client, fix native fallback error state, restore share payload
1 parent 2e44fd0 commit e042842

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

hooks/useShareActions.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
'use client';
12
import { useState, useRef, useEffect } from 'react';
23
import { toPng } from 'html-to-image';
34
import type { DashboardExportData } from '@/types/dashboard';
@@ -35,14 +36,16 @@ export function useShareActions(
3536
};
3637
}, []);
3738

38-
const handleCopyLink = async () => {
39+
const handleCopyLink = async (): Promise<boolean> => {
3940
setOptionState('copy', 'loading');
4041
try {
4142
await navigator.clipboard.writeText(PROFILE_URL(username));
4243
setOptionState('copy', 'success');
4344
setTimeout(() => onClose(), 800);
45+
return true;
4446
} catch {
4547
setOptionState('copy', 'error');
48+
return false;
4649
}
4750
};
4851

@@ -158,18 +161,19 @@ export function useShareActions(
158161
const handleNativeShare = async () => {
159162
if (!('share' in navigator)) {
160163
setOptionState('native', 'loading');
161-
await handleCopyLink();
162-
setOptionState('native', 'success');
164+
const success = await handleCopyLink();
165+
setOptionState('native', success ? 'success' : 'error');
163166
return;
164167
}
165168
setOptionState('native', 'loading');
166169
try {
167170
await navigator.share({
168171
title: `${username}'s Commit Pulse`,
172+
text: `Check out my GitHub commit pulse on CommitPulse 🚀`,
169173
url: PROFILE_URL(username),
170174
});
171175
setOptionState('native', 'success');
172-
onClose();
176+
setTimeout(() => onClose(), 800);
173177
} catch (err) {
174178
if (err instanceof Error && err.name !== 'AbortError') {
175179
setOptionState('native', 'error');

0 commit comments

Comments
 (0)