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,43 @@
|
||||
import type { PageLoad } from "./$types";
|
||||
import { browser } from '$app/environment';
|
||||
import { isOffline, canUseOfflineData } from '$lib/offline/helpers';
|
||||
import { getAllCategories, isOfflineDataAvailable } from '$lib/offline/db';
|
||||
|
||||
export async function load({ fetch, params}) {
|
||||
export const load: PageLoad = async ({ fetch, params }) => {
|
||||
const isEnglish = params.recipeLang === 'recipes';
|
||||
const apiBase = isEnglish ? '/api/recipes' : '/api/rezepte';
|
||||
|
||||
const res = await fetch(`${apiBase}/items/category`);
|
||||
const categories= await res.json();
|
||||
return {categories}
|
||||
// Check if we should use offline data
|
||||
if (browser && isOffline() && canUseOfflineData()) {
|
||||
try {
|
||||
const hasOfflineData = await isOfflineDataAvailable();
|
||||
if (hasOfflineData) {
|
||||
const categories = await getAllCategories();
|
||||
return { categories, isOffline: true };
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to load offline categories:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Online mode - fetch from API
|
||||
try {
|
||||
const res = await fetch(`${apiBase}/items/category`);
|
||||
const categories = await res.json();
|
||||
return { categories, isOffline: false };
|
||||
} catch (error) {
|
||||
// Network error - try offline fallback
|
||||
if (browser && canUseOfflineData()) {
|
||||
try {
|
||||
const hasOfflineData = await isOfflineDataAvailable();
|
||||
if (hasOfflineData) {
|
||||
const categories = await getAllCategories();
|
||||
return { categories, isOffline: true };
|
||||
}
|
||||
} catch (offlineError) {
|
||||
console.error('Failed to load offline categories:', offlineError);
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user