Herden/Gang-System + Online-Praesenz
- V11-Tabellen genutzt: Gruppen gruenden/beitreten/verlassen (group_create/join/leave) - Praesenz: last_seen + current_room werden bei state-Polls gesetzt, heartbeat fuer Landing - groups_my liefert Mitglieder mit Online-Status und aktueller Lobby - index.html: 'Deine Herde'-Sektion (nur eingeloggt) mit Live-Uebersicht + 20s-Polling Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
6b21658a70
commit
f22007003a
2 changed files with 175 additions and 1 deletions
96
index.html
96
index.html
|
|
@ -149,6 +149,25 @@
|
|||
.cookie .btn{font-size:14px;padding:11px 18px}
|
||||
.hidden{display:none!important}
|
||||
|
||||
/* Deine Herde */
|
||||
.herd-actions{display:flex;gap:10px;max-width:520px;margin:0 auto 26px;flex-wrap:wrap}
|
||||
.herd-actions input{flex:1;min-width:180px;background:#fff;border:1.5px solid var(--line);
|
||||
border-radius:999px;padding:12px 18px;font-size:15px;font-family:inherit;outline:none;color:var(--text)}
|
||||
.herd-actions input:focus{border-color:var(--accent-deep)}
|
||||
.herd-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(260px,1fr));gap:16px}
|
||||
.herd-card{background:#fff;border:1px solid var(--line);border-radius:var(--radius);padding:20px;box-shadow:var(--shadow)}
|
||||
.herd-card-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}
|
||||
.herd-card-head h3{font-size:18px;color:var(--navy)}
|
||||
.herd-leave{background:transparent;border:none;color:var(--muted);font-size:12px;font-weight:600;cursor:pointer}
|
||||
.herd-leave:hover{color:#c0392b}
|
||||
.herd-member{display:flex;align-items:center;gap:10px;padding:7px 0;border-top:1px solid var(--line);font-size:14px}
|
||||
.herd-member:first-of-type{border-top:none}
|
||||
.herd-dot{width:9px;height:9px;border-radius:50%;flex-shrink:0;background:#c2cad8}
|
||||
.herd-dot.on{background:var(--accent);box-shadow:0 0 0 3px rgba(62,204,92,.2)}
|
||||
.herd-name{font-weight:700}
|
||||
.herd-status{margin-left:auto;font-size:12.5px;color:var(--muted)}
|
||||
.herd-status.playing{color:var(--accent-deep);font-weight:700}
|
||||
|
||||
/* Icons (Lucide) */
|
||||
svg.lucide{width:18px;height:18px;stroke-width:2;vertical-align:-3px;flex-shrink:0}
|
||||
.hero-meta .lucide{width:16px;height:16px}
|
||||
|
|
@ -264,6 +283,23 @@
|
|||
</div>
|
||||
</section> -->
|
||||
|
||||
<!-- DEINE HERDE (nur eingeloggt) -->
|
||||
<section id="herdSection" class="sec-soft hidden">
|
||||
<div class="wrap">
|
||||
<div class="sec-head">
|
||||
<div class="sec-tag">Deine Herde</div>
|
||||
<h2>Wer aus deiner Crew ist gerade da?</h2>
|
||||
<p>Gründe eine Herde oder tritt einer bei – seht in Echtzeit, wer online ist und in welcher Lobby zockt.</p>
|
||||
</div>
|
||||
<div class="herd-actions">
|
||||
<input id="herdName" placeholder="Herden-Name…" maxlength="60" autocomplete="off">
|
||||
<button class="btn btn-primary" onclick="Herd.create()">Gründen</button>
|
||||
<button class="btn btn-ghost" onclick="Herd.join()">Beitreten</button>
|
||||
</div>
|
||||
<div id="herdList"><p style="text-align:center;color:var(--muted);font-size:14px">Lade…</p></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- CTA -->
|
||||
<section>
|
||||
<div class="wrap">
|
||||
|
|
@ -314,7 +350,7 @@
|
|||
function bsbGalleryFail(img){ const f=img.closest('figure'); if(f){ f.classList.add('empty'); f.innerHTML='<i data-lucide="image"></i><span>Bild hier ablegen</span>'; renderIcons(); } }
|
||||
renderIcons();
|
||||
|
||||
// Auth-aware nav (Login bleibt Pflicht zum Spielen)
|
||||
// Auth-aware nav (Login bleibt Pflicht zum Spielen) + Herde
|
||||
(async () => {
|
||||
try {
|
||||
const r = await fetch('auth.php?action=me');
|
||||
|
|
@ -322,10 +358,68 @@
|
|||
if (d && d.user) {
|
||||
document.getElementById('navProfile').classList.remove('hidden');
|
||||
document.getElementById('navLogin').classList.add('hidden');
|
||||
document.getElementById('herdSection').classList.remove('hidden');
|
||||
Herd.init();
|
||||
}
|
||||
} catch (e) {}
|
||||
})();
|
||||
|
||||
// ── Deine Herde (Gruppen + Online-Präsenz) ──
|
||||
const Herd = (() => {
|
||||
const $ = id => document.getElementById(id);
|
||||
const esc = s => (s||'').replace(/[&<>"']/g,c=>({'&':'&','<':'<','>':'>','"':'"',"'":'''}[c]));
|
||||
async function api(action, body){
|
||||
const opt = body ? {method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify(body)} : {};
|
||||
const r = await fetch('api.php?action='+action, opt);
|
||||
return r.json();
|
||||
}
|
||||
function render(groups){
|
||||
const wrap = $('herdList');
|
||||
if(!groups || !groups.length){
|
||||
wrap.innerHTML = '<p style="text-align:center;color:var(--muted);font-size:14px">Noch keine Herde – gründe oder tritt einer bei. 🐑</p>';
|
||||
return;
|
||||
}
|
||||
wrap.innerHTML = '<div class="herd-grid">'+groups.map(g => `
|
||||
<div class="herd-card">
|
||||
<div class="herd-card-head">
|
||||
<h3>${esc(g.group_name)}</h3>
|
||||
<button class="herd-leave" onclick="Herd.leave(${parseInt(g.id)})">verlassen</button>
|
||||
</div>
|
||||
${(g.members||[]).map(m => {
|
||||
const status = m.online ? (m.room ? `in Lobby ${esc(m.room)}` : 'online') : 'offline';
|
||||
return `<div class="herd-member">
|
||||
<span class="herd-dot ${m.online?'on':''}"></span>
|
||||
<span class="herd-name" style="color:${m.color||'var(--navy)'}">${esc(m.username)}</span>
|
||||
<span class="herd-status ${m.online&&m.room?'playing':''}">${status}</span>
|
||||
</div>`;
|
||||
}).join('')}
|
||||
</div>`).join('')+'</div>';
|
||||
}
|
||||
async function load(){
|
||||
try{ const d = await api('groups_my'); render(d.groups||[]); }catch(e){}
|
||||
}
|
||||
async function create(){
|
||||
const name = $('herdName').value.trim();
|
||||
if(!name) return;
|
||||
try{ const d = await api('group_create',{name}); if(d.error){alert(d.error);return;} $('herdName').value=''; load(); }catch(e){}
|
||||
}
|
||||
async function join(){
|
||||
const name = $('herdName').value.trim();
|
||||
if(!name) return;
|
||||
try{ const d = await api('group_join',{name}); if(d.error){alert(d.error);return;} $('herdName').value=''; load(); }catch(e){}
|
||||
}
|
||||
async function leave(id){
|
||||
try{ await api('group_leave',{id}); load(); }catch(e){}
|
||||
}
|
||||
function init(){
|
||||
load();
|
||||
// Heartbeat: hält den eigenen Online-Status auf der Landing aktuell
|
||||
fetch('api.php?action=heartbeat');
|
||||
setInterval(()=>{ fetch('api.php?action=heartbeat'); load(); }, 20000);
|
||||
}
|
||||
return { init, create, join, leave };
|
||||
})();
|
||||
|
||||
// Cookie banner
|
||||
const Cookie = (() => {
|
||||
const KEY = 'bsb_cookie_consent';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue