feat: extend PWA offline support to all recipe routes and glaube pages
- Add offline support for category, tag, icon list pages - Add offline support for favorites page (stores locally for offline) - Add offline support for season list page - Cache root page and glaube pages for offline access - Dynamically discover glaube routes at build time using Vite glob - Add db functions for getAllCategories, getAllTags, getAllIcons - Pre-cache __data.json for all category, tag, icon, season subroutes - Update service worker to cache glaube and root page responses
This commit is contained in:
@@ -1,10 +1,40 @@
|
||||
import type { PageLoad } from "./$types";
|
||||
import { browser } from '$app/environment';
|
||||
import { isOffline, canUseOfflineData } from '$lib/offline/helpers';
|
||||
import { getAllIcons, isOfflineDataAvailable } from '$lib/offline/db';
|
||||
|
||||
export async function load({ fetch }) {
|
||||
let current_month = new Date().getMonth() + 1
|
||||
const res_icons = await fetch(`/api/rezepte/items/icon`);
|
||||
const item = await res_icons.json();
|
||||
return {
|
||||
icons: item,
|
||||
};
|
||||
export const load: PageLoad = async ({ fetch }) => {
|
||||
// Check if we should use offline data
|
||||
if (browser && isOffline() && canUseOfflineData()) {
|
||||
try {
|
||||
const hasOfflineData = await isOfflineDataAvailable();
|
||||
if (hasOfflineData) {
|
||||
const icons = await getAllIcons();
|
||||
return { icons, isOffline: true };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load offline icons:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Online mode - fetch from API
|
||||
try {
|
||||
const res_icons = await fetch(`/api/rezepte/items/icon`);
|
||||
const icons = await res_icons.json();
|
||||
return { icons, isOffline: false };
|
||||
} catch (error) {
|
||||
// Network error - try offline fallback
|
||||
if (browser && canUseOfflineData()) {
|
||||
try {
|
||||
const hasOfflineData = await isOfflineDataAvailable();
|
||||
if (hasOfflineData) {
|
||||
const icons = await getAllIcons();
|
||||
return { icons, isOffline: true };
|
||||
}
|
||||
} catch (offlineError) {
|
||||
console.error('Failed to load offline icons:', offlineError);
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user