Refactor navigation and form elements for improved usability and localization

This commit is contained in:
2025-01-25 11:21:26 +01:00
parent 09772d859d
commit 1122de442b
3 changed files with 41 additions and 62 deletions

View File

@@ -17,17 +17,20 @@ document.addEventListener('DOMContentLoaded', function() {
const loginMessage = document.getElementById('loginMessage');
const logoutButton = document.getElementById('logoutButton');
const taskForm = document.getElementById('taskForm');
const hamburgerButton = document.getElementById('hamburgerButton');
const menuContent = document.getElementById('menuContent');
const sidenav = document.querySelector('.sidenav');
if (!loginForm || !loginContainer || !appContainer || !loginMessage || !logoutButton || !taskForm || !hamburgerButton || !menuContent) {
if (!loginForm || !loginContainer || !appContainer || !loginMessage || !logoutButton || !taskForm || !sidenav) {
console.error('One or more elements are missing in the DOM');
return;
}
// Toggle the hamburger menu
hamburgerButton.addEventListener('click', function() {
menuContent.classList.toggle('show');
// Initialize Materialize components
M.Sidenav.init(sidenav);
M.Datepicker.init(document.querySelectorAll('.datepicker'), {
format: 'yyyy-mm-dd',
defaultDate: new Date(),
setDefaultDate: true,
firstDay: 1
});
// Check if user is already logged in
@@ -130,6 +133,7 @@ document.addEventListener('DOMContentLoaded', function() {
});
const data = await response.json();
document.getElementById('responseMessage').textContent = data.message;
taskForm.reset(); // Reset the form after saving the task
} catch (error) {
if (error.status === 401) {
sessionStorage.removeItem('loggedIn');
@@ -149,6 +153,7 @@ document.addEventListener('DOMContentLoaded', function() {
});
await db.add('tasks', taskData);
document.getElementById('responseMessage').textContent = "Task saved offline!";
taskForm.reset(); // Reset the form after saving the task
} catch (error) {
document.getElementById('responseMessage').textContent = "Error saving task offline!";
console.error('Error saving task offline:', error);
@@ -156,19 +161,6 @@ document.addEventListener('DOMContentLoaded', function() {
}
});
// Set tomorrow's date as the default for the date input
const today = new Date();
const tomorrow = new Date(today);
tomorrow.setDate(today.getDate() + 1);
const tomorrowString = tomorrow.toISOString().split('T')[0];
document.getElementById('scheduled').value = tomorrowString;
// Initialize flatpickr with Swedish locale and Monday as the first day of the week
flatpickr("#scheduled", {
weekNumbers: true, // Show week numbers
firstDayOfWeek: 1 // Start weeks on Monday
});
// Load tags from server and initialize autocomplete
function loadTags() {
fetch('/get-tags')