|
| 1 | +'use client'; |
1 | 2 | import { useState, useRef, useEffect } from 'react'; |
2 | 3 | import { toPng } from 'html-to-image'; |
3 | 4 | import type { DashboardExportData } from '@/types/dashboard'; |
@@ -35,14 +36,16 @@ export function useShareActions( |
35 | 36 | }; |
36 | 37 | }, []); |
37 | 38 |
|
38 | | - const handleCopyLink = async () => { |
| 39 | + const handleCopyLink = async (): Promise<boolean> => { |
39 | 40 | setOptionState('copy', 'loading'); |
40 | 41 | try { |
41 | 42 | await navigator.clipboard.writeText(PROFILE_URL(username)); |
42 | 43 | setOptionState('copy', 'success'); |
43 | 44 | setTimeout(() => onClose(), 800); |
| 45 | + return true; |
44 | 46 | } catch { |
45 | 47 | setOptionState('copy', 'error'); |
| 48 | + return false; |
46 | 49 | } |
47 | 50 | }; |
48 | 51 |
|
@@ -158,18 +161,19 @@ export function useShareActions( |
158 | 161 | const handleNativeShare = async () => { |
159 | 162 | if (!('share' in navigator)) { |
160 | 163 | setOptionState('native', 'loading'); |
161 | | - await handleCopyLink(); |
162 | | - setOptionState('native', 'success'); |
| 164 | + const success = await handleCopyLink(); |
| 165 | + setOptionState('native', success ? 'success' : 'error'); |
163 | 166 | return; |
164 | 167 | } |
165 | 168 | setOptionState('native', 'loading'); |
166 | 169 | try { |
167 | 170 | await navigator.share({ |
168 | 171 | title: `${username}'s Commit Pulse`, |
| 172 | + text: `Check out my GitHub commit pulse on CommitPulse 🚀`, |
169 | 173 | url: PROFILE_URL(username), |
170 | 174 | }); |
171 | 175 | setOptionState('native', 'success'); |
172 | | - onClose(); |
| 176 | + setTimeout(() => onClose(), 800); |
173 | 177 | } catch (err) { |
174 | 178 | if (err instanceof Error && err.name !== 'AbortError') { |
175 | 179 | setOptionState('native', 'error'); |
|
0 commit comments