(null);
@@ -327,8 +331,7 @@ export default function CommitDialog({
setError(null);
setReported(null);
if (wasSuccess) lastAttempt.current = null;
- setShareCopied(false);
- setCopyResult(null);
+ setCopyFailed(false);
if (wasSuccess) router.refresh();
}
@@ -374,32 +377,20 @@ export default function CommitDialog({
// user cancelled or share failed; fall through to copy
}
}
- try {
- await navigator.clipboard.writeText(success.editUrl);
- setShareCopied(true);
- setTimeout(() => setShareCopied(false), 2000);
- } catch {
- // last resort: do nothing — link is already on screen
- }
+ // last resort: if the clipboard refuses, do nothing — the link is on screen
+ await linkCopy.copy(success.editUrl);
}
// Someone without an email gets Copy link, not Save your link: the link is how
// they change or cancel, and a share sheet invites them to post it.
async function handleCopy() {
if (!success) return;
- try {
- await navigator.clipboard.writeText(success.editUrl);
- setCopyResult('copied');
- // Back to Copy link, as Save your link does, unless a failure replaced it.
- setTimeout(() => setCopyResult((r) => (r === 'copied' ? null : r)), 2000);
- } catch {
- // No clipboard over plain HTTP, or the browser refused.
- setCopyResult('failed');
- }
+ // No clipboard over plain HTTP, or the browser refused: say so in the region.
+ setCopyFailed(!(await linkCopy.copy(success.editUrl)));
}
// Save your link and Copy link each say "Link copied" on themselves after a copy.
- const linkCopied = success?.emailed ? shareCopied : copyResult === 'copied';
+ const linkCopied = linkCopy.copied && !copyFailed;
// The trigger's name and the sheet's: every row's button reads "Sign up".
const signUpFor = t('signUpFor', { slot: actionName });
@@ -519,13 +510,9 @@ export default function CommitDialog({
// says what to do next, shows here on screen.
- {copyResult === 'copied'
- ? t('copied')
- : copyResult === 'failed'
- ? t('copyFailed')
- : null}
+ {copyFailed ? t('copyFailed') : linkCopied ? t('copied') : null}
)}