Owner directives (2026-10-10/11, verbatim in brief): show "no upcoming
appointments" when empty; show a month calendar with days and times
highlighted when there are events; stylize to fit every theme; keep the
widget weather-widget-sized.
Changes (status/ frontend + tests):
- status/js/calendar-widget.js: rewritten render path — chip states ("No
upcoming appointments" / next appointment with highlighted when-span),
month grid modal (cal-grid + prev/next nav, appointment days highlighted,
per-event time dots), upcoming list with day/time emphasis, month-following
fetch with window-authoritative event merge (via calendar-cache.js),
forced refresh on periodic tick + source mutations, local escapeHtml (was
an undefined global).
- status/js/calendar-cache.js (new): uid+start-keyed event cache; fetched
window is authoritative for entries starting inside it (deletions and
reschedules propagate), entries outside survive. Dual export (module +
window) for tests and browser bundle.
- status/build.js: calendar-cache.js bundled before calendar-widget.js.
- status/css/dashboard.css: DC-168 block — chip states, month grid, day
highlight states, dots, list/source rows, universal light-bg contrast
rules (color-mix; WCAG >= 4.5:1 verified for all 10 builtin themes, worst
4.60:1 ocean) + light-surface rules.
Tests: 20 total in __tests__/calendar — 9 in caldav-default-ns (extraction
incl. mixed docs, empty multistatus, namespace-aware fixture validation,
undeclared-prefix rejection both quote styles, positive declared-attr),
5 in dc168-cache-contract (merge, duplicate suppression, recurring uid+start,
window-authoritative removal on refetch, cross-window survival, ended-
exclusion), 6 in dc168-widget-contract (navigation fetch windows, forced-
refresh semantics, cache+widget integration, interval coverage). Existing
suites pass unmodified; eslint 0 errors on touched files.
119 lines
3.5 KiB
JavaScript
119 lines
3.5 KiB
JavaScript
const CACHE = 'dashcaddy-shell-c022807d83';
|
|
const PRECACHE = [
|
|
'/',
|
|
'/index.html',
|
|
'/css/themes.css',
|
|
'/css/dashboard.css',
|
|
'/css/driver.min.css',
|
|
'/css/onboarding.css',
|
|
'/dist/core.js',
|
|
'/dist/features.js',
|
|
'/dist/init.js',
|
|
'/dist/onboarding.js',
|
|
'/assets/fonts.css',
|
|
'/assets/site.webmanifest',
|
|
'/assets/favicon.svg',
|
|
'/assets/dashcaddy-favicon.ico',
|
|
'/assets/icon-192.png',
|
|
'/assets/icon-512.png',
|
|
'/assets/apple-touch-icon.png',
|
|
'/assets/dashcaddy-logo-dark.png',
|
|
'/assets/dashcaddy-logo-light.png',
|
|
'/assets/sami7777-logo.png',
|
|
'/assets/fonts/sami-grotesk/SamiGrotesk-Regular.woff2',
|
|
'/assets/fonts/sami-grotesk/SamiGrotesk-Medium.woff2',
|
|
'/assets/fonts/sami-grotesk/SamiGrotesk-Bold.woff2',
|
|
'/assets/fonts/DSEG7Classic-Bold.woff2',
|
|
'/assets/weather/clear-day.svg',
|
|
'/assets/weather/clear-night.svg',
|
|
'/assets/weather/partly-cloudy-day.svg',
|
|
'/assets/weather/partly-cloudy-night.svg',
|
|
'/assets/weather/cloudy.svg',
|
|
'/assets/weather/fog.svg',
|
|
'/assets/weather/drizzle.svg',
|
|
'/assets/weather/rain.svg',
|
|
'/assets/weather/sleet.svg',
|
|
'/assets/weather/snow.svg',
|
|
'/assets/weather/thunderstorm.svg',
|
|
'/assets/weather/wind.svg'
|
|
];
|
|
|
|
function isNavigationRequest(request) {
|
|
return request.mode === 'navigate';
|
|
}
|
|
|
|
function isStaticAsset(pathname) {
|
|
return pathname.startsWith('/assets/')
|
|
|| pathname.startsWith('/css/')
|
|
|| pathname.startsWith('/dist/');
|
|
}
|
|
|
|
async function networkFirst(request, preloadResponsePromise) {
|
|
const cache = await caches.open(CACHE);
|
|
try {
|
|
const preloadResponse = preloadResponsePromise ? await preloadResponsePromise : null;
|
|
if (preloadResponse) {
|
|
cache.put(request, preloadResponse.clone()).catch(() => {});
|
|
return preloadResponse;
|
|
}
|
|
const response = await fetch(request);
|
|
cache.put(request, response.clone()).catch(() => {});
|
|
return response;
|
|
} catch (_) {
|
|
return caches.match(request) || caches.match('/index.html');
|
|
}
|
|
}
|
|
|
|
async function staleWhileRevalidate(request) {
|
|
const cache = await caches.open(CACHE);
|
|
const cached = await cache.match(request);
|
|
|
|
const networkPromise = fetch(request)
|
|
.then((response) => {
|
|
cache.put(request, response.clone()).catch(() => {});
|
|
return response;
|
|
})
|
|
.catch(() => null);
|
|
|
|
if (cached) return cached;
|
|
return networkPromise.then((response) => response || Response.error());
|
|
}
|
|
|
|
self.addEventListener('install', (event) => {
|
|
self.skipWaiting();
|
|
event.waitUntil(
|
|
caches.open(CACHE).then((cache) =>
|
|
cache.addAll(PRECACHE.map((url) => new Request(url, { cache: 'reload' })))
|
|
)
|
|
);
|
|
});
|
|
|
|
self.addEventListener('activate', (event) => {
|
|
event.waitUntil((async () => {
|
|
const keys = await caches.keys();
|
|
await Promise.all(keys.filter((key) => key !== CACHE).map((key) => caches.delete(key)));
|
|
if ('navigationPreload' in self.registration) {
|
|
await self.registration.navigationPreload.enable();
|
|
}
|
|
await self.clients.claim();
|
|
})());
|
|
});
|
|
|
|
self.addEventListener('fetch', (event) => {
|
|
const { request } = event;
|
|
if (request.method !== 'GET') return;
|
|
|
|
const url = new URL(request.url);
|
|
if (url.origin !== self.location.origin) return;
|
|
if (url.pathname.startsWith('/api/v1/') || url.pathname.startsWith('/probe/')) return;
|
|
|
|
if (isNavigationRequest(request) || url.pathname === '/' || url.pathname.endsWith('/index.html')) {
|
|
event.respondWith(networkFirst(request, event.preloadResponse));
|
|
return;
|
|
}
|
|
|
|
if (isStaticAsset(url.pathname)) {
|
|
event.respondWith(staleWhileRevalidate(request));
|
|
}
|
|
});
|