From 7b4a1794281eb5c5218918c926c2bba6ca06b245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roman=20Kr=C4=8Dek?= Date: Tue, 2 Sep 2025 19:35:49 +0200 Subject: [PATCH] Fix diff counting logic --- .../private/events/event/view/+page.svelte | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/routes/private/events/event/view/+page.svelte b/src/routes/private/events/event/view/+page.svelte index 482450c..e1578ac 100644 --- a/src/routes/private/events/event/view/+page.svelte +++ b/src/routes/private/events/event/view/+page.svelte @@ -115,6 +115,8 @@ } syncingParticipants = true; + const previousCount = participants.length; // Capture count before sync + try { // Fetch sheet data const response = await fetch(`/private/api/google/sheets/${event.sheet_id}/data`, { @@ -177,16 +179,23 @@ // Reload participants await loadParticipants(); - - // Show success message with count of synced participants - const previousCount = participants.length; - const newCount = names.length; - const addedCount = Math.max(0, participants.length - previousCount); - - toast.success( - `Successfully synced participants. ${newCount} entries processed, ${addedCount} new participants added.`, - 5000 - ); + + // Show success message with accurate count of changes + const newCount = participants.length; + const diff = newCount - previousCount; + const processedCount = names.length; + + let message = `Sync complete. ${processedCount} confirmed entries processed from the sheet.`; + + if (diff > 0) { + message += ` ${diff} new participants added.`; + } else if (diff < 0) { + message += ` ${-diff} participants removed.`; + } else { + message += ` No changes to the participant list.`; + } + + toast.success(message, 6000); } catch (err) { console.error('Error syncing participants:', err); toast.error(`Failed to sync participants: ${err instanceof Error ? err.message : 'Unknown error'}`);