diff --git a/data/events.json b/data/events.json index 52940fc..088ffe1 100644 --- a/data/events.json +++ b/data/events.json @@ -87,7 +87,7 @@ "title": "Japanese Delight", "location": "Zürich", "address": "Limmatquai 92, 8001 Zürich", - "date": "02. MAI. 2026", + "date": "24. April. 2026", "time": "12:30 UHR", "category": "Lunch", "diet": "Fisch", diff --git a/js/event_detail.js b/js/event_detail.js index cc68c87..6899f74 100644 --- a/js/event_detail.js +++ b/js/event_detail.js @@ -105,6 +105,19 @@ localStorage.setItem(REGISTRATION_STORAGE_KEY, JSON.stringify(registrationMap)); } + function getRegistrationIdsForUser(registrationMap, user) { + const userEmail = String(user?.email || '').trim().toLowerCase(); + if (!userEmail) return []; + + const matchingIds = Object.entries(registrationMap || {}) + .filter(([email]) => String(email || '').trim().toLowerCase() === userEmail) + .flatMap(([, ids]) => (Array.isArray(ids) ? ids : [])) + .map(id => Number(id)) + .filter(id => Number.isFinite(id)); + + return Array.from(new Set(matchingIds)); + } + function parseEventDateTime(event) { if (!event?.date) return null; const dateValue = String(event.date).trim(); @@ -116,11 +129,39 @@ month = Number(isoDateMatch[2]); day = Number(isoDateMatch[3]); } else { - const monthMap = { JAN:1, FEB:2, 'MÄR':3, MRZ:3, APR:4, MAI:5, JUN:6, JUL:7, AUG:8, SEP:9, OKT:10, NOV:11, DEZ:12 }; - const localizedMatch = dateValue.match(/^(\d{1,2})\.\s*([A-ZÄÖÜ]{3})\.\s*(\d{4})$/); + const monthMap = { + jan: 1, + januar: 1, + feb: 2, + februar: 2, + 'mär': 3, + mrz: 3, + mar: 3, + maerz: 3, + märz: 3, + apr: 4, + april: 4, + mai: 5, + jun: 6, + juni: 6, + jul: 7, + juli: 7, + aug: 8, + august: 8, + sep: 9, + sept: 9, + september: 9, + okt: 10, + oktober: 10, + nov: 11, + november: 11, + dez: 12, + dezember: 12 + }; + const localizedMatch = dateValue.match(/^(\d{1,2})\.\s*([A-Za-zÄÖÜäöü]{3,9})\.?\s*(\d{4})$/); if (!localizedMatch) return null; day = Number(localizedMatch[1]); - month = monthMap[localizedMatch[2]]; + month = monthMap[String(localizedMatch[2]).toLowerCase()]; year = Number(localizedMatch[3]); if (!month) return null; } @@ -150,8 +191,18 @@ function isAddressVisibleWindow(event) { const eventDateTime = parseEventDateTime(event); if (!eventDateTime || Number.isNaN(eventDateTime.getTime())) return false; - const msUntilStart = eventDateTime.getTime() - Date.now(); - return msUntilStart >= 0 && msUntilStart <= 24 * 60 * 60 * 1000; + const now = Date.now(); + const start = eventDateTime.getTime(); + const revealStart = start - (24 * 60 * 60 * 1000); + const revealEnd = start + (1 * 60 * 60 * 1000); + return now >= revealStart && now <= revealEnd; + } + + function isEventPastAddressWindow(event) { + const eventDateTime = parseEventDateTime(event); + if (!eventDateTime || Number.isNaN(eventDateTime.getTime())) return false; + const revealEnd = eventDateTime.getTime() + (1 * 60 * 60 * 1000); + return Date.now() > revealEnd; } function isEventOwnedByCurrentUser(event, user) { @@ -290,11 +341,10 @@ const isFull = freePlaces === 0; const isRegistrationClosed = isRegistrationClosedForEvent(event); const deregInfo = getDeregistrationInfo(event); - const userRegistrations = currentUser?.email && Array.isArray(registrationMap[currentUser.email]) - ? registrationMap[currentUser.email].map(id => Number(id)) : []; + const userRegistrations = getRegistrationIdsForUser(registrationMap, currentUser); const isRegistered = userRegistrations.includes(Number(event.id)); const isListedParticipant = isUserListedInEventParticipants(event, currentUser); - const hasAddressAccess = isRegistered || isListedParticipant; + const hasAddressAccess = isRegistered || isListedParticipant || isOwnEvent; const actionButtonLabel = isOwnEvent ? 'Dein Event!' : !currentUser ? 'Einloggen' @@ -309,9 +359,21 @@ : ' button-primary '; const shouldRevealAddress = Boolean(event.address) && isAddressVisibleWindow(event) && hasAddressAccess; + let addressMessage = 'Wenn du dich anmeldest, wird die Adresse für diesen Event wird 24 Stunden vorher genau hier sichtbar sein.'; + + if (isOwnEvent) { + addressMessage = 'Deine Adresse für diesen Event wird 24 Stunden vorher genau hier für alle Teilnehmer sichtbar sein'; + } else if (hasAddressAccess) { + addressMessage = 'Vielen Dank für die Anmeldung! Die Adresse für diesen Event wird 24 Stunden vorher genau hier sichtbar sein.'; + } + + if (isEventPastAddressWindow(event)) { + addressMessage = 'Vielen Dank, dass du an diesem Event teilgenommen hast.'; + } + const addressPanelMarkup = shouldRevealAddress ? `

Adresse

${event.address}

` - : `

Adresse

Vielen Dank für die Anmeldung! Die Adresse für diesen Event wird 24 Stunden vorher genau hier sichtbar sein.

`; + : `

Adresse

${addressMessage}

`; const detailChips = [ `${eventCategory}`,