- Add service worker with caching for build assets, static files, images, and pages - Add IndexedDB storage for recipes (brief and full data) - Add offline-db API endpoint for bulk recipe download - Add offline sync button component in header - Add offline-shell page for direct navigation fallback - Pre-cache __data.json for client-side navigation - Add +page.ts universal load functions with IndexedDB fallback - Add PWA manifest and icons for installability - Update recipe page to handle missing data gracefully
35 lines
876 B
TypeScript
35 lines
876 B
TypeScript
import { browser } from '$app/environment';
|
|
import { error } from '@sveltejs/kit';
|
|
|
|
export async function load({ params, data }) {
|
|
// Validate recipeLang parameter
|
|
if (params.recipeLang !== 'rezepte' && params.recipeLang !== 'recipes') {
|
|
throw error(404, 'Not found');
|
|
}
|
|
|
|
const lang = params.recipeLang === 'recipes' ? 'en' : 'de';
|
|
|
|
// Check if we're offline:
|
|
// 1. Browser reports offline (navigator.onLine === false)
|
|
// 2. Service worker returned offline flag (data.isOffline === true)
|
|
const isClientOffline = browser && (!navigator.onLine || data?.isOffline);
|
|
|
|
if (isClientOffline) {
|
|
// Return minimal data for offline mode
|
|
return {
|
|
session: null,
|
|
lang,
|
|
recipeLang: params.recipeLang,
|
|
isOffline: true
|
|
};
|
|
}
|
|
|
|
// Use server data when available (online mode)
|
|
return {
|
|
...data,
|
|
lang,
|
|
recipeLang: params.recipeLang,
|
|
isOffline: false
|
|
};
|
|
}
|