Fix: Welten-Config — DB-Load bei jedem Login-Wechsel, einmalige localStorage→DB-Migration (SW by-v660)
This commit is contained in:
parent
71a13d695e
commit
7b8ee7e2b1
4 changed files with 22 additions and 15 deletions
|
|
@ -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; }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue