fix: update event date and enhance address visibility logic

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
viiivo 2026-04-23 18:46:24 +02:00
parent 4ff703b4ff
commit ae631cd463
2 changed files with 72 additions and 10 deletions

View File

@ -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",

View File

@ -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
? `<article class="detail-panel"><h2 class="detail-section-title">Adresse</h2><p>${event.address}</p></article>`
: `<article class="detail-panel"><h2 class="detail-section-title">Adresse</h2><p>Vielen Dank für die Anmeldung! Die Adresse für diesen Event wird 24 Stunden vorher genau hier sichtbar sein.</p></article>`;
: `<article class="detail-panel"><h2 class="detail-section-title">Adresse</h2><p>${addressMessage}</p></article>`;
const detailChips = [
`<span class="event-tag">${eventCategory}</span>`,