From eee88ac804c1045ed68791484f9fa32c2dc98b68 Mon Sep 17 00:00:00 2001 From: chris Date: Thu, 31 Jul 2025 11:38:37 -0400 Subject: [PATCH] ui improvments mobile --- public/index.html | 55 +++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/public/index.html b/public/index.html index 91a0f97..22ad909 100644 --- a/public/index.html +++ b/public/index.html @@ -21,16 +21,15 @@
-
@@ -65,9 +64,8 @@ const formatDuration = (ms) => { if (!ms || ms < 0) return '00:00:00'; const s = Math.floor(ms / 1000); const h = Math.floor(s / 3600); const m = Math.floor((s % 3600) / 60); return `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}:${String(s % 60).padStart(2, '0')}`; }; // --- API Calls --- - // MODIFIED: This now points to the full server address, including the port. const API_BASE_URL = '/api'; - async function apiCall(endpoint, method = 'GET', body = null) { + async function apiCall(endpoint, method = 'GET', body = null) { const headers = { 'Content-Type': 'application/json' }; if (authToken) headers['Authorization'] = `Bearer ${authToken}`; try { @@ -86,14 +84,23 @@ // --- UI Rendering --- function updateUI() { - if (authToken && user) { - navUserControls.classList.remove('hidden'); - welcomeMessage.textContent = `Welcome, ${user.username}`; - user.role === 'admin' ? (showView('admin'), renderAdminDashboard()) : (showView('employee'), renderEmployeeDashboard()); - } else { - navUserControls.classList.add('hidden'); - showView('auth'); - renderAuthView(); + try { + const storedUser = localStorage.getItem('user'); + user = storedUser ? JSON.parse(storedUser) : null; + authToken = localStorage.getItem('authToken'); + + if (authToken && user) { + navUserControls.classList.remove('hidden'); + welcomeMessage.textContent = `Welcome, ${user.username}`; + user.role === 'admin' ? (showView('admin'), renderAdminDashboard()) : (showView('employee'), renderEmployeeDashboard()); + } else { + navUserControls.classList.add('hidden'); + showView('auth'); + renderAuthView(); + } + } catch (error) { + console.error("Error in updateUI:", error); + handleSignOut("There was an error loading your session."); } } @@ -160,7 +167,20 @@ mainViews.admin.innerHTML = `

Admin Dashboard

-

Currently Punched In

    ${punchedInEntries.map(e => `
  • ${e.username}
    Since: ${formatDateTime(e.punch_in_time)}
  • `).join('') || '
  • None
  • '}
+ +
+

Currently Punched In

+
    ${punchedInEntries.map(e => ` +
  • + ${e.username} +
    + Since: ${formatDateTime(e.punch_in_time)} + +
    +
  • + `).join('') || '
  • None
  • '}
+
+

Pending Time Off Requests

${pendingRequests.map(r => ``).join('') || ''}
EmployeeDatesReasonActions
${r.username}${formatDate(r.start_date)} - ${formatDate(r.end_date)}${r.reason||''}
No pending requests.

Hours by Employee

${Object.keys(employeeTotals).map(u => ``).join('')}
EmployeeTotal Hours
${u}${formatDecimal(employeeTotals[u])}

Detailed Logs

${allTimeEntries.map(e => ``).join('')}
EmployeeInOutDurationActions
${e.username||'N/A'}${formatDateTime(e.punch_in_time)}${formatDateTime(e.punch_out_time)}${formatDecimal(new Date(e.punch_out_time) - new Date(e.punch_in_time))}
@@ -250,7 +270,7 @@ signOutBtn.addEventListener('click', () => handleSignOut()); updateUI(); console.log("Attempting to register service worker..."); - // Add the registration code here, inside the same script + if ('serviceWorker' in navigator) { window.addEventListener('load', () => { navigator.serviceWorker.register('/sw.js') @@ -263,7 +283,6 @@ }); } - - + \ No newline at end of file