From 47bd54afec3391de1043acc4f132a1def4ce30ca Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Thu, 6 Aug 2026 14:11:40 +0000 Subject: [PATCH] Fix week nav anchor, timesheet sync range, and in-progress clock entries MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Week Prev/Next/Today now anchor to this Monday instead of today, so navigation stays week-aligned - Timesheet sync no longer pulls into the future — capped at today while shift-fetching still covers the full displayed week - Roster pivot skips entries that are still clocked in with no clock-out yet, instead of showing them as 0 hours Co-Authored-By: Claude Sonnet 5 --- frontend/dist/manifest.webmanifest | 2 +- frontend/dist/sw.js | 2 +- frontend/src/pages/Planner.js | 23 ++++++++++++++++------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/frontend/dist/manifest.webmanifest b/frontend/dist/manifest.webmanifest index 695f419..49c6958 100644 --- a/frontend/dist/manifest.webmanifest +++ b/frontend/dist/manifest.webmanifest @@ -1 +1 @@ -{"name":"HK Planner","short_name":"HK Planner","start_url":"/hk-planner/","display":"standalone","background_color":"#2d6a4f","theme_color":"#2d6a4f","lang":"en","scope":"/hk-planner/","icons":[{"src":"/hk-planner/icons/icon-192.png","sizes":"192x192","type":"image/png"},{"src":"/hk-planner/icons/icon-512.png","sizes":"512x512","type":"image/png"}]} +{"name":"HK Planner","short_name":"HK Planner","start_url":"/hk-planner/","display":"standalone","background_color":"#2d6a4f","theme_color":"#2d6a4f","lang":"en","scope":"/","icons":[{"src":"/hk-planner/icons/icon-192.png","sizes":"192x192","type":"image/png"},{"src":"/hk-planner/icons/icon-512.png","sizes":"512x512","type":"image/png"}]} diff --git a/frontend/dist/sw.js b/frontend/dist/sw.js index 389bde4..d7d8d09 100644 --- a/frontend/dist/sw.js +++ b/frontend/dist/sw.js @@ -1 +1 @@ -if(!self.define){let e,i={};const n=(n,s)=>(n=new URL(n+".js",s).href,i[n]||new Promise(i=>{if("document"in self){const e=document.createElement("script");e.src=n,e.onload=i,document.head.appendChild(e)}else e=n,importScripts(n),i()}).then(()=>{let e=i[n];if(!e)throw new Error(`Module ${n} didn’t register its module`);return e}));self.define=(s,r)=>{const o=e||("document"in self?document.currentScript.src:"")||location.href;if(i[o])return;let t={};const c=e=>n(e,o),d={module:{uri:o},exports:t,require:c};i[o]=Promise.all(s.map(e=>d[e]||c(e))).then(e=>(r(...e),t))}}define(["./workbox-9c191d2f"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"a2c395d8c225f1b3ea12388f15189bce"},{url:"index.html",revision:"4f26c3459b65391beb1152aac0e652f9"},{url:"icons/icon-512.png",revision:"c32202b9deed67ef38331f63dec9d1c8"},{url:"icons/icon-192.png",revision:"46ece317d50d10b8f5e225e073b3221d"},{url:"assets/index-BdIiqds1.js",revision:null},{url:"assets/index-B7_UXJgZ.css",revision:null},{url:"manifest.webmanifest",revision:"c2510de876adb84db0c4b300b71216fa"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("/hk-planner/index.html"),{denylist:[/\/api\//]}))}); +if(!self.define){let e,i={};const n=(n,s)=>(n=new URL(n+".js",s).href,i[n]||new Promise(i=>{if("document"in self){const e=document.createElement("script");e.src=n,e.onload=i,document.head.appendChild(e)}else e=n,importScripts(n),i()}).then(()=>{let e=i[n];if(!e)throw new Error(`Module ${n} didn’t register its module`);return e}));self.define=(s,r)=>{const o=e||("document"in self?document.currentScript.src:"")||location.href;if(i[o])return;let t={};const c=e=>n(e,o),d={module:{uri:o},exports:t,require:c};i[o]=Promise.all(s.map(e=>d[e]||c(e))).then(e=>(r(...e),t))}}define(["./workbox-9c191d2f"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"a2c395d8c225f1b3ea12388f15189bce"},{url:"index.html",revision:"4f26c3459b65391beb1152aac0e652f9"},{url:"icons/icon-512.png",revision:"c32202b9deed67ef38331f63dec9d1c8"},{url:"icons/icon-192.png",revision:"46ece317d50d10b8f5e225e073b3221d"},{url:"assets/index-BdIiqds1.js",revision:null},{url:"assets/index-B7_UXJgZ.css",revision:null},{url:"manifest.webmanifest",revision:"0e833a539081835e9d26b49e8a28fd33"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("/hk-planner/index.html"),{denylist:[/\/api\//]}))}); diff --git a/frontend/src/pages/Planner.js b/frontend/src/pages/Planner.js index 3dd05bb..b76c02d 100644 --- a/frontend/src/pages/Planner.js +++ b/frontend/src/pages/Planner.js @@ -7,6 +7,12 @@ function todayStr() { const d = new Date(); return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; } +function thisMonday() { + const d = new Date(); + const diff = (d.getDay() + 6) % 7; // days since Monday (Mon=0 … Sun=6) + d.setDate(d.getDate() - diff); + return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`; +} function offsetDate(s, days) { const [y, m, d] = s.split('-').map(Number); const dt = new Date(y, m - 1, d); @@ -137,7 +143,7 @@ export function Planner() { setLoading(true); setError(''); const today = todayStr(); - const ws = weekStartRef.current || today; + const ws = weekStartRef.current || thisMonday(); const wsEnd = offsetDate(ws, 6); const lv = lvArg !== undefined ? (lvArg || offsetDate(today, -1)) : (lastViewed || savedLastReviewed || offsetDate(today, -1)); try { @@ -199,8 +205,7 @@ export function Planner() { return () => window.removeEventListener('beforeunload', onUnload); }, [staff, pickup, adjustments]); function handleWeekOffset(days) { - const today = todayStr(); - const newStart = offsetDate(weekStartRef.current || today, days); + const newStart = offsetDate(weekStartRef.current || thisMonday(), days); weekStartRef.current = newStart; setWeekStart(newStart); stampLastReviewed(); @@ -272,11 +277,13 @@ export function Planner() { if (!bookings) return; const start = bookings.dates[0]; - const end = bookings.dates[bookings.dates.length - 1]; + const today = todayStr(); + const end = bookings.dates[bookings.dates.length - 1] > today ? today : bookings.dates[bookings.dates.length - 1]; setTimesheetSyncing(true); try { await syncTimesheets(start, end); - const shifts = await getWorkforceShifts(start, end); + const wsEnd = bookings.dates[bookings.dates.length - 1]; + const shifts = await getWorkforceShifts(start, wsEnd); setWfShifts(shifts); flash('Timesheets pulled from Workforce'); } @@ -303,8 +310,7 @@ export function Planner() { // ── Required hours (memoised on state changes) ──────────────────────────── const required = bookings ? calcRequired(bookings, timeReqs, pickup, generalTasks, adjustments) : null; // ── Render ────────────────────────────────────────────────────────────────── - const today = todayStr(); - const displayWeekStart = weekStart || today; + const displayWeekStart = weekStart || thisMonday(); return (_jsxs("div", { style: { padding: '1.5rem', maxWidth: '1600px' }, children: [_jsxs("div", { style: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: '0.75rem', marginBottom: '1.25rem' }, children: [_jsxs("div", { children: [_jsx("h1", { style: { fontSize: '1.15rem', fontWeight: 700, color: 'var(--text-dark)' }, children: "Housekeeping Planner" }), bookings && (_jsxs("p", { style: { fontSize: '0.8rem', color: 'var(--text-mid)', marginTop: '0.1rem' }, children: [fmtDate(bookings.dates[0]), " \u2013 ", fmtDate(bookings.dates[bookings.dates.length - 1])] }))] }), _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: '0.4rem', marginLeft: 'auto', flexWrap: 'wrap' }, children: [_jsx(CtrlBtn, { onClick: () => handleWeekOffset(-7), children: "\u2039 Prev" }), _jsx(CtrlBtn, { onClick: handleWeekToday, primary: true, children: "Today" }), _jsx(CtrlBtn, { onClick: () => handleWeekOffset(7), children: "Next \u203A" }), _jsx("input", { type: "date", value: displayWeekStart, onChange: e => { if (e.target.value) { const v = e.target.value; weekStartRef.current = v; @@ -458,6 +464,9 @@ function pivotWfShifts(wfShifts, dates) { if (!day) continue; for (const s of day.staff) { + // Skip in-progress timesheet entries — clocked in but no clock-out time yet + if (s.times === '?' && s.hours === 0) + continue; if (!members[s.id]) members[s.id] = { id: s.id, name: s.name, days: {} }; members[s.id].days[date] = { hours: s.hours, times: s.times, status: s.status };