Fix diff counting logic

This commit is contained in:
Roman Krček
2025-09-02 19:35:49 +02:00
parent 5ef9735ea5
commit 7b4a179428

View File

@@ -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'}`);