From 1122de442bf2160ddb3d8860864457f4a3c62be9 Mon Sep 17 00:00:00 2001 From: Fredrik Wahlberg Date: Sat, 25 Jan 2025 11:21:26 +0100 Subject: [PATCH] Refactor navigation and form elements for improved usability and localization --- public/app.js | 30 +++++++++-------------- public/index.html | 62 +++++++++++++++++++++-------------------------- public/style.css | 11 ++------- 3 files changed, 41 insertions(+), 62 deletions(-) diff --git a/public/app.js b/public/app.js index 6d2d714..fcb4d3f 100644 --- a/public/app.js +++ b/public/app.js @@ -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') diff --git a/public/index.html b/public/index.html index f7d48fb..7b08529 100644 --- a/public/index.html +++ b/public/index.html @@ -17,12 +17,12 @@

Logga in

- - + +
- - + +
@@ -31,49 +31,43 @@