import { h, render } from './vendor/preact.module.js'; import htm from './vendor/htm.module.js'; const html = htm.bind(h); let users = []; let q = ''; let selected = null; let loading = true; let error = null; const labels = { active: 'активен', trial: 'пробный', exhausted: 'исчерпан', blocked: 'заблокирован', unverified: 'не подтверждён', read_only: 'только чтение', deleted: 'удалён' }; const fmt = (iso) => iso ? new Date(iso).toLocaleString('ru-RU', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit' }) : '—'; const visible = () => users.filter((u) => !q || (u.name + ' ' + u.email).toLowerCase().includes(q.toLowerCase())); const Row = ({ u, onPick }) => html` onPick(u)} onKeyDown=${(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onPick(u); } }}>
${u.name}${u.email}
${labels[u.status] || u.status} ${fmt(u.last_seen)} ${u.spent_24h} ₽ ${u.balance} ₽ ${u.access} `; const Drawer = ({ u, onClose }) => html` `; const App = () => html`

Клиенты

{ q = e.currentTarget.value; draw(); }} />
${loading ? html`` : error ? html`` : visible().length ? visible().map((u) => html`<${Row} key=${u.email} u=${u} onPick=${(x) => { selected = x; draw(); }} />`) : html``}
КлиентСтатусБыл(а)24 чБалансДоступ
Загрузка…
Никого не нашлось
<${Drawer} u=${selected} onClose=${() => { selected = null; draw(); }} />`; function draw() { render(html`<${App} />`, document.querySelector('#app')); } draw(); // сразу видно «Загрузка…», а не пустоту/ложное «никого» fetch('./data.json') .then((r) => { if (!r.ok) throw new Error('HTTP ' + r.status); return r.json(); }) .then((data) => { users = data; loading = false; draw(); }) .catch((e) => { console.error(e); error = e.message || 'сеть'; loading = false; draw(); });