- Added a new profile page (my_profil.html) for users to manage their events and personal information. - Introduced a new CSS file (my_profil.css) for styling the profile page. - Created a JavaScript file (my_profil.js) to handle profile data retrieval, event registration management, and form submission. - Updated navigation logic (navigation.js) to dynamically display login/signup or event management links based on user authentication status. - Enhanced event creation and detail pages to support user-specific actions (registration/unregistration). - Improved login and signup processes to handle user data more robustly, including fallback user creation. - Refactored event overview to show user-specific events and registrations. - Added error handling and validation for user input in profile management.
64 lines
2.3 KiB
JavaScript
64 lines
2.3 KiB
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
const CURRENT_USER_KEY = 'socialCookingCurrentUser';
|
|
const navContainers = document.querySelectorAll('.nav-tab-links');
|
|
const currentPage = (window.location.pathname.split('/').pop() || 'index.html').toLowerCase();
|
|
|
|
// Beendet frueh, falls auf einer Seite keine Hauptnavigation vorhanden ist.
|
|
if (!navContainers.length) {
|
|
return;
|
|
}
|
|
|
|
// Liest den aktiven Benutzer robust aus localStorage.
|
|
function getCurrentUser() {
|
|
try {
|
|
const stored = localStorage.getItem(CURRENT_USER_KEY);
|
|
return stored ? JSON.parse(stored) : null;
|
|
} catch (error) {
|
|
console.error('Aktueller Benutzer konnte nicht gelesen werden.', error);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
// Baut die Navigation fuer ausgeloggte Besucher.
|
|
function buildLoggedOutNavigation() {
|
|
const loginIsActive = currentPage === 'login.html';
|
|
const signupIsActive = currentPage === 'signup.html';
|
|
|
|
return `
|
|
<a
|
|
class="button-small auth-nav-button ${loginIsActive ? 'auth-nav-button--active' : 'auth-nav-button--default'}"
|
|
href="login.html"
|
|
aria-label="Login"
|
|
${loginIsActive ? 'aria-current="page"' : ''}
|
|
>
|
|
Login
|
|
</a>
|
|
<a
|
|
class="button-small auth-nav-button ${signupIsActive ? 'auth-nav-button--active' : 'auth-nav-button--default'}"
|
|
href="signup.html"
|
|
aria-label="Signup"
|
|
${signupIsActive ? 'aria-current="page"' : ''}
|
|
>
|
|
Signup
|
|
</a>
|
|
`;
|
|
}
|
|
|
|
// Baut die Navigation fuer eingeloggte Benutzer.
|
|
function buildLoggedInNavigation() {
|
|
return `
|
|
<a class="nav-tab" href="event_overview.html">Event finden</a>
|
|
<a class="nav-tab" href="event_create.html">Event erstellen</a>
|
|
<a class="button-small" href="my_profil.html" aria-label="Mein Profil">Mein Profil</a>
|
|
`;
|
|
}
|
|
|
|
const currentUser = getCurrentUser();
|
|
const nextMarkup = currentUser ? buildLoggedInNavigation() : buildLoggedOutNavigation();
|
|
|
|
// Wendet das passende Markup auf alle vorhandenen Kopf-Navigationen an.
|
|
navContainers.forEach(container => {
|
|
container.innerHTML = nextMarkup;
|
|
});
|
|
});
|