Feature: Offline-Banner, Online-Toast und API-Offline-Fehlerbehandlung

- #offline-banner in index.html (display:none, fixed oben) mit Inline-Script für window.online/offline Events
- Wieder-online Toast via UI.toast.success
- api.js fängt network-Fehler und SW-503-Offline-Antworten ab und zeigt UI.toast.warning
- SW-Cache auf by-v210 gebumpt (api.js + components.css geändert)
This commit is contained in:
rene 2026-04-18 18:40:05 +02:00
parent e98ce0d232
commit eb72d6f675
4 changed files with 154 additions and 4 deletions

View file

@ -33,7 +33,9 @@ const API = (() => {
try {
response = await fetch(`/api${path}`, config);
} catch (err) {
throw new APIError('Keine Verbindung zum Server.', 0, 'network');
const offlineMsg = 'Kein Internet — du bist offline.';
if (window.UI && UI.toast) UI.toast.warning(offlineMsg, 4000);
throw new APIError(offlineMsg, 0, 'network');
}
// 204 No Content
@ -48,7 +50,12 @@ const API = (() => {
if (!response.ok) {
const message = data?.detail || data?.message || `Fehler ${response.status}`;
throw new APIError(message, response.status, data?.code);
// SW gibt bei Offline-Anfragen 503 + 'Offline — keine Verbindung.' zurück
const isOffline = response.status === 503 && message.startsWith('Offline');
if (isOffline && window.UI && UI.toast) {
UI.toast.warning('Kein Internet — du bist offline.', 4000);
}
throw new APIError(message, response.status, isOffline ? 'network' : data?.code);
}
return data;
@ -272,6 +279,21 @@ const API = (() => {
updateRequest(id, status) { return patch(`/sitting/requests/${id}`, { status }); },
};
// ----------------------------------------------------------
// RATINGS
// ----------------------------------------------------------
const ratings = {
rate(targetType, targetId, stars, kommentar = null) {
return post('/ratings', { target_type: targetType, target_id: targetId, stars, kommentar });
},
list(targetType, targetId) {
return get(`/ratings/${targetType}/${targetId}`);
},
mine(targetType, targetId) {
return get(`/ratings/me/${targetType}/${targetId}`);
},
};
// ----------------------------------------------------------
// FORUM
// ----------------------------------------------------------
@ -508,7 +530,7 @@ const API = (() => {
get, post, put, patch, del, upload,
auth, dogs, diary, health, tieraerzte, poison,
places, routes, walks, events, sitting, forum, lost, knigge, weather, push,
friends, chat, webcal, importData, sharing, widget, notifications, services,
friends, chat, webcal, importData, sharing, widget, notifications, services, ratings,
subscribeToPush, getLocation,
APIError,
};