Release v1.5.0

This commit is contained in:
rene 2026-05-06 19:31:35 +02:00
commit ed9c482ae5
17 changed files with 837 additions and 267 deletions

View file

@ -3,8 +3,8 @@
Router, State-Management, Navigation, Initialisierung.
============================================================ */
const APP_VER = '727'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
const APP_VERSION = '1.4.0'; // ← semantische Version, wird bei make release gesetzt
const APP_VER = '741'; // ← 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';
const App = (() => {
@ -43,7 +43,7 @@ const App = (() => {
routes: { title: 'Routen', module: null },
events: { title: 'Events', module: null },
poison: { title: 'Giftköder-Alarm', module: null },
walks: { title: 'Gassi-Treffen', module: null, requiresAuth: true },
walks: { title: 'Gassi-Treffen', module: null, requiresAuth: true, requiresPro: true },
sitting: { title: 'Sitting', module: null, requiresAuth: true },
forum: { title: 'Forum', module: null },
wiki: { title: 'Wiki', module: null },
@ -51,12 +51,12 @@ const App = (() => {
movies: { title: 'Filme', module: null },
trainingsplaene: { title: 'Trainingspläne', module: null },
uebungen: { title: 'Übungsbibliothek', module: null },
notes: { title: 'Notizblock', module: null, requiresAuth: true },
notes: { title: 'Notizblock', module: null, requiresAuth: true, requiresPro: true },
'erste-hilfe': { title: 'Erste Hilfe', module: null },
settings: { title: 'Einstellungen', module: null },
lost: { title: 'Verlorener Hund', module: null },
friends: { title: 'Freunde', module: null, requiresAuth: true },
chat: { title: 'Nachrichten', module: null, requiresAuth: true },
friends: { title: 'Freunde', module: null, requiresAuth: true, requiresPro: true },
chat: { title: 'Nachrichten', module: null, requiresAuth: true, requiresPro: true },
social: { title: 'Social Media', module: null, requiresAuth: true },
admin: { title: 'Admin', module: null, requiresAuth: true },
moderation: { title: 'Moderation', module: null, requiresAuth: true },
@ -74,14 +74,28 @@ const App = (() => {
expenses: { title: 'Ausgaben', module: null, requiresAuth: true },
recalls: { title: 'Rückrufe', module: null },
adoption: { title: 'Adoption', module: null },
playdate: { title: 'Playdate', module: null, requiresAuth: true },
playdate: { title: 'Playdate', module: null, requiresAuth: true, requiresPro: true },
wetter: { title: 'Wetter', module: null },
ernaehrung: { title: 'Ernährung', module: null, requiresAuth: true },
ernaehrung: { title: 'Ernährung', module: null, requiresAuth: true, requiresPro: true },
personality: { title: 'Persönlichkeitstest', module: null },
reise: { title: 'Reise mit Hund', module: null },
reise: { title: 'Reise mit Hund', module: null, requiresPro: true },
hilfe: { title: 'Hilfe & FAQ', module: null },
};
// ----------------------------------------------------------
// TIER-CHECK — Frontend-Pendant zu has_pro_access() in auth.py
// ----------------------------------------------------------
function _hasPro(user) {
if (!user) return false;
const t = user.subscription_tier || 'standard';
// _test-Tiers simulieren ihren Tier ohne Admin-Override — so sieht Admin was echte User sehen
if (t.endsWith('_test')) return ['pro_test','breeder_test'].includes(t);
// Normale Prüfung: Admin/Mod/Social bekommen immer Pro
if (user.rolle === 'admin' || user.rolle === 'moderator') return true;
if (user.is_moderator || user.is_social_media) return true;
return ['pro','breeder'].includes(t);
}
// ----------------------------------------------------------
// AUTH GUARD — Login-Gate Texte pro Seite
// ----------------------------------------------------------
@ -142,6 +156,34 @@ const App = (() => {
return;
}
// Pro-Guard — nur wenn User eingeloggt aber kein Pro-Zugang
if (page.requiresPro && state.user && !_hasPro(state.user)) {
const container = document.querySelector(`#page-${pageId} .page-body`);
if (container) {
container.innerHTML = `
<div style="max-width:420px;margin:40px auto;padding:var(--space-6) var(--space-4);text-align:center">
<div style="font-size:3rem;margin-bottom:var(--space-4)"></div>
<h2 style="font-size:var(--text-xl);font-weight:800;margin:0 0 var(--space-3)">Ban Yaro Pro</h2>
<p style="color:var(--c-text-secondary);margin:0 0 var(--space-6);line-height:1.6">
Dieses Feature ist Teil von Ban Yaro Pro verfügbar wenn wir die nächste Stufe zünden.<br>
Du wirst benachrichtigt wenn es soweit ist.
</p>
<div style="background:var(--c-bg-card);border:1px solid var(--c-border);border-radius:var(--radius-lg);
padding:var(--space-4);text-align:left;font-size:var(--text-sm);color:var(--c-text-secondary)">
<div style="font-weight:700;margin-bottom:var(--space-2);color:var(--c-text)">Ban Yaro Pro enthält:</div>
<ul style="margin:0;padding-left:var(--space-5);display:flex;flex-direction:column;gap:var(--space-1)">
<li>Mehrere Hunde verwalten</li>
<li>KI-Trainer für personalisiertes Training</li>
<li>Direktnachrichten &amp; Freunde</li>
<li>Gassi-Treffen, Playdate, Ernährung, Reise</li>
<li>Notizblock</li>
</ul>
</div>
</div>`;
}
return;
}
if (page.module) {
const hasParams = params && Object.keys(params).length > 0;
if (hasParams) {
@ -819,6 +861,7 @@ const App = (() => {
try { localStorage.removeItem('by_wissen_open'); } catch (_) {}
_initVersionCheck();
await _checkAuth();
// Einladungslink /teilen/{token} → direkt annehmen
@ -916,6 +959,124 @@ const App = (() => {
});
}
// ----------------------------------------------------------
// ----------------------------------------------------------
// VERSION-CHECK — persistentes Banner wenn neue Version verfügbar
// ----------------------------------------------------------
let _updateBannerShown = false;
async function _checkVersion() {
try {
const r = await fetch('/api/version', { cache: 'no-store' });
if (!r.ok) return;
const { version } = await r.json();
if (version && version !== APP_VER && !_updateBannerShown) {
_updateBannerShown = true;
_showUpdateBanner(version);
}
} catch { /* offline — ignorieren */ }
}
function _showUpdateBanner(newVersion) {
const isIos = /iphone|ipad|ipod/i.test(navigator.userAgent);
const existing = document.getElementById('app-update-banner');
if (existing) return;
const banner = document.createElement('div');
banner.id = 'app-update-banner';
banner.style.cssText = [
'position:fixed;bottom:calc(env(safe-area-inset-bottom,0px) + 72px);left:12px;right:12px',
'z-index:9000;background:var(--c-primary);color:#fff;border-radius:16px',
'padding:14px 16px;box-shadow:0 4px 20px rgba(0,0,0,0.3)',
'display:flex;flex-direction:column;gap:10px',
].join(';');
banner.innerHTML = `
<div style="display:flex;align-items:center;justify-content:space-between;gap:10px">
<div>
<div style="font-weight:700;font-size:var(--text-sm)">
Neue Version verfügbar (v${newVersion})
</div>
<div style="font-size:var(--text-xs);opacity:0.85;margin-top:2px">
Tippe auf Aktualisieren um die neueste Version zu laden.
</div>
</div>
<div style="display:flex;gap:8px;flex-shrink:0">
<button id="upd-btn-reload"
style="background:rgba(255,255,255,0.2);border:1px solid rgba(255,255,255,0.4);
color:#fff;border-radius:10px;padding:8px 14px;cursor:pointer;
font-size:var(--text-sm);font-weight:700;white-space:nowrap">
Aktualisieren
</button>
<button id="upd-btn-close"
style="background:none;border:none;color:rgba(255,255,255,0.7);
cursor:pointer;font-size:1.1rem;padding:4px 6px;line-height:1"></button>
</div>
</div>
<div id="upd-ios-hint" style="display:none;font-size:var(--text-xs);
background:rgba(0,0,0,0.2);border-radius:10px;padding:10px 12px;line-height:1.6">
${isIos
? `Falls die App nach dem Aktualisieren noch die alte Version zeigt:<br>
<strong>1.</strong> Drücke lange auf das App-Icon am Homescreen<br>
<strong>2.</strong> Wähle App entfernen" (nur das Symbol, keine Daten)<br>
<strong>3.</strong> Öffne banyaro.app in Safari und füge die App erneut hinzu`
: `Falls die Seite noch die alte Version zeigt:<br>
Drücke <strong>Cmd+Shift+R</strong> (Mac) bzw. <strong>Ctrl+Shift+R</strong> (Windows/Android Chrome) für einen harten Reload.`}
</div>
`;
document.body.appendChild(banner);
banner.querySelector('#upd-btn-close').addEventListener('click', () => banner.remove());
banner.querySelector('#upd-btn-reload').addEventListener('click', async () => {
const btn = banner.querySelector('#upd-btn-reload');
btn.textContent = 'Lädt…';
btn.disabled = true;
sessionStorage.setItem('by_update_reload', APP_VER);
try {
// SW aktivieren + alle Caches leeren für sauberen Reload
const reg = await navigator.serviceWorker?.getRegistration();
if (reg?.waiting) reg.waiting.postMessage({ type: 'SKIP_WAITING' });
await reg?.update();
const keys = await caches.keys();
await Promise.all(keys.map(k => caches.delete(k)));
} catch { /* ignorieren */ }
setTimeout(() => location.reload(), 600);
});
}
function _initVersionCheck() {
// Beim Start nach 10 Sekunden prüfen (nicht sofort — Prio für Auth)
setTimeout(_checkVersion, 10_000);
// Dann alle 30 Minuten
setInterval(_checkVersion, 30 * 60_000);
// Beim Wiedereinstieg in die App
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') _checkVersion();
});
// Nach Reload: war das ein Update-Reload? Falls Version immer noch alt → iOS-Hinweis
const reloadVer = sessionStorage.getItem('by_update_reload');
if (reloadVer && reloadVer === APP_VER) {
// Version hat sich nicht geändert nach Reload → iOS-Cache-Problem
sessionStorage.removeItem('by_update_reload');
setTimeout(() => {
fetch('/api/version', { cache: 'no-store' })
.then(r => r.json())
.then(({ version }) => {
if (version && version !== APP_VER) {
_updateBannerShown = true;
_showUpdateBanner(version);
// iOS-Hinweis sofort aufklappen
setTimeout(() => {
document.getElementById('upd-ios-hint')?.style.setProperty('display', 'block');
}, 300);
}
}).catch(() => {});
}, 2000);
}
}
// ----------------------------------------------------------
// ÖFFENTLICHE API
// (andere Module können App.state, App.navigate etc. nutzen)