@volter/world-console 3.0.6 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/console.tsx +13 -6
- package/dist/client/console.bundle.js +11 -11
- package/dist/client/console.tsx +13 -6
- package/dist/client/main.bundle.js +65 -65
- package/package.json +3 -3
package/dist/client/console.tsx
CHANGED
|
@@ -1752,25 +1752,30 @@ function Thumb({ url, title }: { url: string; title: string }): React.JSX.Elemen
|
|
|
1752
1752
|
* was the moment before the first of them beside how it is now. "Before" is a read-only copy of the World as of then (a
|
|
1753
1753
|
* branch the World makes for an hour, removed when this closes), its site read at the copy's own address. */
|
|
1754
1754
|
function Compare({ name, token, frame, onClose, reads }: { name: string; token: string; frame: BoardFrame; onClose: () => void; /** the board's reads so far: its changes are read again with each */ reads: number }): React.JSX.Element {
|
|
1755
|
-
const [before, setBefore] = useState<{ state: 'opening' } | { state: 'ok'; url: string; at: string } | { state: 'none'; why: string }>({ state: 'opening' });
|
|
1755
|
+
const [before, setBefore] = useState<{ state: 'opening' } | { state: 'ok'; url: string; at: string; /** a vendor's page: opened as a page of its own, never framed */ opens?: boolean } | { state: 'none'; why: string }>({ state: 'opening' });
|
|
1756
1756
|
// its changes, read for this comparison alone
|
|
1757
1757
|
const listed = useDoor<{ total: number; acts: BoardAct[] }>(token, `/-/${name}/board/changes?frame=${encodeURIComponent(frameKey(frame))}`, reads);
|
|
1758
1758
|
useEffect(() => {
|
|
1759
1759
|
if (!frame.since) { setBefore({ state: 'none', why: 'Nothing here has changed since the World was last cut.' }); return; }
|
|
1760
|
-
if (!frame.at
|
|
1760
|
+
if (!frame.at) { setBefore({ state: 'none', why: `${vendorName(frame.vendor)}'s twin draws no page for this ${frame.kind} yet; its changes are listed below.` }); return; }
|
|
1761
|
+
const shown = frame.at;
|
|
1761
1762
|
const at = new Date(Date.parse(frame.since) - 1).toISOString();
|
|
1762
1763
|
let made: string | null = null; let closed = false;
|
|
1763
1764
|
// a copy is made once the comparison has stayed open a moment: one passed through on the way to another makes none
|
|
1764
1765
|
const wait = setTimeout(() => void (async () => {
|
|
1765
1766
|
const r = await door(token, `/-/${name}/branches`, { method: 'POST', body: JSON.stringify({ at: { instant: at }, ttl: 3600 }), signal: AbortSignal.timeout(60000) }).catch(() => null);
|
|
1766
1767
|
if (!r?.ok) { setBefore({ state: 'none', why: `The World made no copy of itself as it was then${r ? `: ${await failure(r)}` : ''}.` }); return; }
|
|
1767
|
-
const b = (await r.json()) as { name: string; origin?: string };
|
|
1768
|
+
const b = (await r.json()) as { name: string; origin?: string; readToken?: string };
|
|
1768
1769
|
made = b.name;
|
|
1769
1770
|
if (closed) { void door(token, `/-/${name}/branches/${b.name}`, { method: 'DELETE' }).catch(() => null); return; }
|
|
1770
1771
|
const o = httpOrigin(b.origin);
|
|
1771
1772
|
if (!o) { setBefore({ state: 'none', why: 'This World shows sites only at its own local address.' }); return; }
|
|
1772
|
-
|
|
1773
|
-
|
|
1773
|
+
// a site at the copy's own address, framed; a vendor's page in the copy is behind the copy's session, which opens
|
|
1774
|
+
// only on the copy's own pages (another site's frame is refused it), so it opens as a page of its own: the copy's
|
|
1775
|
+
// hand-off page (served-world, `session/hand-off`) opens the session from the read token, then goes to the page
|
|
1776
|
+
if ('site' in shown) { const u = new URL(frame.url); setBefore({ state: 'ok', url: `${o.protocol}//${u.hostname}.${o.host}${u.pathname}${u.search}`, at }); return; }
|
|
1777
|
+
if (!b.readToken) { setBefore({ state: 'none', why: 'The copy of the World gave no read token to open its pages with.' }); return; }
|
|
1778
|
+
setBefore({ state: 'ok', url: `${o.origin}/-/${b.name}/session/hand-off#${new URLSearchParams({ token: b.readToken, land: `/${b.name}/${frame.vendor}${shown.screen}` }).toString()}`, at, opens: true });
|
|
1774
1779
|
})(), 500);
|
|
1775
1780
|
return () => { closed = true; clearTimeout(wait); if (made) void door(token, `/-/${name}/branches/${made}`, { method: 'DELETE' }).catch(() => null); };
|
|
1776
1781
|
}, [name, token, frame.vendor, frame.id, frame.since]);
|
|
@@ -1785,7 +1790,9 @@ function Compare({ name, token, frame, onClose, reads }: { name: string; token:
|
|
|
1785
1790
|
<div className="compare-sides">
|
|
1786
1791
|
<figure>
|
|
1787
1792
|
<figcaption>Before{before.state === 'ok' ? ` · as of ${when(before.at)}` : ''}</figcaption>
|
|
1788
|
-
{before.state === 'ok' ?
|
|
1793
|
+
{before.state === 'ok' ? (before.opens
|
|
1794
|
+
? <p className="mode compare-note"><a href={before.url} target="_blank" rel="noopener noreferrer">Open {frame.title} as it was →</a><br />A read-only copy of the World, kept while this comparison is open.</p>
|
|
1795
|
+
: <Thumb url={before.url} title={`${frame.title} before`} />) : before.state === 'opening' ? <p className="mode compare-note" role="status">Opening the World as it was…</p> : <p className="mode compare-note">{before.why}</p>}
|
|
1789
1796
|
</figure>
|
|
1790
1797
|
<figure>
|
|
1791
1798
|
<figcaption>Now</figcaption>
|