Feature: App-Einstellungen in DB (preferred_theme neu, notes_ki+gassi_stunde schon drin) — geräteübergreifend sync (SW by-v785)

This commit is contained in:
rene 2026-05-08 19:06:29 +02:00
parent 2ff6d4dfe4
commit e8cf742911
8 changed files with 41 additions and 20 deletions

View file

@ -575,10 +575,10 @@
<div id="modal-container"></div>
<!-- JS: Reihenfolge ist wichtig — erst Basis, dann Features -->
<script src="/js/api.js?v=784"></script>
<script src="/js/ui.js?v=784"></script>
<script src="/js/app.js?v=784"></script>
<script src="/js/worlds.js?v=784"></script>
<script src="/js/api.js?v=785"></script>
<script src="/js/ui.js?v=785"></script>
<script src="/js/app.js?v=785"></script>
<script src="/js/worlds.js?v=785"></script>
<!-- Feature-Seiten werden lazy geladen -->

View file

@ -3,7 +3,7 @@
Router, State-Management, Navigation, Initialisierung.
============================================================ */
const APP_VER = '784'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
const APP_VER = '785'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
const APP_VERSION = '1.5.0'; // ← semantische Version, wird bei make release gesetzt
const IS_STAGING = location.hostname === 'staging.banyaro.app';
// Cache-Bust-Parameter nach Update-Reload sofort entfernen
@ -529,6 +529,9 @@ const App = (() => {
navigate('onboarding');
}
// Theme aus DB-Profil übernehmen (überschreibt localStorage-Wert)
_applyUserTheme(state.user);
// Drei Welten nach Login starten (falls noch nicht initialisiert)
if (window.Worlds) window.Worlds.init(state);
@ -607,6 +610,15 @@ const App = (() => {
navigate('welcome', false);
}
function _applyUserTheme(user) {
const theme = user?.preferred_theme;
if (!theme || theme === 'system') return; // System-Einstellung: nichts tun
localStorage.setItem('by_theme', theme);
const html = document.documentElement;
if (theme === 'dark') html.setAttribute('data-theme', 'dark');
else if (theme === 'light') html.setAttribute('data-theme', 'light');
}
function _showVerifyBanner() {
const banner = document.getElementById('verify-banner');
if (!banner) return;

View file

@ -315,9 +315,9 @@ window.Page_settings = (() => {
font-size:var(--text-sm);
font-family:inherit;
cursor:pointer">
<option value="system" ${(localStorage.getItem('by_theme')||'system') === 'system' ? 'selected' : ''}>System</option>
<option value="light" ${localStorage.getItem('by_theme') === 'light' ? 'selected' : ''}>Hell</option>
<option value="dark" ${localStorage.getItem('by_theme') === 'dark' ? 'selected' : ''}>Dunkel</option>
<option value="system" ${(u.preferred_theme||localStorage.getItem('by_theme')||'system') === 'system' ? 'selected' : ''}>System</option>
<option value="light" ${(u.preferred_theme||localStorage.getItem('by_theme')) === 'light' ? 'selected' : ''}>Hell</option>
<option value="dark" ${(u.preferred_theme||localStorage.getItem('by_theme')) === 'dark' ? 'selected' : ''}>Dunkel</option>
</select>
</div>
@ -849,22 +849,22 @@ window.Page_settings = (() => {
}
});
document.getElementById('select-theme')?.addEventListener('change', e => {
document.getElementById('select-theme')?.addEventListener('change', async e => {
const val = e.target.value;
localStorage.setItem('by_theme', val);
localStorage.setItem('by_theme', val); // lokaler Cache für schnellen Start
const html = document.documentElement;
if (val === 'dark') {
html.setAttribute('data-theme', 'dark');
} else if (val === 'light') {
html.setAttribute('data-theme', 'light');
} else {
html.removeAttribute('data-theme');
}
if (val === 'dark') html.setAttribute('data-theme', 'dark');
else if (val === 'light') html.setAttribute('data-theme', 'light');
else html.removeAttribute('data-theme');
UI.toast.info(
val === 'dark' ? 'Dark Mode aktiviert.' :
val === 'light' ? 'Hell-Modus aktiviert.' :
'Theme folgt der Systemeinstellung.'
);
try {
await API.patch('/profile', { preferred_theme: val });
if (_appState?.user) _appState.user.preferred_theme = val;
} catch { /* ignorieren — localStorage-Fallback greift */ }
});
document.getElementById('toggle-pocket-mode')?.addEventListener('change', e => {

View file

@ -3,7 +3,7 @@
Offline-Cache + Push Notifications + Tile-Cache
============================================================ */
const CACHE_VERSION = 'by-v784';
const CACHE_VERSION = 'by-v785';
const CACHE_STATIC = `${CACHE_VERSION}-static`;
const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten
const CACHE_API = 'ban-yaro-api-v1'; // API-Response-Cache