Add POST /me/join and a join card: accounts survive a world reset
Found while resetting the live test world: joinWorld's comment promised POST /worlds/:id/join but no route existed, so after reset-world (accounts kept) nobody could found a POP again. Added POST /me/join (default: first running world; 409 if already joined), a join card on the POP screen, en/nb strings, API.md + openapi. Client no longer polls /movements while it has no operator (that 404ed). Tested: npm test 209/209 (new test/me-join.test.js incl. response contract), openapi check, npm run e2e (new check: account without a POP sees the join card and founds one). NOT tested: joining a second/other world (only the default-world path in the browser), nb text of the card visually. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
parent
bf7af0679c
commit
9104480463
9 changed files with 170 additions and 6 deletions
|
|
@ -72,7 +72,7 @@
|
|||
'pop.level': 'Lv {n}', 'pop.notBuilt': 'Not built', 'pop.max': 'Max', 'pop.inQueue': 'Building',
|
||||
'pop.upgradeReady': 'Can upgrade', 'pop.locked': 'Requirements missing',
|
||||
'pop.load.error': 'Could not load this POP.',
|
||||
'pop.noTown': 'No POP on this account yet.',
|
||||
'pop.noTown': 'No POP on this account yet.', 'pop.join': 'Found my POP', 'pop.join.hint': 'The world was reset or is new. Join it to get a capital POP and start building.',
|
||||
'pop.bonus': 'Rural bonus', 'pop.bonus.none': 'No rural areas in reach',
|
||||
|
||||
'power.title': 'Power', 'power.out': 'Output', 'power.draw': 'Draw', 'power.net': 'Net', 'power.buffer': 'Buffer',
|
||||
|
|
@ -212,7 +212,7 @@
|
|||
'pop.level': 'Nv {n}', 'pop.notBuilt': 'Ikke bygget', 'pop.max': 'Maks', 'pop.inQueue': 'Under bygging',
|
||||
'pop.upgradeReady': 'Kan oppgraderes', 'pop.locked': 'Mangler krav',
|
||||
'pop.load.error': 'Kunne ikke laste denne POP-en.',
|
||||
'pop.noTown': 'Ingen POP på denne kontoen ennå.',
|
||||
'pop.noTown': 'Ingen POP på denne kontoen ennå.', 'pop.join': 'Etabler min POP', 'pop.join.hint': 'Verdenen er nullstilt eller ny. Bli med for å få en hovedstads-POP og begynne å bygge.',
|
||||
'pop.bonus': 'Landsbygdbonus', 'pop.bonus.none': 'Ingen landsbygd innen rekkevidde',
|
||||
|
||||
'power.title': 'Strøm', 'power.out': 'Produksjon', 'power.draw': 'Forbruk', 'power.net': 'Netto', 'power.buffer': 'Buffer',
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@
|
|||
// ------------------------------------------------------------------ refetchers
|
||||
let movesFlight = null;
|
||||
App.refreshMovements = () => {
|
||||
if (!App.state.user) return Promise.resolve(null);
|
||||
if (!App.state.user || !App.state.operator) return Promise.resolve(null);
|
||||
if (movesFlight) return movesFlight;
|
||||
lastMovesFetch = Date.now();
|
||||
movesFlight = api.get('/movements').then((r) => {
|
||||
|
|
|
|||
|
|
@ -366,12 +366,26 @@
|
|||
return h('section', { class: 'card' }, h('div', { class: 'card-head' }, h('h2', { text: App.t('pop.infra.title') })), h('div', { class: 'rows' }, list.map(infraRow)));
|
||||
}
|
||||
|
||||
// An account with no operator (the world was reset or a new one opened): one tap founds the capital POP.
|
||||
function joinCard() {
|
||||
const btn = h('button', { class: 'btn primary', type: 'button', 'data-keep': '' }, App.t('pop.join'));
|
||||
btn.addEventListener('click', async () => {
|
||||
btn.disabled = true;
|
||||
try {
|
||||
const me = await App.api.post('/me/join', {});
|
||||
App.setSession(me.user, me.operators);
|
||||
await App.enter('pop');
|
||||
} catch (e) { toast(App.errMsg(e), 'error'); btn.disabled = false; }
|
||||
});
|
||||
return h('div', { class: 'card pad' }, h('h2', { text: App.t('pop.noTown') }), h('p', { text: App.t('pop.join.hint') }), btn);
|
||||
}
|
||||
|
||||
function draw() {
|
||||
dirty = false;
|
||||
refs = { tiles: new Map(), rows: new Map(), queue: [] };
|
||||
clear(box);
|
||||
const t = td();
|
||||
if (!App.state.townId) { box.appendChild(h('p', { class: 'empty pad', text: App.t('pop.noTown') })); return; }
|
||||
if (!App.state.townId) { box.appendChild(joinCard()); return; }
|
||||
if (!t) { box.appendChild(h('div', { class: 'boot' }, h('div', { class: 'spinner', 'aria-hidden': 'true' }), h('p', { text: App.t('common.loading') }))); return; }
|
||||
// other screens add cards here through App.popSections (military: incoming banner on top, expansion below the power card)
|
||||
const extra = (slot) => (App.popSections || []).filter((s) => s.slot === slot).map((s) => { try { return s.render(t); } catch (e) { console.error(e); return null; } });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue