Portal demo for Vercel
- The real portal over a router that lives in the page (web/src/portal/demo): "User" on "Dawnline Preview", ten scenarios (first visit, settings changed, out of data, outside the hours, paused, ended, plain HTTP, plain WireGuard, no free slots), devices kept per visitor in localStorage. Keys are random and the server's address never resolves: nothing is installed and nothing connects - A "Demo" chip after the breadcrumb opens a drawer with the scenarios and Start over; a new device "connects" a few seconds after its settings - A GitHub pill beside the page's QR knob; on a phone, where the names need the room, a GitHub button in the drawer instead - npm run build:demo builds the static site into web/dist/demo; web/vercel.json deploys it with the portal's CSP and headers, and builds only commits on main that change web/ - README links to the live demo (dawnline-demo.vercel.app) - Tests for the demo router (tests/demo.test.ts)
This commit is contained in:
1 parent
8e7c15ad56
commit
caed976e63
14 files changed
+1007
-3
No files matched your search
@@ -0,0 +1,104 @@
|
||||
// The demo's scenario picker: the "Demo" chip, opening a drawer with the
|
||||
// scenarios in groups (glass icon, name, what the page shows) and "Start over".
|
||||
// Picking one swaps the page in place. Built only from the portal's own parts
|
||||
// (sheet, glass icons, toast, motion); where the chip sits is crumbs.ts. On a
|
||||
// phone the drawer's foot also links to GitHub, the breadcrumb having no room.
|
||||
|
||||
import { h, ic } from '../dom';
|
||||
import { call } from '../api';
|
||||
import { repaint, setState, type State } from '../state';
|
||||
import { closeSheet, head, openSheet, sub, type View } from '../ui/sheet';
|
||||
import { glass, type Tone } from '../ui/glass';
|
||||
import { toast } from '../ui/feedback';
|
||||
import { EASE_OUT, play } from '../motion';
|
||||
import { GROUPS, REPO, type Scenario, type ScenarioId } from './data';
|
||||
import type { DemoRouter } from './router';
|
||||
|
||||
/** Each scenario's glass icon and tone (the glass set is smaller than the line icons). */
|
||||
const LOOK: Record<ScenarioId, [string, Tone]> = {
|
||||
normal: ['check', 'green'],
|
||||
first: ['plus', 'blue'],
|
||||
stale: ['refresh', 'orange'],
|
||||
quota: ['chart', 'red'],
|
||||
hours: ['clock', 'orange'],
|
||||
paused: ['pause', 'orange'],
|
||||
expired: ['calendar', 'red'],
|
||||
http: ['lock', 'orange'],
|
||||
plain: ['shield', 'grey'],
|
||||
full: ['phone', 'grey'],
|
||||
};
|
||||
|
||||
/** The chip that opens the scenarios. */
|
||||
export function scenarioChip(router: DemoRouter): HTMLElement {
|
||||
const app = document.getElementById('app')!;
|
||||
|
||||
/** Swap the page in place: it dims away and comes back drawn from the scenario, the link saying which. */
|
||||
async function pick(s: ScenarioId, done?: string) {
|
||||
closeSheet();
|
||||
router.use(s);
|
||||
const u = new URL(location.href);
|
||||
u.searchParams.set('s', s);
|
||||
history.replaceState(history.state, '', u);
|
||||
const out = play(app, [{ opacity: 1 }, { opacity: 0, filter: 'blur(4px)' }], { duration: 160, easing: EASE_OUT, fill: 'forwards' });
|
||||
const st = await call<State>('state');
|
||||
await out.finished;
|
||||
setState(st);
|
||||
repaint();
|
||||
out.cancel();
|
||||
play(
|
||||
app,
|
||||
[
|
||||
{ opacity: 0, filter: 'blur(4px)', transform: 'translateY(6px)' },
|
||||
{ opacity: 1, filter: 'none', transform: 'none' },
|
||||
],
|
||||
{
|
||||
duration: 420,
|
||||
easing: EASE_OUT,
|
||||
},
|
||||
);
|
||||
if (done) toast(done);
|
||||
}
|
||||
|
||||
function row(s: Scenario): HTMLElement {
|
||||
const on = s.id === router.scenario();
|
||||
const [icon, tone] = LOOK[s.id];
|
||||
return h(
|
||||
'button',
|
||||
{ type: 'button', class: `dm-row${on ? ' on' : ''}`, 'aria-pressed': String(on), onclick: () => pick(s.id) },
|
||||
glass(icon, tone),
|
||||
h('span', { class: 't' }, h('b', {}, s.label), h('span', {}, s.about)),
|
||||
on ? ic('check', 'i dm-tick') : null,
|
||||
);
|
||||
}
|
||||
|
||||
function scenarios(): View {
|
||||
const el = h(
|
||||
'div',
|
||||
{ class: 'view' },
|
||||
head('Try a scenario'),
|
||||
sub('How the page looks in each case. Nothing here connects.'),
|
||||
...GROUPS.map((g) =>
|
||||
h('div', { class: 'dm-group' }, h('div', { class: 'lbl-s' }, g.title), h('div', { class: 'dm-list' }, ...g.items.map(row))),
|
||||
),
|
||||
h(
|
||||
'div',
|
||||
{ class: 'dm-foot' },
|
||||
h(
|
||||
'button',
|
||||
{ type: 'button', class: 'btn soft', onclick: () => pick(router.scenario(), 'The demo started over') },
|
||||
ic('reset'),
|
||||
h('span', {}, 'Start over'),
|
||||
),
|
||||
h('a', { class: 'btn soft dm-gh-alt', href: REPO, target: '_blank', rel: 'noopener' }, ic('github'), h('span', {}, 'GitHub')),
|
||||
),
|
||||
);
|
||||
return { el, label: 'Try a scenario' };
|
||||
}
|
||||
|
||||
return h(
|
||||
'button',
|
||||
{ type: 'button', class: 'dm-chip', 'aria-haspopup': 'dialog', onclick: () => openSheet(scenarios) },
|
||||
h('span', {}, 'Demo'),
|
||||
ic('chevron', 'i'),
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user