Skip to content

Commit 483c483

Browse files
committed
Stabilize join contact subject updates
1 parent bde6cd5 commit 483c483

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

src/scripts/app.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,11 +476,13 @@ function initJoinContact() {
476476
const selectedPrefix = status.dataset.selectedPrefix ?? 'Email subject:';
477477
const copiedPrefix = status.dataset.copiedPrefix ?? 'Copied email and subject:';
478478
const fallbackPrefix = status.dataset.copyFallbackPrefix ?? 'Use email and subject:';
479+
let selectionVersion = 0;
479480

480481
document.querySelectorAll<HTMLAnchorElement>('[data-join-contact-cta]').forEach((link) => {
481482
if (link.dataset.joinContactReady === 'true') return;
482483
link.dataset.joinContactReady = 'true';
483484
link.addEventListener('click', () => {
485+
const version = ++selectionVersion;
484486
const subject = link.dataset.contactSubject ?? '';
485487
const copyText = [email, subject ? `Subject: ${subject}` : ''].filter(Boolean).join('\n');
486488

@@ -497,11 +499,13 @@ function initJoinContact() {
497499
void navigator.clipboard
498500
.writeText(copyText)
499501
.then(() => {
502+
if (version !== selectionVersion) return;
500503
status.textContent = subject
501504
? `${copiedPrefix} ${email}${subject}`
502505
: `${copiedPrefix} ${email}`;
503506
})
504507
.catch(() => {
508+
if (version !== selectionVersion) return;
505509
status.textContent = subject
506510
? `${fallbackPrefix} ${email}${subject}`
507511
: `${fallbackPrefix} ${email}`;

0 commit comments

Comments
 (0)