From 7b8ee7e2b1015ec1f9d7923888c8e7614ee8d510 Mon Sep 17 00:00:00 2001 From: rene Date: Sun, 3 May 2026 20:54:11 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20Welten-Config=20=E2=80=94=20DB-Load=20be?= =?UTF-8?q?i=20jedem=20Login-Wechsel,=20einmalige=20localStorage=E2=86=92D?= =?UTF-8?q?B-Migration=20(SW=20by-v660)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/static/index.html | 8 ++++---- backend/static/js/app.js | 2 +- backend/static/js/worlds.js | 25 ++++++++++++++++--------- backend/static/sw.js | 2 +- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/backend/static/index.html b/backend/static/index.html index faa6b22..55a7e59 100644 --- a/backend/static/index.html +++ b/backend/static/index.html @@ -93,9 +93,9 @@ - - - + + + @@ -562,7 +562,7 @@ - + diff --git a/backend/static/js/app.js b/backend/static/js/app.js index bd21f75..1c14738 100644 --- a/backend/static/js/app.js +++ b/backend/static/js/app.js @@ -3,7 +3,7 @@ Router, State-Management, Navigation, Initialisierung. ============================================================ */ -const APP_VER = '659'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen +const APP_VER = '660'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen const APP_VERSION = '1.3.0'; // ← semantische Version, wird bei make release gesetzt const IS_STAGING = location.hostname === 'staging.banyaro.app'; diff --git a/backend/static/js/worlds.js b/backend/static/js/worlds.js index b0bbb84..e34d163 100644 --- a/backend/static/js/worlds.js +++ b/backend/static/js/worlds.js @@ -49,11 +49,6 @@ window.Worlds = (() => { _setupButtons(); _goTo(_cur, false); show(); - // Config aus DB laden (async, dann neu rendern wenn nötig) - await _loadConfigFromServer(); - // Welten parallel rendern - _renderJetzt(); - _renderHund(); } function show(worldIdx) { @@ -68,12 +63,17 @@ window.Worlds = (() => { if (worldIdx != null) _goTo(worldIdx, false); if (_cur === 2 && !_weltInited) { _weltInited = true; _renderWelt(); } - // Nach Login/Logout neu rendern + // Nach Login/Logout: Config aus DB laden, dann rendern const currentUserId = _state?.user?.id ?? null; if (currentUserId !== _lastUserId) { _lastUserId = currentUserId; - _renderJetzt(); - _renderHund(); + if (currentUserId) { + _loadConfigFromServer().then(() => { _renderJetzt(); _renderHund(); }); + } else { + _cfgCache = null; + _renderJetzt(); + _renderHund(); + } } } @@ -323,8 +323,15 @@ window.Worlds = (() => { try { localStorage.setItem('world_chips', JSON.stringify(_cfgCache)); } catch {} return; } + // Noch nichts in DB: lokale Config hochladen (einmalige Migration) + const local = (() => { try { return JSON.parse(localStorage.getItem('world_chips') || 'null'); } catch { return null; } })(); + if (local) { + _cfgCache = local; + API.put('/profile/world-config', { config: local }).catch(() => {}); + return; + } } catch {} - // Fallback: localStorage + // Fallback: localStorage → Default try { _cfgCache = JSON.parse(localStorage.getItem('world_chips') || 'null') || _DEFAULT_CONFIG; } catch { _cfgCache = _DEFAULT_CONFIG; } } diff --git a/backend/static/sw.js b/backend/static/sw.js index c022eca..90cdf3a 100644 --- a/backend/static/sw.js +++ b/backend/static/sw.js @@ -3,7 +3,7 @@ Offline-Cache + Push Notifications + Tile-Cache ============================================================ */ -const CACHE_VERSION = 'by-v659'; +const CACHE_VERSION = 'by-v660'; 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