@volter/world-console 2.0.7 → 2.0.8

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.
@@ -936,6 +936,15 @@ function BranchList({ name, token, canWrite, branches, opens, note, remove, onCh
936
936
  const list = branches.state === 'ok' ? branches.data.branches : [];
937
937
  const [making, setMaking] = useState(false); const [busy, setBusy] = useState(false); const [error, setError] = useState<string | null>(null);
938
938
  const [label, setLabel] = useState(''); const [when, setWhen] = useState<'now' | 'at'>('now'); const [at, setAt] = useState(''); const [hours, setHours] = useState('24');
939
+ // SERVE ANOTHER of the World's own branches here: the World switches under this page, which then reads it afresh
940
+ const [serving, setServing] = useState<string | null>(null); const [serveError, setServeError] = useState<string | null>(null);
941
+ const serveHere = async (branch: string): Promise<void> => {
942
+ setServing(branch); setServeError(null);
943
+ const r = await door(token, `/-/${name}/branches/${encodeURIComponent(branch)}/serve`, { method: 'POST' }).catch(() => null);
944
+ if (r?.ok) { location.reload(); return; }
945
+ setServing(null);
946
+ setServeError(r ? ((await r.json().catch(() => null)) as { error?: string } | null)?.error ?? `${r.status}` : `${ORIGIN} did not answer`);
947
+ };
939
948
  // made here: kept with its tokens so it opens in this tab; not `made` (a snapshot's "Return to live" never removes it: it lives as long as it was given)
940
949
  const make = async (body: Record<string, unknown>, opened: string): Promise<{ name: string } | string> => {
941
950
  const r = await door(token, `/-/${name}/branches`, { method: 'POST', body: JSON.stringify(body) }).catch(() => null);
@@ -1010,15 +1019,17 @@ function BranchList({ name, token, canWrite, branches, opens, note, remove, onCh
1010
1019
  ) : null}
1011
1020
  {branches.state === 'ok' && (branches.data.named?.length ?? 0) > 0 ? (
1012
1021
  <>
1013
- <p className="lede">This World's own branches (<code>volter world branch</code>). One runs at a time; this page shows the one served here. Another is served by stopping this serve, <code>volter world checkout &lt;branch&gt;</code>, and serving again.</p>
1022
+ <p className="lede">This World's own branches (<code>volter world branch</code>). One runs at a time; “Serve here” stops this one's twins and serves that one in its place.</p>
1023
+ {serveError ? <p role="alert">{serveError}</p> : null}
1014
1024
  <div className="block">
1015
1025
  <table className="dense" aria-label="World branches">
1016
- <thead><tr><th>Branch</th><th>State</th></tr></thead>
1026
+ <thead><tr><th>Branch</th><th>State</th><th /></tr></thead>
1017
1027
  <tbody>
1018
1028
  {branches.data.named!.map((b) => (
1019
1029
  <tr key={b.name}>
1020
1030
  <td><b>{b.name}</b>{b.name === branches.data.checkedOut ? <> <span className="badge">served here</span></> : null}</td>
1021
1031
  <td className="mode">{b.running ? 'running' : 'stopped'}</td>
1032
+ <td className="num row-actions">{canWrite && b.name !== branches.data.checkedOut ? <button type="button" disabled={serving !== null} onClick={() => void serveHere(b.name)}>{serving === b.name ? 'Switching…' : 'Serve here'}</button> : null}</td>
1022
1033
  </tr>
1023
1034
  ))}
1024
1035
  </tbody>