Offline-Fallbacks für diary, poison, map + SW-Erweiterung
- sw.js: /api/places, /api/breeder/map-markers, /api/gassi-zeiten in _CACHEABLE_GET; /api/lost/report und /api/walks in _QUEUEABLE - diary.js: localStorage-Cache pro Hund, Fallback bei Offline mit Toast - poison.js: localStorage-Cache, Fallback bei Offline mit Toast (sicherheitsrelevant) - map.js: POI-Cache (places/poison/breeders) in localStorage, Offline-Toast + Fallback auf gecachte Daten
This commit is contained in:
parent
0c0daaad6b
commit
53fcb61933
6 changed files with 222 additions and 14 deletions
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
window.Page_diary = (() => {
|
||||
|
||||
const _CACHE_KEY = 'by_diary_cache';
|
||||
|
||||
// ----------------------------------------------------------
|
||||
// MODUL-STATE
|
||||
// ----------------------------------------------------------
|
||||
|
|
@ -324,6 +326,7 @@ window.Page_diary = (() => {
|
|||
async function _load() {
|
||||
const dog = _appState.activeDog;
|
||||
if (!dog) return;
|
||||
const cacheKey = _CACHE_KEY + '_' + dog.id;
|
||||
try {
|
||||
const params = { limit: LIMIT, offset: _offset };
|
||||
if (_searchQuery) params.q = _searchQuery;
|
||||
|
|
@ -331,6 +334,10 @@ window.Page_diary = (() => {
|
|||
const batch = await API.diary.list(dog.id, params);
|
||||
_entries = _entries.concat(batch);
|
||||
|
||||
if (_offset === 0 && !_searchQuery && !_filterMilestone) {
|
||||
try { localStorage.setItem(cacheKey, JSON.stringify({ ts: Date.now(), data: batch })); } catch {}
|
||||
}
|
||||
|
||||
// "Mehr laden" anzeigen wenn volle Page geladen wurde
|
||||
const loadMore = _container.querySelector('#diary-load-more');
|
||||
if (loadMore) {
|
||||
|
|
@ -339,7 +346,17 @@ window.Page_diary = (() => {
|
|||
|
||||
// Stats-Bar befüllen
|
||||
_renderStatsBar();
|
||||
} catch (err) {
|
||||
} catch {
|
||||
try {
|
||||
const raw = localStorage.getItem(cacheKey);
|
||||
if (raw) {
|
||||
const cached = JSON.parse(raw).data || [];
|
||||
_entries = cached;
|
||||
_renderStatsBar();
|
||||
UI.toast.info('Offline — zeige zuletzt geladene Einträge.');
|
||||
return;
|
||||
}
|
||||
} catch {}
|
||||
UI.toast.error('Einträge konnten nicht geladen werden.');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue