// 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(); }; const pol = w => w == null ? 'not tracked yet' : FX.polOf(w) + ' POL'; let D = null, focus = null; const stat = (k, v, note) => '
' + k + '' + v + '' + (note ? '' + note + '' : '') + '
'; const stepsHtml = steps => '
' + steps.map(s => '
' + esc(s.label) + (s.next ? ' (next)' : '') + '
').join('') + '
'; const thread = items => items.length ? items.map(x => '
' + esc(x.text) + '' + esc(FX.when(x.at)) + '
').join('') : '

No messages yet. Say hello: they see it in their member area.

'; 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 => '' + esc(p.name) + '').join(' ') || 'No builder links yet.'; } 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 => '').join('') : '

' + (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.') + '

'; 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 => '
@' + esc(h.username || 'player') + '
' + esc(h.why) + '
').join('') : '

Nobody needs a nudge right now.

'; 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 => '@' + esc(p.username || 'player') + '').join(' '); $('queue').innerHTML = d.queue.length ? '

' + 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 Draft Board.

' : '

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 Draft Board.

'; } 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', pol(p.surfWei)], ['Came from', p.door || 'not tracked yet'], ['Last seen', FX.ago(p.lastSeen)]] .map(r => '
' + r[0] + '' + esc(r[1]) + '
').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) => '').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); })();