Stage 3-5 server (military, expansion, social), web client for stages 1-2, ops/deploy
Built: units/research/training, movements (scan, raid, attack, takeover, reinforce, settle, transport), deterministic combat resolved in the event queue, reports, power/offline units, founding + conquest + incumbent sites; alliances, roles, diplomacy (24h pact cancel via events), messages, rankings; vanilla-JS phone-first client (auth, POP, map, alerts, settings, en/nb); systemd units, backup timer, DEPLOY.md, tools/admin.js. Tested: npm test 96/96 (fake clock, in-memory db, a few real-HTTP tests); client checked with headless Chromium screenshots only. NOT done: marketplace/transport trade, client screens for military/social, WebSocket push, bots/balance, e2e suite. All unit stats and costs are unbalanced first guesses. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
This commit is contained in:
parent
b56b13880e
commit
249818a7aa
111 changed files with 17472 additions and 13 deletions
84
public/js/screens/alerts.js
Normal file
84
public/js/screens/alerts.js
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
'use strict';
|
||||
/* Alerts: the durable notification feed (GET /notifications). Newest first; what arrived since you last looked is marked. */
|
||||
(function () {
|
||||
const { h, clear, icon } = UI;
|
||||
const PAGE = 100, MAX_PAGES = 5;
|
||||
|
||||
let box, listEl, statusEl, items = [], seenAtOpen = 0, loading = false, offTick = null;
|
||||
|
||||
function townName(id) {
|
||||
const t = App.state.towns.find((x) => x.id === id);
|
||||
return t ? t.name : '#' + id;
|
||||
}
|
||||
|
||||
// One entry per notification type: icon + title + detail. Unknown types still show something readable.
|
||||
function describe(n) {
|
||||
const p = n.payload || {};
|
||||
if (n.type === 'build_done') {
|
||||
return { icon: 'b-' + p.type, title: App.t('alerts.build_done', { name: App.buildingName(p.type), level: p.level }), detail: App.t('alerts.build_done.in', { town: townName(p.townId) }), go: 'pop' };
|
||||
}
|
||||
return { icon: 'bell', title: App.t('alerts.unknown', { type: n.type }), detail: '', go: null };
|
||||
}
|
||||
|
||||
function draw() {
|
||||
clear(listEl);
|
||||
if (!items.length) { listEl.appendChild(h('p', { class: 'empty pad', text: App.t('alerts.empty') })); return; }
|
||||
const now = App.now();
|
||||
for (const n of items.slice().reverse()) {
|
||||
const d = describe(n);
|
||||
const isNew = n.id > seenAtOpen;
|
||||
listEl.appendChild(h('li', null,
|
||||
h('button', { class: 'alert' + (isNew ? ' new' : ''), type: 'button', onclick: () => { if (d.go) App.go(d.go); } },
|
||||
h('span', { class: 'row-ic' }, icon(d.icon)),
|
||||
h('span', { class: 'row-main' }, h('span', { class: 'row-title' }, h('b', { text: d.title }), isNew ? h('span', { class: 'pill accent', text: App.t('alerts.new') }) : null),
|
||||
d.detail ? h('span', { class: 'row-sub', text: d.detail }) : null),
|
||||
h('span', { class: 'when mono', dataset: { at: n.createdAt }, text: App.fmt.ago(now - n.createdAt) }))));
|
||||
}
|
||||
}
|
||||
|
||||
async function load() {
|
||||
if (loading) return;
|
||||
loading = true;
|
||||
statusEl.hidden = true;
|
||||
try {
|
||||
let after = items.length ? items[items.length - 1].id : 0;
|
||||
for (let page = 0; page < MAX_PAGES; page++) {
|
||||
const r = await App.api.get('/notifications', { after, limit: PAGE });
|
||||
items = items.concat(r.items);
|
||||
if (r.next === null || !r.items.length) break;
|
||||
after = r.next;
|
||||
}
|
||||
draw();
|
||||
if (items.length) App.markSeen(items[items.length - 1].id); else App.markSeen(0);
|
||||
} catch (e) {
|
||||
statusEl.textContent = App.t('alerts.error') + ' ' + App.errMsg(e);
|
||||
statusEl.hidden = false;
|
||||
} finally { loading = false; }
|
||||
}
|
||||
|
||||
App.registerScreen({
|
||||
id: 'alerts', titleKey: 'screen.alerts', navKey: 'nav.alerts', icon: 'bell', hud: false,
|
||||
render(container) {
|
||||
box = container;
|
||||
listEl = h('ul', { class: 'alert-list' });
|
||||
statusEl = h('p', { class: 'form-error', role: 'alert', hidden: true });
|
||||
box.appendChild(h('div', { class: 'page' },
|
||||
h('div', { class: 'card-head page-head' }, h('h1', { text: App.t('screen.alerts') }),
|
||||
h('button', { class: 'icon-btn', type: 'button', 'aria-label': App.t('common.retry'), onclick: () => load() }, icon('refresh'))),
|
||||
statusEl, listEl));
|
||||
App.on('session', () => { items = []; });
|
||||
},
|
||||
onShow() {
|
||||
seenAtOpen = App.getSeen();
|
||||
box.querySelector('h1').textContent = App.t('screen.alerts');
|
||||
draw();
|
||||
load();
|
||||
if (offTick) offTick();
|
||||
offTick = App.onTick(() => {
|
||||
const now = App.now();
|
||||
for (const el of listEl.querySelectorAll('.when')) { const s = App.fmt.ago(now - Number(el.dataset.at)); if (el.textContent !== s) el.textContent = s; }
|
||||
});
|
||||
},
|
||||
onHide() { if (offTick) offTick(); offTick = null; },
|
||||
});
|
||||
}());
|
||||
Loading…
Add table
Add a link
Reference in a new issue