Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b65e392fe | ||
|
|
d46b65aa73 | ||
|
|
f4463bbd9a | ||
|
|
ae631cd463 |
No files matched your search
@@ -471,12 +471,20 @@ label {
|
|||||||
transition: background-color 0.2s ease, border-color 0.2s ease;
|
transition: background-color 0.2s ease, border-color 0.2s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button-primary-abmelden:hover,
|
.button-primary-abmelden:hover:not(:disabled),
|
||||||
.button-primary-abmelden:focus-visible {
|
.button-primary-abmelden:focus-visible:not(:disabled) {
|
||||||
background: var(--blue-dark);
|
background: var(--blue-dark);
|
||||||
border-color: var(--blue-dark);
|
border-color: var(--blue-dark);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.button-primary-abmelden:disabled {
|
||||||
|
background-color: var(--blue);
|
||||||
|
border-color: var(--blue);
|
||||||
|
color: var(--butter-light);
|
||||||
|
opacity: 0.6;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
.button-primary-eigener-event{
|
.button-primary-eigener-event{
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 0.375rem 1.5rem;
|
padding: 0.375rem 1.5rem;
|
||||||
@@ -589,6 +597,7 @@ label {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.category-item-profile {
|
.category-item-profile {
|
||||||
|
position: relative;
|
||||||
font-size: 1.25rem;
|
font-size: 1.25rem;
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
@@ -643,6 +652,7 @@ label {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.profile-pill {
|
.profile-pill {
|
||||||
|
position: relative;
|
||||||
width: 2.375rem;
|
width: 2.375rem;
|
||||||
height: 2.375rem;
|
height: 2.375rem;
|
||||||
border-radius: 1.1875rem;
|
border-radius: 1.1875rem;
|
||||||
@@ -658,6 +668,18 @@ label {
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.notification-dot {
|
||||||
|
position: absolute;
|
||||||
|
top: -2px;
|
||||||
|
right: -2px;
|
||||||
|
width: 12px;
|
||||||
|
height: 12px;
|
||||||
|
background-color: var(--error);
|
||||||
|
border-radius: 50%;
|
||||||
|
border: 2px solid var(--butter-light);
|
||||||
|
z-index: 10;
|
||||||
|
}
|
||||||
|
|
||||||
/* Utilities */
|
/* Utilities */
|
||||||
.text-center {
|
.text-center {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|||||||
+35
-1
@@ -87,7 +87,7 @@
|
|||||||
"title": "Japanese Delight",
|
"title": "Japanese Delight",
|
||||||
"location": "Zürich",
|
"location": "Zürich",
|
||||||
"address": "Limmatquai 92, 8001 Zürich",
|
"address": "Limmatquai 92, 8001 Zürich",
|
||||||
"date": "02. MAI. 2026",
|
"date": "24. April. 2026",
|
||||||
"time": "12:30 UHR",
|
"time": "12:30 UHR",
|
||||||
"category": "Lunch",
|
"category": "Lunch",
|
||||||
"diet": "Fisch",
|
"diet": "Fisch",
|
||||||
@@ -121,5 +121,39 @@
|
|||||||
"https://i.pinimg.com/1200x/b1/fb/3a/b1fb3a7809f4046843904ac8800daacc.jpg",
|
"https://i.pinimg.com/1200x/b1/fb/3a/b1fb3a7809f4046843904ac8800daacc.jpg",
|
||||||
"https://i.pinimg.com/1200x/c6/93/42/c69342ec621333e853c35bda891d8bc6.jpg"
|
"https://i.pinimg.com/1200x/c6/93/42/c69342ec621333e853c35bda891d8bc6.jpg"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": 4,
|
||||||
|
"title": "Mexican Fiesta",
|
||||||
|
"location": "Basel",
|
||||||
|
"address": "Münsterplatz 10, 4051 Basel",
|
||||||
|
"date": "28. April. 2026",
|
||||||
|
"time": "18:00 UHR",
|
||||||
|
"category": "Dinner",
|
||||||
|
"diet": "Omnivore",
|
||||||
|
"spots": 6,
|
||||||
|
"status": "canceled",
|
||||||
|
"host": {
|
||||||
|
"name": "Carlos",
|
||||||
|
"initial": "C"
|
||||||
|
},
|
||||||
|
"hostMessage": [
|
||||||
|
"Hallo zusammen! Leider muss ich dieses Event absagen, da mir etwas Wichtiges dazwischengekommen ist.",
|
||||||
|
"Ich hoffe, wir können das bald nachholen!"
|
||||||
|
],
|
||||||
|
"menu": [
|
||||||
|
"Guacamole & Nachos",
|
||||||
|
"Tacos al Pastor",
|
||||||
|
"Churros"
|
||||||
|
],
|
||||||
|
"specifications": [],
|
||||||
|
"participants": [
|
||||||
|
"Carlos",
|
||||||
|
"Vivien",
|
||||||
|
"Test"
|
||||||
|
],
|
||||||
|
"gallery": [
|
||||||
|
"https://i.pinimg.com/1200x/e2/6a/f5/e26af5c24b805081a3f304d240818302.jpg"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
+79
-12
@@ -105,6 +105,19 @@
|
|||||||
localStorage.setItem(REGISTRATION_STORAGE_KEY, JSON.stringify(registrationMap));
|
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) {
|
function parseEventDateTime(event) {
|
||||||
if (!event?.date) return null;
|
if (!event?.date) return null;
|
||||||
const dateValue = String(event.date).trim();
|
const dateValue = String(event.date).trim();
|
||||||
@@ -116,11 +129,39 @@
|
|||||||
month = Number(isoDateMatch[2]);
|
month = Number(isoDateMatch[2]);
|
||||||
day = Number(isoDateMatch[3]);
|
day = Number(isoDateMatch[3]);
|
||||||
} else {
|
} 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 monthMap = {
|
||||||
const localizedMatch = dateValue.match(/^(\d{1,2})\.\s*([A-ZÄÖÜ]{3})\.\s*(\d{4})$/);
|
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;
|
if (!localizedMatch) return null;
|
||||||
day = Number(localizedMatch[1]);
|
day = Number(localizedMatch[1]);
|
||||||
month = monthMap[localizedMatch[2]];
|
month = monthMap[String(localizedMatch[2]).toLowerCase()];
|
||||||
year = Number(localizedMatch[3]);
|
year = Number(localizedMatch[3]);
|
||||||
if (!month) return null;
|
if (!month) return null;
|
||||||
}
|
}
|
||||||
@@ -150,8 +191,18 @@
|
|||||||
function isAddressVisibleWindow(event) {
|
function isAddressVisibleWindow(event) {
|
||||||
const eventDateTime = parseEventDateTime(event);
|
const eventDateTime = parseEventDateTime(event);
|
||||||
if (!eventDateTime || Number.isNaN(eventDateTime.getTime())) return false;
|
if (!eventDateTime || Number.isNaN(eventDateTime.getTime())) return false;
|
||||||
const msUntilStart = eventDateTime.getTime() - Date.now();
|
const now = Date.now();
|
||||||
return msUntilStart >= 0 && msUntilStart <= 24 * 60 * 60 * 1000;
|
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) {
|
function isEventOwnedByCurrentUser(event, user) {
|
||||||
@@ -290,28 +341,44 @@
|
|||||||
const isFull = freePlaces === 0;
|
const isFull = freePlaces === 0;
|
||||||
const isRegistrationClosed = isRegistrationClosedForEvent(event);
|
const isRegistrationClosed = isRegistrationClosedForEvent(event);
|
||||||
const deregInfo = getDeregistrationInfo(event);
|
const deregInfo = getDeregistrationInfo(event);
|
||||||
const userRegistrations = currentUser?.email && Array.isArray(registrationMap[currentUser.email])
|
const userRegistrations = getRegistrationIdsForUser(registrationMap, currentUser);
|
||||||
? registrationMap[currentUser.email].map(id => Number(id)) : [];
|
|
||||||
const isRegistered = userRegistrations.includes(Number(event.id));
|
const isRegistered = userRegistrations.includes(Number(event.id));
|
||||||
const isListedParticipant = isUserListedInEventParticipants(event, currentUser);
|
const isListedParticipant = isUserListedInEventParticipants(event, currentUser);
|
||||||
const hasAddressAccess = isRegistered || isListedParticipant;
|
const hasAddressAccess = isRegistered || isListedParticipant || isOwnEvent;
|
||||||
|
const isCanceled = event.status === 'canceled';
|
||||||
|
|
||||||
const actionButtonLabel = isOwnEvent ? 'Dein Event!'
|
const actionButtonLabel = isCanceled ? 'Abgesagt'
|
||||||
|
: isOwnEvent ? 'Dein Event!'
|
||||||
: !currentUser ? 'Einloggen'
|
: !currentUser ? 'Einloggen'
|
||||||
: isRegistered ? (deregInfo.isClosed ? 'Abmeldung geschlossen' : 'Abmelden')
|
: isRegistered ? (deregInfo.isClosed ? 'Abmeldung geschlossen' : 'Abmelden')
|
||||||
: isRegistrationClosed ? 'Anmeldung geschlossen'
|
: isRegistrationClosed ? 'Anmeldung geschlossen'
|
||||||
: 'Anmelden';
|
: 'Anmelden';
|
||||||
const actionButtonDisabled = isOwnEvent
|
const actionButtonDisabled = isCanceled
|
||||||
|
|| isOwnEvent
|
||||||
|| (!isRegistered && (isFull || isRegistrationClosed))
|
|| (!isRegistered && (isFull || isRegistrationClosed))
|
||||||
|| (isRegistered && deregInfo.isClosed);
|
|| (isRegistered && deregInfo.isClosed);
|
||||||
const actionButtonVariantClass = isOwnEvent ? ' button-primary-eigener-event'
|
const actionButtonVariantClass = isOwnEvent ? ' button-primary-eigener-event'
|
||||||
: isRegistered ? ' button-primary-abmelden '
|
: (isRegistered || isRegistrationClosed) ? ' button-primary-abmelden '
|
||||||
: ' button-primary ';
|
: ' button-primary ';
|
||||||
|
|
||||||
const shouldRevealAddress = Boolean(event.address) && isAddressVisibleWindow(event) && hasAddressAccess;
|
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 (isCanceled) {
|
||||||
|
addressMessage = 'Dieses Event wurde leider vom Gastgeber abgesagt.';
|
||||||
|
} else 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 (!isCanceled && isEventPastAddressWindow(event)) {
|
||||||
|
addressMessage = 'Vielen Dank, dass du an diesem Event teilgenommen hast.';
|
||||||
|
}
|
||||||
|
|
||||||
const addressPanelMarkup = shouldRevealAddress
|
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>${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 = [
|
const detailChips = [
|
||||||
`<span class="event-tag">${eventCategory}</span>`,
|
`<span class="event-tag">${eventCategory}</span>`,
|
||||||
|
|||||||
+67
-33
@@ -286,28 +286,42 @@
|
|||||||
day = Number(isoDateMatch[3]);
|
day = Number(isoDateMatch[3]);
|
||||||
} else {
|
} else {
|
||||||
const monthMap = {
|
const monthMap = {
|
||||||
JAN: 1,
|
jan: 1,
|
||||||
FEB: 2,
|
januar: 1,
|
||||||
'MÄR': 3,
|
feb: 2,
|
||||||
MRZ: 3,
|
februar: 2,
|
||||||
APR: 4,
|
'mär': 3,
|
||||||
MAI: 5,
|
mrz: 3,
|
||||||
JUN: 6,
|
mar: 3,
|
||||||
JUL: 7,
|
maerz: 3,
|
||||||
AUG: 8,
|
märz: 3,
|
||||||
SEP: 9,
|
apr: 4,
|
||||||
OKT: 10,
|
april: 4,
|
||||||
NOV: 11,
|
mai: 5,
|
||||||
DEZ: 12
|
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-ZÄÖÜ]{3})\.\s*(\d{4})$/);
|
const localizedMatch = dateValue.match(/^(\d{1,2})\.\s*([A-Za-zÄÖÜäöü]{3,9})\.?\s*(\d{4})$/);
|
||||||
|
|
||||||
if (!localizedMatch) {
|
if (!localizedMatch) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
day = Number(localizedMatch[1]);
|
day = Number(localizedMatch[1]);
|
||||||
month = monthMap[localizedMatch[2]];
|
month = monthMap[String(localizedMatch[2]).toLowerCase()];
|
||||||
year = Number(localizedMatch[3]);
|
year = Number(localizedMatch[3]);
|
||||||
|
|
||||||
if (!month) {
|
if (!month) {
|
||||||
@@ -383,23 +397,24 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
const filtered = allEvents.filter(event => {
|
const filtered = allEvents.filter(event => {
|
||||||
|
if (event.status === 'canceled') return false;
|
||||||
|
|
||||||
const categoryMatch = activeCategory === 'ALLE' || event.category === activeCategory;
|
const categoryMatch = activeCategory === 'ALLE' || event.category === activeCategory;
|
||||||
|
|
||||||
// Diet filter: if no diets selected, show all. Otherwise, event MUST have at least one selected diet.
|
// Diet filter: if no diets selected, show all. Otherwise, event MUST have at least one selected diet.
|
||||||
const dietMatch = activeDiets.size === 0 ||
|
const dietMatch = activeDiets.size === 0 ||
|
||||||
(event.diet && event.diet.split(', ').some(d => activeDiets.has(d.trim())));
|
(event.diet && event.diet.split(', ').some(d => activeDiets.has(d.trim())));
|
||||||
|
|
||||||
// Allergie filter: if no allergies selected, show all. Otherwise, event MUST have at least one selected allergie.
|
// Allergie filter: if no allergies selected, show all. Otherwise, event MUST have at least one selected allergie.
|
||||||
const allergieMatch = activeAllergies.size === 0 ||
|
const allergieMatch = activeAllergies.size === 0 ||
|
||||||
(event.specifications && event.specifications.some(spec => activeAllergies.has(spec)));
|
(event.specifications && event.specifications.some(spec => activeAllergies.has(spec)));
|
||||||
|
|
||||||
const locationMatch = selectedLocation === 'ALLE_ORTE' || event.location === selectedLocation;
|
const locationMatch = selectedLocation === 'ALLE_ORTE' || event.location === selectedLocation;
|
||||||
const eventDateIso = parseEventDateToIso(event.date);
|
const eventDateIso = parseEventDateToIso(event.date);
|
||||||
const dateMatch = !selectedDate || eventDateIso === selectedDate;
|
const dateMatch = !selectedDate || eventDateIso === selectedDate;
|
||||||
|
|
||||||
return categoryMatch && dietMatch && allergieMatch && locationMatch && dateMatch;
|
return categoryMatch && dietMatch && allergieMatch && locationMatch && dateMatch;
|
||||||
});
|
});
|
||||||
|
|
||||||
renderEvents(filtered);
|
renderEvents(filtered);
|
||||||
|
|
||||||
sessionStorage.setItem('activeFilter', activeCategory);
|
sessionStorage.setItem('activeFilter', activeCategory);
|
||||||
@@ -459,6 +474,11 @@
|
|||||||
const isOwnEvent = isEventOwnedByCurrentUser(event, currentUser);
|
const isOwnEvent = isEventOwnedByCurrentUser(event, currentUser);
|
||||||
const isRegistered = userRegistrationSet.has(Number(event.id));
|
const isRegistered = userRegistrationSet.has(Number(event.id));
|
||||||
const isRegistrationClosed = isRegistrationClosedForEvent(event);
|
const isRegistrationClosed = isRegistrationClosedForEvent(event);
|
||||||
|
const isCanceled = event.status === 'canceled';
|
||||||
|
|
||||||
|
if (isCanceled) {
|
||||||
|
card.style.opacity = '0.6';
|
||||||
|
}
|
||||||
|
|
||||||
// Build optional specification chips only when data exists.
|
// Build optional specification chips only when data exists.
|
||||||
const specsChips = event.specifications && event.specifications.length > 0
|
const specsChips = event.specifications && event.specifications.length > 0
|
||||||
@@ -470,17 +490,31 @@
|
|||||||
? event.diet.split(', ').map(d => `<span class="event-tag">${d.trim()}</span>`).join('')
|
? event.diet.split(', ').map(d => `<span class="event-tag">${d.trim()}</span>`).join('')
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
const actionMarkup = isOwnEvent
|
let actionMarkup = '';
|
||||||
? '<button class="button-primary-eigener-event" type="button" data-registration-action="own" disabled>Dein Event!</button>'
|
if (isCanceled) {
|
||||||
: isRegistered
|
actionMarkup = '<button class="button-primary" type="button" disabled>Abgesagt</button>';
|
||||||
? '<button class="button-primary button-primary-abmelden" type="button" data-registration-action="unregister">Abmelden</button>'
|
} else if (isOwnEvent) {
|
||||||
: isRegistrationClosed
|
actionMarkup = '<button class="button-primary-eigener-event" type="button" data-registration-action="own" disabled>Dein Event!</button>';
|
||||||
? '<button class="button-primary" button-plaetze" type="button" data-registration-action="closed" disabled>Anmeldung geschlossen</button>'
|
} else if (isRegistered) {
|
||||||
: isFull
|
actionMarkup = isRegistrationClosed
|
||||||
? ''
|
? '<button class="button-primary-abmelden" type="button" disabled>Abmeldung geschlossen</button>'
|
||||||
: !currentUser
|
: '<button class="button-primary-abmelden" type="button" data-registration-action="unregister">Abmelden</button>';
|
||||||
? '<button class="button-primary btn-primary-register" type="button" data-registration-action="login">Anmelden</button>'
|
} else if (isRegistrationClosed) {
|
||||||
: '<button class="button-primary btn-primary-register" type="button" data-registration-action="register">Anmelden</button>';
|
actionMarkup = '<button class="button-primary-abmelden" type="button" data-registration-action="closed" disabled>Anmeldung geschlossen</button>';
|
||||||
|
} else if (!isFull) {
|
||||||
|
if (!currentUser) {
|
||||||
|
actionMarkup = '<button class="button-primary btn-primary-register" type="button" data-registration-action="login">Anmelden</button>';
|
||||||
|
} else {
|
||||||
|
actionMarkup = '<button class="button-primary btn-primary-register" type="button" data-registration-action="register">Anmelden</button>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let sideInfoMarkup = '';
|
||||||
|
if (isCanceled) {
|
||||||
|
sideInfoMarkup = '<span class="button-plaetze">Event abgesagt</span>';
|
||||||
|
} else if (!isRegistrationClosed) {
|
||||||
|
sideInfoMarkup = `<span class="button-plaetze${isFull ? ' event-spots-full' : ''}">${isFull ? 'Ausgebucht' : `${freePlaces} Plätze frei`}</span>`;
|
||||||
|
}
|
||||||
|
|
||||||
card.innerHTML = `
|
card.innerHTML = `
|
||||||
<div class="event-main">
|
<div class="event-main">
|
||||||
@@ -501,7 +535,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="event-side${isFull ? ' event-side-full' : ''}">
|
<div class="event-side${isFull ? ' event-side-full' : ''}">
|
||||||
${isRegistrationClosed ? '' : `<span class="button-plaetze${isFull ? ' event-spots-full' : ''}">${isFull ? 'Ausgebucht' : `${freePlaces} Plätze frei`}</span>`}
|
${sideInfoMarkup}
|
||||||
${actionMarkup}
|
${actionMarkup}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|||||||
+192
-40
@@ -213,6 +213,11 @@
|
|||||||
const isActive = panel.getAttribute('data-profile-panel') === tabName;
|
const isActive = panel.getAttribute('data-profile-panel') === tabName;
|
||||||
panel.classList.toggle('hidden', !isActive);
|
panel.classList.toggle('hidden', !isActive);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (tabName === 'teilnehmen') {
|
||||||
|
const registeredEvents = getMyRegisteredEvents(allEvents, currentUser);
|
||||||
|
markRegistrationsAsRead(registeredEvents);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reagiert auf Aktionen in der Liste "Meine Anmeldungen" per Event Delegation.
|
// Reagiert auf Aktionen in der Liste "Meine Anmeldungen" per Event Delegation.
|
||||||
@@ -452,13 +457,27 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ermittelt angemeldete Events über die Registration-Map.
|
// Ermittelt angemeldete Events über die Registration-Map und participants-Liste.
|
||||||
function getMyRegisteredEvents(events, user) {
|
function getMyRegisteredEvents(events, user) {
|
||||||
const registrationMap = getRegistrationMap();
|
const registrationMap = getRegistrationMap();
|
||||||
const registeredIds = Array.isArray(registrationMap[user.email]) ? registrationMap[user.email] : [];
|
const registeredIds = Array.isArray(registrationMap[user.email]) ? registrationMap[user.email] : [];
|
||||||
const idSet = new Set(registeredIds.map(id => Number(id)));
|
const idSet = new Set(registeredIds.map(id => Number(id)));
|
||||||
|
|
||||||
return events.filter(event => idSet.has(Number(event.id)));
|
const userFirstName = String(user.vorname || '').trim().toLowerCase();
|
||||||
|
const userFullName = `${String(user.vorname || '').trim()} ${String(user.nachname || '').trim()}`.trim().toLowerCase();
|
||||||
|
|
||||||
|
return events.filter(event => {
|
||||||
|
if (idSet.has(Number(event.id))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (Array.isArray(event.participants)) {
|
||||||
|
const participantSet = new Set(event.participants.map(name => String(name || '').trim().toLowerCase()).filter(Boolean));
|
||||||
|
if ((userFirstName && participantSet.has(userFirstName)) || (userFullName && participantSet.has(userFullName))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rendert angemeldete Events inkl. Zähler.
|
// Rendert angemeldete Events inkl. Zähler.
|
||||||
@@ -477,6 +496,35 @@
|
|||||||
}, 'hosting');
|
}, 'hosting');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSeenAddresses() {
|
||||||
|
try {
|
||||||
|
const raw = localStorage.getItem('socialCookingSeenAddresses');
|
||||||
|
return raw ? JSON.parse(raw) : [];
|
||||||
|
} catch (err) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function markRegistrationsAsRead(events) {
|
||||||
|
const seen = getSeenAddresses();
|
||||||
|
let changed = false;
|
||||||
|
events.forEach(event => {
|
||||||
|
if (isAddressVisibleWindow(event) && !seen.includes(Number(event.id))) {
|
||||||
|
seen.push(Number(event.id));
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (changed) {
|
||||||
|
localStorage.setItem('socialCookingSeenAddresses', JSON.stringify(seen));
|
||||||
|
// Remove dots from UI
|
||||||
|
const tabDot = document.querySelector('[data-category-item="teilnehmen"] .notification-dot');
|
||||||
|
if (tabDot) tabDot.remove();
|
||||||
|
|
||||||
|
const navDot = document.querySelector('.profile-pill .notification-dot');
|
||||||
|
if (navDot) navDot.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Rendert angemeldete Events inkl. Zähler.
|
// Rendert angemeldete Events inkl. Zähler.
|
||||||
function renderMyRegistrations(events, user) {
|
function renderMyRegistrations(events, user) {
|
||||||
const registeredEvents = getMyRegisteredEvents(events, user);
|
const registeredEvents = getMyRegisteredEvents(events, user);
|
||||||
@@ -486,16 +534,51 @@
|
|||||||
myRegistrationsCount.textContent = String(count);
|
myRegistrationsCount.textContent = String(count);
|
||||||
if (myRegistrationsBtnCount) myRegistrationsBtnCount.textContent = String(count);
|
if (myRegistrationsBtnCount) myRegistrationsBtnCount.textContent = String(count);
|
||||||
|
|
||||||
|
const seenAddresses = getSeenAddresses();
|
||||||
|
const unreadEvents = registeredEvents.filter(e => isAddressVisibleWindow(e) && !seenAddresses.includes(Number(e.id)));
|
||||||
|
const hasNotifications = unreadEvents.length > 0;
|
||||||
|
|
||||||
|
const tabButton = document.querySelector('[data-category-item="teilnehmen"]');
|
||||||
|
if (tabButton) {
|
||||||
|
let dot = tabButton.querySelector('.notification-dot');
|
||||||
|
if (hasNotifications) {
|
||||||
|
if (!dot) {
|
||||||
|
dot = document.createElement('span');
|
||||||
|
dot.className = 'notification-dot';
|
||||||
|
tabButton.appendChild(dot);
|
||||||
|
}
|
||||||
|
} else if (dot) {
|
||||||
|
dot.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
renderEventCards(myRegistrationsList, registeredEvents, {
|
renderEventCards(myRegistrationsList, registeredEvents, {
|
||||||
title: 'Noch keine Anmeldungen',
|
title: 'Noch keine Anmeldungen',
|
||||||
text: 'Entdecke spannende Dinner in deiner Naehe und melde dich direkt an.',
|
text: 'Entdecke spannende Dinner in deiner Naehe und melde dich direkt an.',
|
||||||
buttonLabel: 'Events entdecken',
|
buttonLabel: 'Events entdecken',
|
||||||
href: 'event_overview.html'
|
href: 'event_overview.html'
|
||||||
}, 'registrations');
|
}, 'registrations', seenAddresses);
|
||||||
|
|
||||||
|
// Falls wir bereits auf dem Tab sind, direkt als gelesen markieren
|
||||||
|
const activeTab = document.querySelector('[data-category-item="teilnehmen"].is-active');
|
||||||
|
if (activeTab && hasNotifications) {
|
||||||
|
// Kurze Verzögerung, damit UI sich erst aufbaut
|
||||||
|
setTimeout(() => markRegistrationsAsRead(registeredEvents), 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gibt true zurück, wenn die Abmeldung gesperrt ist (innerhalb von 24h oder in der Vergangenheit).
|
||||||
|
function isDeregistrationClosed(event) {
|
||||||
|
const eventDateTime = parseEventDateTime(event);
|
||||||
|
if (!eventDateTime || Number.isNaN(eventDateTime.getTime())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const msUntilStart = eventDateTime.getTime() - Date.now();
|
||||||
|
return msUntilStart <= 24 * 60 * 60 * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Baut die Eventkarten für beide Listen in einheitlichem Markup.
|
// Baut die Eventkarten für beide Listen in einheitlichem Markup.
|
||||||
function renderEventCards(container, events, emptyStateConfig, mode) {
|
function renderEventCards(container, events, emptyStateConfig, mode, seenAddresses = []) {
|
||||||
container.innerHTML = '';
|
container.innerHTML = '';
|
||||||
|
|
||||||
if (events.length === 0) {
|
if (events.length === 0) {
|
||||||
@@ -515,33 +598,81 @@
|
|||||||
const card = document.createElement('article');
|
const card = document.createElement('article');
|
||||||
card.className = 'profile-event-card profile-event-card-clickable';
|
card.className = 'profile-event-card profile-event-card-clickable';
|
||||||
card.setAttribute('data-event-id', String(event.id));
|
card.setAttribute('data-event-id', String(event.id));
|
||||||
const addressMarkup = mode === 'registrations' && event.address
|
|
||||||
? (isAddressVisibleWindow(event)
|
const isCanceled = event.status === 'canceled';
|
||||||
? `
|
if (isCanceled) {
|
||||||
|
card.style.opacity = '0.6';
|
||||||
|
}
|
||||||
|
|
||||||
|
let 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.';
|
||||||
|
}
|
||||||
|
|
||||||
|
let addressMarkup = '';
|
||||||
|
if (mode === 'registrations' && event.address) {
|
||||||
|
if (isCanceled) {
|
||||||
|
addressMarkup = `
|
||||||
|
<div class="profile-event-address-block" aria-label="Hinweis zur Adresse">
|
||||||
|
<p class="profile-event-address-label">Adresse</p>
|
||||||
|
<p class="profile-event-address">Dieses Event wurde leider vom Gastgeber abgesagt.</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
} else if (isAddressVisibleWindow(event)) {
|
||||||
|
addressMarkup = `
|
||||||
<div class="profile-event-address-block" aria-label="Event Adresse">
|
<div class="profile-event-address-block" aria-label="Event Adresse">
|
||||||
<p class="profile-event-address-label">Adresse</p>
|
<p class="profile-event-address-label">Adresse</p>
|
||||||
<p class="profile-event-address">${event.address}</p>
|
<p class="profile-event-address">${event.address}</p>
|
||||||
</div>
|
</div>
|
||||||
`
|
`;
|
||||||
: `
|
} else {
|
||||||
|
addressMarkup = `
|
||||||
<div class="profile-event-address-block" aria-label="Hinweis zur Adresse">
|
<div class="profile-event-address-block" aria-label="Hinweis zur Adresse">
|
||||||
<p class="profile-event-address-label">Adresse</p>
|
<p class="profile-event-address-label">Adresse</p>
|
||||||
<p class="profile-event-address">Vielen Dank für die Anmeldung! Die Adresse für diesen Event wird 24 Stunden vorher genau hier sichtbar sein.</p>
|
<p class="profile-event-address">${addressMessage}</p>
|
||||||
</div>
|
</div>
|
||||||
`)
|
`;
|
||||||
: '';
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const actionMarkup = mode === 'registrations'
|
const isDeregClosed = isDeregistrationClosed(event);
|
||||||
? `
|
|
||||||
|
let actionMarkup = '';
|
||||||
|
if (mode === 'registrations') {
|
||||||
|
if (isCanceled) {
|
||||||
|
actionMarkup = `
|
||||||
|
<div class="event-side">
|
||||||
|
<button class="button-primary-abmelden" type="button" disabled>Abgesagt</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
} else if (isDeregClosed) {
|
||||||
|
actionMarkup = `
|
||||||
|
<div class="event-side">
|
||||||
|
<button class="button-primary-abmelden" type="button" disabled>Abmeldung geschlossen</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
} else {
|
||||||
|
actionMarkup = `
|
||||||
<div class="event-side">
|
<div class="event-side">
|
||||||
<button class="button-primary-abmelden" type="button" data-unregister-id="${event.id}">Abmelden</button>
|
<button class="button-primary-abmelden" type="button" data-unregister-id="${event.id}">Abmelden</button>
|
||||||
</div>
|
</div>
|
||||||
`
|
`;
|
||||||
: `
|
}
|
||||||
|
} else {
|
||||||
|
if (isCanceled) {
|
||||||
|
actionMarkup = `
|
||||||
|
<div class="event-side">
|
||||||
|
<button class="button-primary-eigener-event" type="button" disabled>Abgesagt</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
} else {
|
||||||
|
actionMarkup = `
|
||||||
<div class="event-side">
|
<div class="event-side">
|
||||||
<button class="button-primary-eigener-event" type="button" data-cancel-event-id="${event.id}">Event absagen</button>
|
<button class="button-primary-eigener-event" type="button" data-cancel-event-id="${event.id}">Event absagen</button>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
card.innerHTML = `
|
card.innerHTML = `
|
||||||
<div>
|
<div>
|
||||||
@@ -556,17 +687,24 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gibt true zurück, wenn ein Event innerhalb der nächsten 24 Stunden startet.
|
// Gibt true zurück, wenn die Adresse sichtbar sein soll (24h vor bis 1h nach Start).
|
||||||
function isAddressVisibleWindow(event) {
|
function isAddressVisibleWindow(event) {
|
||||||
|
if (event.status === 'canceled') return false;
|
||||||
const eventDateTime = parseEventDateTime(event);
|
const eventDateTime = parseEventDateTime(event);
|
||||||
if (!eventDateTime || Number.isNaN(eventDateTime.getTime())) {
|
if (!eventDateTime || Number.isNaN(eventDateTime.getTime())) return false;
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
const msUntilStart = eventDateTime.getTime() - Date.now();
|
// Gibt true zurück, wenn ein Event bereits vorbei ist (1h nach Start).
|
||||||
const twentyfourHoursInMs = 24 * 60 * 60 * 1000;
|
function isEventPastAddressWindow(event) {
|
||||||
|
const eventDateTime = parseEventDateTime(event);
|
||||||
return msUntilStart >= 0 && msUntilStart <= twentyfourHoursInMs;
|
if (!eventDateTime || Number.isNaN(eventDateTime.getTime())) return false;
|
||||||
|
const revealEnd = eventDateTime.getTime() + (1 * 60 * 60 * 1000);
|
||||||
|
return Date.now() > revealEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse für ISO- und lokalisierte Datumsformate aus den Eventdaten.
|
// Parse für ISO- und lokalisierte Datumsformate aus den Eventdaten.
|
||||||
@@ -587,28 +725,42 @@
|
|||||||
day = Number(isoDateMatch[3]);
|
day = Number(isoDateMatch[3]);
|
||||||
} else {
|
} else {
|
||||||
const monthMap = {
|
const monthMap = {
|
||||||
JAN: 1,
|
jan: 1,
|
||||||
FEB: 2,
|
januar: 1,
|
||||||
'MÄR': 3,
|
feb: 2,
|
||||||
MRZ: 3,
|
februar: 2,
|
||||||
APR: 4,
|
'mär': 3,
|
||||||
MAI: 5,
|
mrz: 3,
|
||||||
JUN: 6,
|
mar: 3,
|
||||||
JUL: 7,
|
maerz: 3,
|
||||||
AUG: 8,
|
märz: 3,
|
||||||
SEP: 9,
|
apr: 4,
|
||||||
OKT: 10,
|
april: 4,
|
||||||
NOV: 11,
|
mai: 5,
|
||||||
DEZ: 12
|
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-ZÄÖÜ]{3})\.\s*(\d{4})$/);
|
const localizedMatch = dateValue.match(/^(\d{1,2})\.\s*([A-Za-zÄÖÜäöü]{3,9})\.?\s*(\d{4})$/);
|
||||||
|
|
||||||
if (!localizedMatch) {
|
if (!localizedMatch) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
day = Number(localizedMatch[1]);
|
day = Number(localizedMatch[1]);
|
||||||
month = monthMap[localizedMatch[2]];
|
month = monthMap[String(localizedMatch[2]).toLowerCase()];
|
||||||
year = Number(localizedMatch[3]);
|
year = Number(localizedMatch[3]);
|
||||||
|
|
||||||
if (!month) {
|
if (!month) {
|
||||||
|
|||||||
+110
-7
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
const CURRENT_USER_KEY = 'socialCookingCurrentUser';
|
const CURRENT_USER_KEY = 'socialCookingCurrentUser';
|
||||||
|
const REGISTRATION_STORAGE_KEY = 'socialCookingRegistrations';
|
||||||
|
const EVENTS_STORAGE_KEY = 'socialCookingEvents';
|
||||||
const navcontainers = document.querySelectorAll('.nav-tab-links');
|
const navcontainers = document.querySelectorAll('.nav-tab-links');
|
||||||
const currentPage = (window.location.pathname.split('/').pop() || 'index.html').toLowerCase();
|
const currentPage = (window.location.pathname.split('/').pop() || 'index.html').toLowerCase();
|
||||||
|
|
||||||
@@ -31,6 +33,94 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
window.location.href = 'index.html';
|
window.location.href = 'index.html';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Hilfsfunktionen für Datumsberechnungen
|
||||||
|
function parseEventDateTime(event) {
|
||||||
|
if (!event?.date) return null;
|
||||||
|
const dateValue = String(event.date).trim();
|
||||||
|
const isoDateMatch = dateValue.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
||||||
|
let year, month, day;
|
||||||
|
|
||||||
|
if (isoDateMatch) {
|
||||||
|
year = Number(isoDateMatch[1]);
|
||||||
|
month = Number(isoDateMatch[2]);
|
||||||
|
day = Number(isoDateMatch[3]);
|
||||||
|
} else {
|
||||||
|
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[String(localizedMatch[2]).toLowerCase()];
|
||||||
|
year = Number(localizedMatch[3]);
|
||||||
|
if (!month) return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const timeMatch = String(event.time || '').match(/(\d{1,2}):(\d{2})/);
|
||||||
|
const hours = timeMatch ? Number(timeMatch[1]) : 0;
|
||||||
|
const minutes = timeMatch ? Number(timeMatch[2]) : 0;
|
||||||
|
return new Date(year, month - 1, day, hours, minutes, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isAddressVisibleWindow(event) {
|
||||||
|
if (event.status === 'canceled') return false;
|
||||||
|
const eventDateTime = parseEventDateTime(event);
|
||||||
|
if (!eventDateTime || Number.isNaN(eventDateTime.getTime())) return false;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function hasUnreadNotifications(user) {
|
||||||
|
if (!user || !user.email) return false;
|
||||||
|
|
||||||
|
let events = [];
|
||||||
|
try {
|
||||||
|
const rawStored = localStorage.getItem(EVENTS_STORAGE_KEY);
|
||||||
|
const storedEvents = rawStored ? JSON.parse(rawStored) : [];
|
||||||
|
|
||||||
|
const response = await fetch('data/events.json');
|
||||||
|
const apiEvents = await response.json();
|
||||||
|
events = [...storedEvents, ...apiEvents];
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Fehler beim Laden der Events für Benachrichtigungen', err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let map = {};
|
||||||
|
try {
|
||||||
|
const rawReg = localStorage.getItem(REGISTRATION_STORAGE_KEY);
|
||||||
|
map = rawReg ? JSON.parse(rawReg) : {};
|
||||||
|
} catch (err) {}
|
||||||
|
|
||||||
|
let seenAddresses = [];
|
||||||
|
try {
|
||||||
|
const rawSeen = localStorage.getItem('socialCookingSeenAddresses');
|
||||||
|
seenAddresses = rawSeen ? JSON.parse(rawSeen) : [];
|
||||||
|
} catch (err) {}
|
||||||
|
|
||||||
|
const registeredIds = Array.isArray(map[user.email]) ? map[user.email] : [];
|
||||||
|
const idSet = new Set(registeredIds.map(id => Number(id)));
|
||||||
|
|
||||||
|
const myRegisteredEvents = events.filter(e => idSet.has(Number(e.id)));
|
||||||
|
|
||||||
|
// Unread = address visible AND NOT marked as seen
|
||||||
|
return myRegisteredEvents.some(e => isAddressVisibleWindow(e) && !seenAddresses.includes(Number(e.id)));
|
||||||
|
}
|
||||||
|
|
||||||
// Baut die Navigation für ausgeloggte Besucher.
|
// Baut die Navigation für ausgeloggte Besucher.
|
||||||
function buildLoggedOutNavigation() {
|
function buildLoggedOutNavigation() {
|
||||||
const loginIsActive = currentPage === 'login.html';
|
const loginIsActive = currentPage === 'login.html';
|
||||||
@@ -71,10 +161,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Baut die Navigation für eingeloggte Benutzer.
|
// Baut die Navigation für eingeloggte Benutzer.
|
||||||
function buildLoggedInNavigation(user) {
|
function buildLoggedInNavigation(user, hasNotifications) {
|
||||||
const initial = (user.vorname || 'U').charAt(0).toUpperCase();
|
const initial = (user.vorname || 'U').charAt(0).toUpperCase();
|
||||||
const isEventOverview = currentPage === 'event_overview.html';
|
const isEventOverview = currentPage === 'event_overview.html';
|
||||||
const isEventCreate = currentPage === 'event_create.html';
|
const isEventCreate = currentPage === 'event_create.html';
|
||||||
|
const notificationMarkup = hasNotifications ? '<span class="notification-dot"></span>' : '';
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<a
|
<a
|
||||||
@@ -105,15 +196,27 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
title="${user.vorname || 'Profil'}"
|
title="${user.vorname || 'Profil'}"
|
||||||
>
|
>
|
||||||
${initial}
|
${initial}
|
||||||
|
${notificationMarkup}
|
||||||
</a>
|
</a>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentUser = getCurrentUser();
|
async function initNavigation() {
|
||||||
const nextMarkup = currentUser ? buildLoggedInNavigation(currentUser) : buildLoggedOutNavigation();
|
const currentUser = getCurrentUser();
|
||||||
|
let nextMarkup;
|
||||||
|
|
||||||
// Wendet das passende Markup auf alle vorhandenen Kopf-Navigationen an.
|
if (currentUser) {
|
||||||
navcontainers.forEach(container => {
|
const hasNotifications = await hasUnreadNotifications(currentUser);
|
||||||
container.innerHTML = nextMarkup;
|
nextMarkup = buildLoggedInNavigation(currentUser, hasNotifications);
|
||||||
});
|
} else {
|
||||||
|
nextMarkup = buildLoggedOutNavigation();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wendet das passende Markup auf alle vorhandenen Kopf-Navigationen an.
|
||||||
|
navcontainers.forEach(container => {
|
||||||
|
container.innerHTML = nextMarkup;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
initNavigation();
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user