Feature: JETZT-Welt — Gassirunde+Übungs-Vorschlag-Balken, Desktop-Zahnrad entfernt, SW by-v648

This commit is contained in:
rene 2026-05-03 11:02:57 +02:00
parent 1d50bf1430
commit bb8ceaf114
5 changed files with 88 additions and 7 deletions

View file

@ -3,7 +3,7 @@
Router, State-Management, Navigation, Initialisierung.
============================================================ */
const APP_VER = '647'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
const APP_VER = '648'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
const APP_VERSION = '1.2.1'; // ← semantische Version, wird bei make release gesetzt
const IS_STAGING = location.hostname === 'staging.banyaro.app';

View file

@ -715,6 +715,33 @@ window.Worlds = (() => {
</div>
${alertHtml}
${streakHtml}
${user && dog ? `
<div id="wj-suggestions" style="display:flex;flex-direction:column;gap:8px">
<div class="world-reminder" id="wj-route-chip" data-wnav="routes">
<svg class="ph-icon" style="width:1.1rem;height:1.1rem;color:var(--c-primary)">
<use href="/icons/phosphor.svg#path"></use></svg>
<div style="flex:1;min-width:0">
<div style="font-size:9px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;
color:rgba(255,255,255,0.45);line-height:1">Gassirunde</div>
<div id="wj-route-val" style="font-size:var(--text-xs);font-weight:700;color:white;margin-top:3px;
white-space:nowrap;overflow:hidden;text-overflow:ellipsis">Berechne</div>
</div>
<svg class="ph-icon" style="width:.9rem;height:.9rem;color:rgba(255,255,255,0.35);flex-shrink:0">
<use href="/icons/phosphor.svg#arrow-right"></use></svg>
</div>
<div class="world-reminder" id="wj-exercise-chip" data-wnav="uebungen">
<svg class="ph-icon" style="width:1.1rem;height:1.1rem;color:var(--c-primary)">
<use href="/icons/phosphor.svg#target"></use></svg>
<div style="flex:1;min-width:0">
<div style="font-size:9px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;
color:rgba(255,255,255,0.45);line-height:1">Übung des Tages</div>
<div id="wj-exercise-val" style="font-size:var(--text-xs);font-weight:700;color:white;margin-top:3px;
white-space:nowrap;overflow:hidden;text-overflow:ellipsis">Lade</div>
</div>
<svg class="ph-icon" style="width:.9rem;height:.9rem;color:rgba(255,255,255,0.35);flex-shrink:0">
<use href="/icons/phosphor.svg#arrow-right"></use></svg>
</div>
</div>` : ''}
</div>
<div class="world-bottom">
<div class="world-section-label">Deine Bereiche</div>
@ -727,6 +754,59 @@ window.Worlds = (() => {
</div>
`;
el.querySelectorAll('[data-wnav]').forEach(e => e.addEventListener('click', () => navigateTo(e.dataset.wnav)));
if (user && dog) {
_loadJetztExercise(dog);
_loadJetztRoute();
}
}
async function _loadJetztExercise(dog) {
const valEl = document.getElementById('wj-exercise-val');
if (!valEl) return;
try {
const res = await _cachedGet(`dash_${dog.id}`, `/dogs/${dog.id}/welcome-dashboard`);
const ex = res.data?.daily_exercise;
valEl.textContent = ex?.name || '—';
} catch { valEl.textContent = '—'; }
}
async function _loadJetztRoute() {
const valEl = document.getElementById('wj-route-val');
if (!valEl) return;
// Tages-Cache (gleicher Key wie welcome.js)
const today = new Date().toISOString().slice(0, 10);
const cacheKey = 'by_daily_route_' + today;
const cached = localStorage.getItem(cacheKey);
if (cached) {
try { _applyJetztRoute(valEl, JSON.parse(cached)); return; } catch {}
}
let loc;
try { loc = await API.getLocation({ timeout: 5000, maximumAge: 300000 }); }
catch { valEl.textContent = 'Standort nötig'; return; }
const dayIdx = Math.floor(Date.now() / 86400000);
const km = [2, 4, 6][dayIdx % 3];
const seed = dayIdx % 5;
try {
const result = await API.post('/routes/suggest', { lat: loc.lat, lon: loc.lon, distance_km: km, seed });
if (!result?.gps_track?.length) { valEl.textContent = 'Keine Route gefunden'; return; }
localStorage.setItem(cacheKey, JSON.stringify(result));
// alte Einträge aufräumen
Object.keys(localStorage)
.filter(k => k.startsWith('by_daily_route_') && k !== cacheKey)
.forEach(k => localStorage.removeItem(k));
_applyJetztRoute(valEl, result);
} catch { valEl.textContent = 'Route nicht verfügbar'; }
}
function _applyJetztRoute(valEl, result) {
const durStr = result.dauer_min < 60
? `${result.dauer_min} min`
: `${Math.floor(result.dauer_min / 60)}h ${result.dauer_min % 60 > 0 ? ' ' + (result.dauer_min % 60) + 'min' : ''}`;
valEl.textContent = `${result.distanz_km} km · ${durStr}`;
}
// ── HUND WORLD ───────────────────────────────────────────────