Milestone 5: canvas for access

The hub now serves a React canvas (web/, embedded at build time):
grant by dragging a vault onto a person, revoke by pulling a ribbon
until it snaps with an 8 s Undo the hub honours before anything reaches
devices, invites (including vaults dropped on invitees), device rename
and removal, Float/Dock, and panels with a button for every gesture.

Sign-in without passwords (SPEC §8): `lunesync open` one-time link or
a pairing code typed on the hub; 30-day HttpOnly session cookie plus an
X-Lune header on every canvas request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-29 07:56:41 +07:00
parent 4025726083
commit 193cb06f85
27 changed files with 3574 additions and 39 deletions

81
web/src/main.tsx Normal file
View File

@@ -0,0 +1,81 @@
import { StrictMode, useEffect, useState } from 'react';
import { createRoot } from 'react-dom/client';
import { api, SignedOut, type CanvasData } from './api';
import { Canvas } from './Canvas';
import './styles.css';
/** Sign in with a code from one of your devices (no passwords, §8). */
function SignIn({ onDone }: { onDone: () => void }) {
const expired = new URLSearchParams(location.search).has('expired');
const [code, setCode] = useState('');
const [error, setError] = useState(expired ? 'That sign-in link was used or expired. Run `lunesync open` again, or use a code.' : '');
const submit = async (e: React.FormEvent) => {
e.preventDefault();
try {
await api.signin(code);
history.replaceState(null, '', '/');
onDone();
} catch (err) {
setError((err as Error).message);
}
};
return (
<main className="page">
<form className="card" onSubmit={submit}>
<span className="eyebrow">Lune</span>
<h1 className="disp">Sign in to the team canvas</h1>
<label htmlFor="code">Code from one of your devices</label>
<input id="code" className="field code" value={code} onChange={(e) => setCode(e.target.value)} placeholder="K7QD-4MXA" autoComplete="one-time-code" autoFocus />
{error && <p className="error" role="alert">{error}</p>}
<button className="btn btn-primary" type="submit" disabled={!code.trim()}>Sign in</button>
<p className="muted">Get a code with <code>lunesync pair</code>, or run <code>lunesync open</code> on a device to skip this page.</p>
</form>
</main>
);
}
/** What an invite link shows in a browser: how to join with the app. */
function Join() {
const link = location.href;
return (
<main className="page">
<div className="card">
<span className="eyebrow">Lune · invite</span>
<h1 className="disp">You're invited to a team</h1>
<p>Install the sync app, then join from the device you'll use (this link works once):</p>
<pre className="cmd">lunesync join {link} --name "My laptop"</pre>
<p className="muted">Pick any name for the device; your team sees it next to your changes. Shared vaults arrive in <code>~/Vaults</code>.</p>
</div>
</main>
);
}
function App() {
const [data, setData] = useState<CanvasData | null>(null);
const [state, setState] = useState<'loading' | 'signin' | 'ready' | 'error'>('loading');
const [error, setError] = useState('');
const load = async () => {
try {
setData(await api.canvas());
setState('ready');
} catch (e) {
if (e instanceof SignedOut) setState('signin');
else {
setError((e as Error).message);
setState('error');
}
}
};
useEffect(() => {
if (!location.pathname.startsWith('/join/')) load();
}, []);
if (location.pathname.startsWith('/join/')) return <Join />;
if (state === 'signin') return <SignIn onDone={load} />;
if (state === 'error') return <main className="page"><div className="card"><p className="error">{error}</p><button className="btn" onClick={load}>Try again</button></div></main>;
if (!data) return <main className="page" aria-busy="true" />;
return <Canvas data={data} reload={load} onSignOut={async () => { await api.signout().catch(() => {}); setState('signin'); }} />;
}
createRoot(document.getElementById('root')!).render(<StrictMode><App /></StrictMode>);