b2d5eb4625
hubevents.js (new, byte-identical in VBB, DLB, ViralAdBlitz, DownlineHydra, 5xYourTeam): POST /api/hub/events, signed by the hub with HUB_SECRET (same hook InstantAdPay and LinkSpin take). member.signedout and member.blocked: the person is looked up by hub id (/v1/resolve, signed as fivex) and their sessions here end (by the main wallet or any contract wallet). member.erased: matched by the wallet SHA-256s (and email SHA-256) the hub now sends with the event. Only sessions made before the event end (a replay never signs anyone out twice); a failed hub lookup answers 503 so the hub resends. Off with HUB_HOOK=0. Admin status: hubEvents (counts only). /team: "Sign out everywhere" next to Sign out (POST /api/auth/logout-everywhere -> networksso.signOutEverywhere, then every session of this member here ends). Smoke: section 14b (same cases as the other wallet sites): 172 pass, 2 fail with UI; the same 2 (pool size, this week's pot: test-clock dated) fail on a clean HEAD. team.js?v=4. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
83 lines
9.0 KiB
JavaScript
83 lines
9.0 KiB
JavaScript
// My Team (the coach's dashboard): stat tiles, instant picks left, the focused pick card (scouting stats, the getting-started
|
|
// steps, one-tap messages, the message composer and thread, release), the rest of the team, who to help first, the draft queue.
|
|
// Someone who is a pick sees their coach here instead (steps, the thread, the coach's builder links). Messages go through the
|
|
// site only; no contact details are ever shown. Every figure comes from /api/my.
|
|
(async function () {
|
|
FX.renderNav('/team'); FX.renderFooter();
|
|
const $ = FX.$, esc = FX.esc;
|
|
const c = await FX.getConfig().catch(() => ({}));
|
|
const me = await FX.getJSON('/api/me');
|
|
if (!me.signedIn) {
|
|
if (await FX.silentSso('/team')) return;
|
|
$('signin').hidden = false; $('signinBox').innerHTML = FX.signInBlock('/team'); FX.wireSignIn($('signinBox')); return;
|
|
}
|
|
$('signout').hidden = false; $('signout').onclick = async () => { await FX.post('/api/auth/logout'); location.reload(); };
|
|
$('signoutAll').hidden = false; $('signoutAll').onclick = async () => { $('signoutAll').disabled = true; await FX.post('/api/auth/logout-everywhere'); location.reload(); };
|
|
const pol = w => w == null ? 'not tracked yet' : FX.polOf(w) + ' POL';
|
|
let D = null, focus = null;
|
|
const stat = (k, v, note) => '<div class="stat"><span>' + k + '</span><b>' + v + '</b>' + (note ? '<em>' + note + '</em>' : '') + '</div>';
|
|
const stepsHtml = steps => '<div class="steps">' + steps.map(s => '<div class="' + (s.done ? 'done' : s.next ? 'next' : '') + '">' + esc(s.label) + (s.next ? ' (next)' : '') + '</div>').join('') + '</div>';
|
|
const thread = items => items.length ? items.map(x => '<div class="msg' + (x.mine ? ' mine' : '') + '">' + esc(x.text) + '<em>' + esc(FX.when(x.at)) + '</em></div>').join('') : '<p class="small" style="color:#4a587e">No messages yet. Say hello: they see it in their member area.</p>';
|
|
|
|
async function load() {
|
|
const d = await FX.getJSON('/api/my'); if (d.error) { FX.status(d.error, 'err'); return; }
|
|
D = d; $('dash').hidden = false;
|
|
$('hello').textContent = d.username ? '@' + d.username : FX.short(d.address);
|
|
// a pick: their coach
|
|
if (d.myCoach) {
|
|
const mc = d.myCoach; $('myCoach').hidden = false;
|
|
$('mcName').textContent = '@' + mc.coach; $('mcTier').textContent = mc.tierName + ' · on the team since ' + FX.when(mc.since);
|
|
$('mcSteps').innerHTML = stepsHtml(mc.steps);
|
|
$('mcThread').innerHTML = thread(mc.messages.map(x => ({ mine: x.dir === 'out', text: x.text, at: x.at })));
|
|
$('mcSend').onclick = async () => { const t = $('mcText').value.trim(); if (!t) return; const r = await FX.post('/api/my/message', { pick: mc.pickId, text: t }); if (r.error) return FX.status(r.error, 'err'); $('mcText').value = ''; load(); };
|
|
$('mcBuilder').innerHTML = mc.builder.slice(0, 8).map(p => '<a class="btn small" href="' + esc(p.url) + '" target="_blank" rel="noopener nofollow">' + esc(p.name) + '</a>').join(' ') || '<span class="small">No builder links yet.</span>';
|
|
}
|
|
if (!d.coach && !d.picks.length) { $('noCoach').hidden = false; if (!d.myCoach) $('coachTools').hidden = true; return; }
|
|
$('coachTools').hidden = false;
|
|
const s = d.stats;
|
|
$('stats').innerHTML = stat('On my team', s.onTeam, s.open + ' open of ' + s.maxOpen) + stat('Started this week', s.startedThisWeek, 'payouts on or a first purchase')
|
|
+ stat('Next draft spot', s.nextSpot ? '#' + s.nextSpot : '-', 'earned by this week\'s starts') + stat('Back to pool soon', s.backSoon, 'within 24 hours');
|
|
$('credits').hidden = !(d.credits > 0);
|
|
$('creditsN').textContent = d.credits + ' instant pick' + (d.credits === 1 ? '' : 's');
|
|
if (d.page) { $('myPage').hidden = false; $('myPageLink').href = d.page; $('myPageLink').textContent = d.page.replace(/^https:\/\//, ''); }
|
|
const team = d.picks.filter(p => ['open', 'done', 'kept'].includes(p.status));
|
|
if (!focus || !team.some(p => p.id === focus)) focus = (d.help[0] && d.help[0].pickId) || (team[0] && team[0].id) || null;
|
|
paintFocus(team.find(p => p.id === focus));
|
|
const rest = team.filter(p => p.id !== focus);
|
|
$('team').innerHTML = rest.length ? rest.map(p => '<button type="button" class="mini' + (p.id === focus ? ' on' : '') + '" data-f="' + p.id + '"><b>@' + esc(p.username || 'player') + '</b><span class="t">' + esc(p.tierName) + (p.status === 'open' ? '' : ' · on the team') + '</span><span class="s">'
|
|
+ esc(p.status === 'open' ? (p.daysLeft <= 1 ? 'Back to the pool in ' + (p.daysLeft ? '1 day' : 'under a day') : (d.help.find(h => h.pickId === p.id) || {}).why || '') : 'Started: stays on your team') + (p.unread ? ' · ' + p.unread + ' new' : '') + '</span></button>').join('')
|
|
: '<p class="muted">' + (team.length ? 'Nobody else on the team yet. ' : 'No picks yet. ') + (d.credits ? 'Use your instant picks on the Draft Board.' : 'Your next picks come in the Monday draft.') + '</p>';
|
|
document.querySelectorAll('[data-f]').forEach(b => b.onclick = () => { focus = Number(b.dataset.f); load(); });
|
|
$('help').innerHTML = d.help.length ? d.help.slice(0, 8).map(h => '<div class="h"><div><b>@' + esc(h.username || 'player') + '</b><div class="small">' + esc(h.why) + '</div></div><button type="button" class="btn small" data-f2="' + h.pickId + '">Coach them</button></div>').join('')
|
|
: '<p class="muted small">Nobody needs a nudge right now.</p>';
|
|
document.querySelectorAll('[data-f2]').forEach(b => b.onclick = () => { focus = Number(b.dataset.f2); load().then(() => $('focus').scrollIntoView({ behavior: 'smooth' })); });
|
|
const past = d.picks.filter(p => p.status === 'returned');
|
|
$('pastWrap').hidden = !past.length;
|
|
$('past').innerHTML = past.slice(0, 12).map(p => '<span class="btn-ghost">@' + esc(p.username || 'player') + '</span>').join(' ');
|
|
$('queue').innerHTML = d.queue.length ? '<p class="small">' + d.queue.length + ' player' + (d.queue.length === 1 ? '' : 's') + ' on your queue. If you are away when your pick comes up, the first one still available is drafted for you. Edit it on the <a href="/">Draft Board</a>.</p>' : '<p class="small">Your queue is empty: if you are away when your pick comes up, the best available player by scouting score is drafted for you. Add players from the <a href="/">Draft Board</a>.</p>';
|
|
}
|
|
async function paintFocus(p) {
|
|
const el = $('focus'); if (!p) { el.hidden = true; return; } el.hidden = false;
|
|
const label = p.kind === 'instant' ? 'INSTANT PICK' : 'ROUND ' + (p.round || '?') + ' PICK';
|
|
$('fKick').textContent = label + ' · ' + p.tierName.toUpperCase();
|
|
$('fName').textContent = '@' + (p.username || 'player');
|
|
$('fWhen').textContent = 'Picked ' + FX.when(p.at) + (p.status === 'open' ? ' · ' + (p.daysLeft ? p.daysLeft + ' day' + (p.daysLeft === 1 ? '' : 's') + ' left to start' : 'goes back to the pool today') : ' · started, stays on your team');
|
|
$('fStats').innerHTML = [['Game plays', p.plays == null ? 'not tracked yet' : FX.n(p.plays) + (p.game ? ' (' + p.game + ')' : '')], ['Earned in games', pol(p.gameWei)], ['Earned surfing', p.surfWei == null && p.surfCredits != null ? FX.n(p.surfCredits) + ' ad credits' : pol(p.surfWei)], ['Came from', p.door || 'not tracked yet'], ['Last seen', FX.ago(p.lastSeen)]]
|
|
.map(r => '<div class="kvr"><span>' + r[0] + '</span><b>' + esc(r[1]) + '</b></div>').join('');
|
|
$('fSteps').innerHTML = stepsHtml(p.steps);
|
|
const h = D.help.find(x => x.pickId === p.id);
|
|
const taps = [h ? h.say : 'Great work so far. Anything I can help with?', 'Any questions so far? Reply here and I will walk you through it.', p.game ? 'Nice run in ' + p.game + '!' : 'Welcome to the team! I am here to help.'];
|
|
$('fTaps').innerHTML = taps.map((t, i) => '<button type="button" data-tap="' + i + '">"' + esc(t) + '"</button>').join('');
|
|
document.querySelectorAll('[data-tap]').forEach(b => b.onclick = () => { $('fText').value = taps[Number(b.dataset.tap)]; $('fText').focus(); });
|
|
$('fSend').onclick = async () => { const t = $('fText').value.trim(); if (!t) return; const r = await FX.post('/api/my/message', { pick: p.id, text: t }); if (r.error) return FX.status(r.error, 'err'); $('fText').value = ''; FX.status('Sent. They see it in their member area.', 'ok'); thr(); };
|
|
$('fRelease').hidden = p.status !== 'open';
|
|
$('fRelease').onclick = async () => { if (!confirmBox()) return; const r = await FX.post('/api/my/release', { pick: p.id }); FX.status(r.error || 'Released back to the pool.', r.error ? 'err' : 'ok'); load(); };
|
|
async function thr() { const t = await FX.getJSON('/api/my/messages?pick=' + p.id); $('fThread').innerHTML = thread(t.items || []); }
|
|
thr();
|
|
}
|
|
// releasing is a commitment decision: ask in the page (no browser dialogs)
|
|
let armed = 0; function confirmBox() { if (Date.now() - armed < 6000) { armed = 0; return true; } armed = Date.now(); FX.status('Tap "Release to the pool" again within 6 seconds to confirm. They go back to the pool for another coach, and it still counts as one of their two adoptions.', ''); return false; }
|
|
await load();
|
|
setInterval(() => { load().catch(() => {}); }, 30000);
|
|
})();
|