feat: add favorites panel to meal generator, remove redundant Another one button
- Add clickable favorites counter with expandable panel - Render saved recipes list with remove button - Remove duplicate 'Another one' button (Generate already covers it) - Sync favorite button state when removing from panel
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
const CACHE_NAME = "randify-v1";
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(self.clients.claim());
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", (event) => {
|
||||
const { request } = event;
|
||||
const isNavigate = request.mode === "navigate";
|
||||
const isSameOrigin = new URL(request.url).origin === self.location.origin;
|
||||
|
||||
if (!isSameOrigin) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isNavigate) {
|
||||
// Network-first for HTML pages: fresh content when online,
|
||||
// fallback to cache when offline.
|
||||
event.respondWith(
|
||||
fetch(request)
|
||||
.then((response) => {
|
||||
if (response && response.status === 200) {
|
||||
const clone = response.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(request, clone));
|
||||
}
|
||||
return response;
|
||||
})
|
||||
.catch(() => caches.match(request)),
|
||||
);
|
||||
} else {
|
||||
// Cache-first for static assets (JS, CSS, SVG, fonts, etc.)
|
||||
event.respondWith(
|
||||
caches.match(request).then((cached) => {
|
||||
if (cached) {
|
||||
return cached;
|
||||
}
|
||||
return fetch(request).then((response) => {
|
||||
if (
|
||||
!response ||
|
||||
response.status !== 200 ||
|
||||
response.type !== "basic"
|
||||
) {
|
||||
return response;
|
||||
}
|
||||
const clone = response.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(request, clone));
|
||||
return response;
|
||||
});
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user