@biolibs/bionet-panels 0.1.0 → 0.3.0
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/README.md +46 -0
- package/dist/backup.d.ts +10 -0
- package/dist/backup.d.ts.map +1 -0
- package/dist/backup.js +50 -0
- package/dist/backup.js.map +1 -0
- package/dist/freezer.d.ts.map +1 -1
- package/dist/freezer.js +4 -2
- package/dist/freezer.js.map +1 -1
- package/dist/history.d.ts +1 -1
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +12 -0
- package/dist/history.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +1 -0
- package/dist/parts.js.map +1 -1
- package/dist/people.d.ts.map +1 -1
- package/dist/people.js +3 -1
- package/dist/people.js.map +1 -1
- package/dist/places.d.ts +41 -0
- package/dist/places.d.ts.map +1 -0
- package/dist/places.js +96 -0
- package/dist/places.js.map +1 -0
- package/dist/public.d.ts +77 -0
- package/dist/public.d.ts.map +1 -0
- package/dist/public.js +73 -0
- package/dist/public.js.map +1 -0
- package/dist/sharing.d.ts.map +1 -1
- package/dist/sharing.js +1 -0
- package/dist/sharing.js.map +1 -1
- package/dist/window.d.ts +29 -6
- package/dist/window.d.ts.map +1 -1
- package/dist/window.js +19 -10
- package/dist/window.js.map +1 -1
- package/package.json +6 -4
- package/panels.css +13 -0
- package/src/backup.tsx +72 -0
- package/src/freezer.tsx +5 -1
- package/src/history.tsx +14 -1
- package/src/index.ts +7 -0
- package/src/parts.tsx +2 -0
- package/src/people.tsx +4 -0
- package/src/places.tsx +170 -0
- package/src/public.tsx +175 -0
- package/src/sharing.tsx +2 -0
- package/src/window.tsx +34 -10
package/src/places.tsx
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
/** The places: where things are kept, which is inside which, and putting a tube somewhere. */
|
|
4
|
+
import type { ItemState, PlaceState } from "@biolibs/bionet";
|
|
5
|
+
import { useAct, useLab } from "@biolibs/bionet-react";
|
|
6
|
+
import { slotFrom, slotName } from "@biolibs/bionet-space";
|
|
7
|
+
import { Ask } from "./parts.js";
|
|
8
|
+
|
|
9
|
+
/** The kinds of place offered when adding one. Any other kind a lab's log holds is shown as it is. */
|
|
10
|
+
export const PLACE_KINDS = ["room", "freezer", "fridge", "shelf", "rack", "box", "bench", "instrument"] as const;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Where a place is, said the way a person would: every place it is inside, then itself.
|
|
14
|
+
*
|
|
15
|
+
* @param places - The lab's places.
|
|
16
|
+
* @param id - The place.
|
|
17
|
+
* @returns Something like `Main lab › −80 › Shelf 2 › Box 7`, or `""` if the lab has no such place.
|
|
18
|
+
*/
|
|
19
|
+
export function placePath(places: readonly Pick<PlaceState, "place" | "name" | "parent">[], id: string): string {
|
|
20
|
+
const names: string[] = [];
|
|
21
|
+
const passed = new Set<string>();
|
|
22
|
+
for (let at: string | null = id; at !== null && !passed.has(at);) {
|
|
23
|
+
const one = places.find((each) => each.place === at);
|
|
24
|
+
if (one === undefined) break;
|
|
25
|
+
passed.add(at);
|
|
26
|
+
names.unshift(one.name);
|
|
27
|
+
at = one.parent;
|
|
28
|
+
}
|
|
29
|
+
return names.join(" › ");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Where an item is, in words.
|
|
34
|
+
*
|
|
35
|
+
* @param item - The item.
|
|
36
|
+
* @param places - The lab's places.
|
|
37
|
+
* @returns Something like `−80 › Box 7 · C4`, or `nowhere recorded`.
|
|
38
|
+
*/
|
|
39
|
+
export function whereWords(item: Pick<ItemState, "where">, places: readonly Pick<PlaceState, "place" | "name" | "parent">[]): string {
|
|
40
|
+
if (item.where === null) return "nowhere recorded";
|
|
41
|
+
const path = placePath(places, item.where.place) || "a place the lab no longer has";
|
|
42
|
+
return item.where.slot === null ? path : `${path} · ${slotName(item.where.slot)}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The places in the order a tree is read: each one followed by what is inside it.
|
|
47
|
+
*
|
|
48
|
+
* @param places - The lab's places.
|
|
49
|
+
* @returns Each place still in use, with how deep it is.
|
|
50
|
+
*/
|
|
51
|
+
export function placeTree(places: readonly PlaceState[]): { place: PlaceState; depth: number }[] {
|
|
52
|
+
const out: { place: PlaceState; depth: number }[] = [];
|
|
53
|
+
const walk = (parent: string | null, depth: number): void => {
|
|
54
|
+
for (const place of places) {
|
|
55
|
+
if (place.parent !== parent || place.retired) continue;
|
|
56
|
+
out.push({ place, depth });
|
|
57
|
+
walk(place.place, depth + 1);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
walk(null, 0);
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Every place as a tree, what needs looking at, and a form to add a place. Draws nothing until the lab has arrived. */
|
|
65
|
+
export function Places() {
|
|
66
|
+
const lab = useLab()?.lab;
|
|
67
|
+
const act = useAct();
|
|
68
|
+
if (lab === null || lab === undefined) return null;
|
|
69
|
+
const tree = placeTree(lab.places);
|
|
70
|
+
const live = lab.items.filter((item) => !item.retired);
|
|
71
|
+
const holding = (id: string): number => live.filter((item) => item.where?.place === id).length;
|
|
72
|
+
return (
|
|
73
|
+
<>
|
|
74
|
+
{lab.crowded.length > 0 && (
|
|
75
|
+
<section className="card">
|
|
76
|
+
<h2>Somebody needs to look</h2>
|
|
77
|
+
<p className="dim small">The lab has more than one tube recorded in each of these positions. Two people put them there without knowing of each other. Move whichever is not really there.</p>
|
|
78
|
+
<ul className="plainlist">
|
|
79
|
+
{lab.crowded.map((one) => (
|
|
80
|
+
<li key={`${one.place} ${one.slot.row} ${one.slot.column}`} className="flagged">
|
|
81
|
+
<strong>{placePath(lab.places, one.place)} · {slotName(one.slot)}</strong> <span className="badge">{one.items.length} tubes</span>
|
|
82
|
+
</li>
|
|
83
|
+
))}
|
|
84
|
+
</ul>
|
|
85
|
+
</section>
|
|
86
|
+
)}
|
|
87
|
+
<section className="card">
|
|
88
|
+
<h2>Where things are kept</h2>
|
|
89
|
+
{tree.length === 0 ? <p className="empty">No places yet. Add the first below: a freezer, then the boxes in it.</p> : (
|
|
90
|
+
<table>
|
|
91
|
+
<thead><tr><th>Place</th><th>Kind</th><th>Positions</th><th>Tubes here</th><th /></tr></thead>
|
|
92
|
+
<tbody>
|
|
93
|
+
{tree.map(({ place, depth }) => (
|
|
94
|
+
<tr key={place.place} className={place.adrift ? "flagged" : undefined}>
|
|
95
|
+
<td style={{ paddingLeft: `${0.6 + depth * 1.2}rem` }}>
|
|
96
|
+
{place.name}
|
|
97
|
+
{place.adrift && <span className="badge" title="Two people each moved this place and another into one another. Move one of them to settle it.">needs moving</span>}
|
|
98
|
+
</td>
|
|
99
|
+
<td className="dim">{place.kind}</td>
|
|
100
|
+
<td className="dim">{place.grid === null ? "" : `${place.grid.rows} × ${place.grid.columns}`}</td>
|
|
101
|
+
<td>{holding(place.place) || ""}</td>
|
|
102
|
+
<td><button type="button" className="plain" onClick={() => void act("retirePlace", { place: place.place })}>retire</button></td>
|
|
103
|
+
</tr>
|
|
104
|
+
))}
|
|
105
|
+
</tbody>
|
|
106
|
+
</table>
|
|
107
|
+
)}
|
|
108
|
+
</section>
|
|
109
|
+
<section className="card">
|
|
110
|
+
<h2>Add a place</h2>
|
|
111
|
+
<p className="dim small">A place is anything something is kept in or on. Only a box has positions; give it rows and columns and its tubes can be found by letter and number.</p>
|
|
112
|
+
<Ask className="stack" onAsk={(data) => {
|
|
113
|
+
const rows = Number(data.get("rows") ?? "");
|
|
114
|
+
const columns = Number(data.get("columns") ?? "");
|
|
115
|
+
const parent = String(data.get("parent") ?? "");
|
|
116
|
+
return act("addPlace", { kind: String(data.get("kind") ?? ""), name: String(data.get("name") ?? ""), parent: parent === "" ? null : parent,
|
|
117
|
+
grid: rows > 0 && columns > 0 ? { rows, columns } : null });
|
|
118
|
+
}}>
|
|
119
|
+
<label>Kind<select name="kind" defaultValue="box">{PLACE_KINDS.map((kind) => <option key={kind} value={kind}>{kind}</option>)}</select></label>
|
|
120
|
+
<label>Name<input name="name" placeholder="Box 7" required maxLength={200} /></label>
|
|
121
|
+
<label>Inside
|
|
122
|
+
<select name="parent" defaultValue="">
|
|
123
|
+
<option value="">nothing</option>
|
|
124
|
+
{tree.map(({ place, depth }) => <option key={place.place} value={place.place}>{" ".repeat(depth)}{place.name}</option>)}
|
|
125
|
+
</select>
|
|
126
|
+
</label>
|
|
127
|
+
<div className="row tight">
|
|
128
|
+
<input name="rows" type="number" min={1} max={100} step={1} placeholder="Rows" aria-label="Rows" className="num" />
|
|
129
|
+
<input name="columns" type="number" min={1} max={100} step={1} placeholder="Columns" aria-label="Columns" className="num" />
|
|
130
|
+
<span className="dim small">for a box</span>
|
|
131
|
+
</div>
|
|
132
|
+
<button type="submit">Add place</button>
|
|
133
|
+
</Ask>
|
|
134
|
+
</section>
|
|
135
|
+
</>
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Where one tube is, and a way to put it somewhere.
|
|
141
|
+
*
|
|
142
|
+
* @param props - `item` is the tube.
|
|
143
|
+
*/
|
|
144
|
+
export function PutItem({ item }: { item: ItemState }) {
|
|
145
|
+
const lab = useLab()?.lab;
|
|
146
|
+
const act = useAct();
|
|
147
|
+
if (lab === null || lab === undefined) return null;
|
|
148
|
+
const tree = placeTree(lab.places);
|
|
149
|
+
return (
|
|
150
|
+
<div className="where">
|
|
151
|
+
<span className={item.where === null ? "dim small" : "small"}>{whereWords(item, lab.places)}</span>
|
|
152
|
+
{tree.length > 0 && (
|
|
153
|
+
<Ask className="row tight" onAsk={async (data) => {
|
|
154
|
+
const place = String(data.get("place") ?? "");
|
|
155
|
+
const written = String(data.get("slot") ?? "").trim();
|
|
156
|
+
const slot = written === "" ? null : slotFrom(written);
|
|
157
|
+
// A position that is not written like one is sent as it is not: the lab refuses it and says why.
|
|
158
|
+
return act("putItem", { item: item.item, place: place === "" ? null : place, slot: written !== "" && slot === null ? { row: -1, column: -1 } : slot });
|
|
159
|
+
}}>
|
|
160
|
+
<select name="place" defaultValue={item.where?.place ?? ""} aria-label="Place">
|
|
161
|
+
<option value="">nowhere</option>
|
|
162
|
+
{tree.map(({ place, depth }) => <option key={place.place} value={place.place}>{" ".repeat(depth)}{place.name}</option>)}
|
|
163
|
+
</select>
|
|
164
|
+
<input name="slot" placeholder="A1" aria-label="Position" className="num" maxLength={5} />
|
|
165
|
+
<button type="submit" className="quiet">Put</button>
|
|
166
|
+
</Ask>
|
|
167
|
+
)}
|
|
168
|
+
</div>
|
|
169
|
+
);
|
|
170
|
+
}
|
package/src/public.tsx
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a lab shows the world, and what it can see of another lab.
|
|
3
|
+
*
|
|
4
|
+
* These are for a lab's public page. They take what was fetched and checked as plain values and
|
|
5
|
+
* draw it; none of them fetches, signs or holds state, so they can be drawn on a server.
|
|
6
|
+
*
|
|
7
|
+
* They also carry the wording. What a signature settles, and what it does not, has to be said the
|
|
8
|
+
* same way on every lab's page — a page that words it itself will sooner or later claim more than
|
|
9
|
+
* the checks support.
|
|
10
|
+
*/
|
|
11
|
+
import type { ReactNode } from "react";
|
|
12
|
+
import { settled, type FetchedInventory, type InventoryPart } from "@biolibs/bionet";
|
|
13
|
+
import type { SignatureCheck } from "@biolibs/opencloning";
|
|
14
|
+
import { Mark } from "@biolibs/bionet-react";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The parts in one list whose checksums are not in another.
|
|
18
|
+
*
|
|
19
|
+
* @param mine - What this lab holds.
|
|
20
|
+
* @param theirs - What the other lab holds.
|
|
21
|
+
* @returns What they have that this lab does not. Names play no part: a part is its checksum.
|
|
22
|
+
*/
|
|
23
|
+
export function onlyTheirs(mine: readonly InventoryPart[], theirs: readonly InventoryPart[]): InventoryPart[] {
|
|
24
|
+
const have = new Set(mine.map((part) => part.checksum));
|
|
25
|
+
return theirs.filter((part) => !have.has(part.checksum));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The parts two lists both hold, by checksum.
|
|
30
|
+
*
|
|
31
|
+
* @param mine - What this lab holds.
|
|
32
|
+
* @param theirs - What the other lab holds.
|
|
33
|
+
* @returns This lab's entries for the parts both have.
|
|
34
|
+
*/
|
|
35
|
+
export function heldByBoth(mine: readonly InventoryPart[], theirs: readonly InventoryPart[]): InventoryPart[] {
|
|
36
|
+
const have = new Set(theirs.map((part) => part.checksum));
|
|
37
|
+
return mine.filter((part) => have.has(part.checksum));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The frame of a lab's public page: the mark, the lab's name, and a line about what it is.
|
|
42
|
+
*
|
|
43
|
+
* @param props - `name` and `note` are the lab's; `children` is the rest of the page.
|
|
44
|
+
*/
|
|
45
|
+
export function LabPage({ name, note, children }: { name: string; note?: string | null; children: ReactNode }) {
|
|
46
|
+
return (
|
|
47
|
+
<div className="bionet">
|
|
48
|
+
<main className="page">
|
|
49
|
+
<div className="title">
|
|
50
|
+
<Mark size={40} />
|
|
51
|
+
<h1>{name}</h1>
|
|
52
|
+
</div>
|
|
53
|
+
{note !== null && note !== undefined && <p className="dim">{note}</p>}
|
|
54
|
+
<p className="small dim">
|
|
55
|
+
This lab publishes what it holds at{" "}
|
|
56
|
+
<a href="/.well-known/bionet.json"><code>/.well-known/bionet.json</code></a>, signed, so that a
|
|
57
|
+
cloning plan can be acted on and not just read. Parts are named by checksum, because a name
|
|
58
|
+
agrees with nothing.
|
|
59
|
+
</p>
|
|
60
|
+
{children}
|
|
61
|
+
</main>
|
|
62
|
+
</div>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** A table of parts: name, length, and whether each is on offer. `checksums` adds that column. */
|
|
67
|
+
export function PartsTable({ parts, checksums = false }: { parts: readonly InventoryPart[]; checksums?: boolean }) {
|
|
68
|
+
return (
|
|
69
|
+
<table>
|
|
70
|
+
<thead><tr><th>Part</th><th>Length</th>{checksums && <th>Checksum</th>}<th>On offer</th></tr></thead>
|
|
71
|
+
<tbody>
|
|
72
|
+
{parts.map((part) => (
|
|
73
|
+
<tr key={part.checksum}>
|
|
74
|
+
<td>{part.name}{part.note !== null && <><br /><span className="dim small">{part.note}</span></>}</td>
|
|
75
|
+
<td className="nowrap"><code>{part.length} bp{part.circular ? " ○" : ""}</code></td>
|
|
76
|
+
{checksums && <td className="dim"><code>{part.checksum.slice(0, 22)}…</code></td>}
|
|
77
|
+
<td className={part.available ? "good" : "bad"}>{part.available ? "yes" : "no"}</td>
|
|
78
|
+
</tr>
|
|
79
|
+
))}
|
|
80
|
+
</tbody>
|
|
81
|
+
</table>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* What this lab holds, and what the signature over that list settles.
|
|
87
|
+
*
|
|
88
|
+
* @param props - `parts` is the published list; `checks` is one check per signature over it;
|
|
89
|
+
* `origin` is the address this page is served from; `bound` is whether the list names that address.
|
|
90
|
+
*/
|
|
91
|
+
export function Held({ parts, checks, origin, bound }: {
|
|
92
|
+
parts: readonly InventoryPart[]; checks: readonly SignatureCheck[]; origin: string; bound: boolean;
|
|
93
|
+
}) {
|
|
94
|
+
const holds = checks.length > 0 && checks.every((check) => check.ok);
|
|
95
|
+
return (
|
|
96
|
+
<section>
|
|
97
|
+
<h2>What we hold</h2>
|
|
98
|
+
{parts.length === 0 ? <p className="dim">Nothing is listed at the moment.</p> : <PartsTable parts={parts} checksums />}
|
|
99
|
+
<p className="small dim">
|
|
100
|
+
{checks.length === 0 ? "This list is not signed, so it claims nothing about who published it." : (
|
|
101
|
+
<>
|
|
102
|
+
Signed by {checks.map((check) => <code key={check.public_key}>{check.fingerprint} </code>)}
|
|
103
|
+
{holds ? "— the signature holds over this list as served." : "— the signature does not hold."}
|
|
104
|
+
</>
|
|
105
|
+
)}{" "}
|
|
106
|
+
Bound to <code>{origin}</code>: {bound ? "yes" : "no"}.
|
|
107
|
+
</p>
|
|
108
|
+
</section>
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The caveat every reader is owed, in the same words everywhere. */
|
|
113
|
+
export function WhatASignatureSettles() {
|
|
114
|
+
return (
|
|
115
|
+
<p className="small dim">
|
|
116
|
+
None of that says this lab is who it says it is. The address does that work, and only as far as
|
|
117
|
+
whoever typed it already trusted it. What a signature settles is that this list has not changed
|
|
118
|
+
since it was published, and that it was published by whoever holds that key.
|
|
119
|
+
</p>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Another lab that answered, beside what this lab holds.
|
|
125
|
+
*
|
|
126
|
+
* @param props - `found` is what was fetched from the other lab and checked; `mine` is this lab's list.
|
|
127
|
+
*/
|
|
128
|
+
export function PeerAnswered({ found, mine }: { found: FetchedInventory; mine: readonly InventoryPart[] }) {
|
|
129
|
+
const theirs = found.signed.inventory.parts;
|
|
130
|
+
const only = onlyTheirs(mine, theirs);
|
|
131
|
+
const both = heldByBoth(mine, theirs);
|
|
132
|
+
return (
|
|
133
|
+
<>
|
|
134
|
+
<p>
|
|
135
|
+
<strong>{found.signed.inventory.lab.name}</strong> answered at <code>{found.origin}</code> with{" "}
|
|
136
|
+
{theirs.length} {theirs.length === 1 ? "part" : "parts"}.{" "}
|
|
137
|
+
{settled(found)
|
|
138
|
+
? <span className="good">Its signature holds and it was served from the address it names.</span>
|
|
139
|
+
: <span className="bad">Its signature or its address does not check out, so nothing below is settled.</span>}
|
|
140
|
+
</p>
|
|
141
|
+
<WhatASignatureSettles />
|
|
142
|
+
<h3>What they have that we do not</h3>
|
|
143
|
+
{only.length === 0 ? <p className="small">Nothing. Everything they list, we hold too.</p> : <PartsTable parts={only} />}
|
|
144
|
+
<h3>What we both have</h3>
|
|
145
|
+
{both.length === 0 ? <p className="small">Nothing in common, by checksum.</p> : (
|
|
146
|
+
<p className="small">
|
|
147
|
+
{both.map((part) => <code key={part.checksum}>{part.name} </code>)}
|
|
148
|
+
— matched by checksum, so it does not matter what either of us calls them.
|
|
149
|
+
</p>
|
|
150
|
+
)}
|
|
151
|
+
<p className="small dim">
|
|
152
|
+
Fetched from that lab when this page was drawn, not copied. Nothing here fetches a part: finding
|
|
153
|
+
out who has a plasmid is as far as software goes, and the rest is an email and a padded envelope.
|
|
154
|
+
</p>
|
|
155
|
+
</>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Another lab that did not answer.
|
|
161
|
+
*
|
|
162
|
+
* @param props - `address` is where it was asked for; `why` is what went wrong.
|
|
163
|
+
*/
|
|
164
|
+
export function PeerSilent({ address, why }: { address: string; why: string }) {
|
|
165
|
+
return (
|
|
166
|
+
<>
|
|
167
|
+
<p>We point at <code>{address}</code> and it did not answer.</p>
|
|
168
|
+
<p className="small dim">
|
|
169
|
+
The reason given was: {why}. A lab that cannot be reached is not a lab that is lying — it may be
|
|
170
|
+
down, or moved, or never have existed. All this page can honestly say is that the address did
|
|
171
|
+
not answer when it was asked.
|
|
172
|
+
</p>
|
|
173
|
+
</>
|
|
174
|
+
);
|
|
175
|
+
}
|
package/src/sharing.tsx
CHANGED
package/src/window.tsx
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* A whole lab application, in one component.
|
|
3
5
|
*
|
|
@@ -8,34 +10,51 @@
|
|
|
8
10
|
* It walks a person through the three places they can be: nobody has said who is at this device,
|
|
9
11
|
* the device is in no lab, the device is waiting to be let into one — and then the lab itself.
|
|
10
12
|
*/
|
|
11
|
-
import { useState } from "react";
|
|
13
|
+
import { useState, type ReactNode } from "react";
|
|
12
14
|
import { Logo, Mark, useAct, useLab } from "@biolibs/bionet-react";
|
|
13
15
|
import { Freezer } from "./freezer.js";
|
|
14
16
|
import { History } from "./history.js";
|
|
15
17
|
import { Ask, CopyContext, DeviceKey, SyncStatus, Trouble } from "./parts.js";
|
|
18
|
+
import { RestoreKey, SaveContext } from "./backup.js";
|
|
16
19
|
import { People } from "./people.js";
|
|
20
|
+
import { Places } from "./places.js";
|
|
17
21
|
import { Sharing } from "./sharing.js";
|
|
18
22
|
|
|
19
|
-
/** The
|
|
20
|
-
export const TABS = ["freezer", "people", "history", "sharing"] as const;
|
|
23
|
+
/** The things a member looks at. */
|
|
24
|
+
export const TABS = ["freezer", "places", "people", "history", "sharing"] as const;
|
|
21
25
|
|
|
22
26
|
/** One of them. */
|
|
23
27
|
export type Tab = (typeof TABS)[number];
|
|
24
28
|
|
|
29
|
+
/** A view a host adds to the window beside its own, such as a drawing of the lab. */
|
|
30
|
+
export interface ExtraTab {
|
|
31
|
+
/** What tells it apart. */
|
|
32
|
+
id: string;
|
|
33
|
+
/** What its tab says. */
|
|
34
|
+
label: string;
|
|
35
|
+
/** What it shows. It is inside the lab's provider, so it may use the hooks. */
|
|
36
|
+
view: ReactNode;
|
|
37
|
+
}
|
|
38
|
+
|
|
25
39
|
/**
|
|
26
40
|
* The window.
|
|
27
41
|
*
|
|
28
|
-
* @param props - `tab` is which view to open on; `copy` puts words on the clipboard
|
|
29
|
-
* cannot use the browser's own way
|
|
42
|
+
* @param props - `tab` is which view to open on; `copy` puts words on the clipboard and `save` hands
|
|
43
|
+
* over a file, for a host that cannot use the browser's own way; `extra` are views the host adds,
|
|
44
|
+
* shown after the window's own.
|
|
30
45
|
*/
|
|
31
|
-
export function LabWindow({ tab: first = "freezer", copy
|
|
32
|
-
|
|
33
|
-
|
|
46
|
+
export function LabWindow({ tab: first = "freezer", copy, save, extra = [] }: {
|
|
47
|
+
tab?: Tab | string; copy?: (words: string) => Promise<void>; save?: (name: string, text: string) => Promise<void>; extra?: readonly ExtraTab[];
|
|
48
|
+
}) {
|
|
49
|
+
let window = <Body first={first} extra={extra} />;
|
|
50
|
+
if (save !== undefined) window = <SaveContext.Provider value={save}>{window}</SaveContext.Provider>;
|
|
51
|
+
if (copy !== undefined) window = <CopyContext.Provider value={copy}>{window}</CopyContext.Provider>;
|
|
52
|
+
return <div className="bionet">{window}</div>;
|
|
34
53
|
}
|
|
35
54
|
|
|
36
|
-
function Body({ first }: { first:
|
|
55
|
+
function Body({ first, extra }: { first: string; extra: readonly ExtraTab[] }) {
|
|
37
56
|
const state = useLab();
|
|
38
|
-
const [tab, setTab] = useState<
|
|
57
|
+
const [tab, setTab] = useState<string>(first);
|
|
39
58
|
if (state === null) return <main className="centre"><p className="dim">Opening the lab…</p></main>;
|
|
40
59
|
if (state.device.person === null) return <main className="centre"><Logo /><Trouble /><Who /></main>;
|
|
41
60
|
if (state.lab === null) return <main className="centre"><Logo /><Trouble /><NoLab /></main>;
|
|
@@ -44,6 +63,7 @@ function Body({ first }: { first: Tab }) {
|
|
|
44
63
|
const lab = state.lab;
|
|
45
64
|
const label: Record<Tab, string> = {
|
|
46
65
|
freezer: `Freezer · ${lab.items.filter((item) => !item.retired).length}`,
|
|
66
|
+
places: `Places · ${lab.places.filter((place) => !place.retired).length}`,
|
|
47
67
|
people: `People · ${lab.roster.filter((key) => key.removed === null).length}`,
|
|
48
68
|
history: `History · ${lab.entries.length}`,
|
|
49
69
|
sharing: "Sharing",
|
|
@@ -62,13 +82,16 @@ function Body({ first }: { first: Tab }) {
|
|
|
62
82
|
</header>
|
|
63
83
|
<nav>
|
|
64
84
|
{TABS.map((one) => <button key={one} type="button" className={one === tab ? "tab on" : "tab"} onClick={() => setTab(one)}>{label[one]}</button>)}
|
|
85
|
+
{extra.map((one) => <button key={one.id} type="button" className={one.id === tab ? "tab on" : "tab"} onClick={() => setTab(one.id)}>{one.label}</button>)}
|
|
65
86
|
</nav>
|
|
66
87
|
<main>
|
|
67
88
|
<Trouble />
|
|
68
89
|
{tab === "freezer" && <Freezer />}
|
|
90
|
+
{tab === "places" && <Places />}
|
|
69
91
|
{tab === "people" && <People />}
|
|
70
92
|
{tab === "history" && <History />}
|
|
71
93
|
{tab === "sharing" && <Sharing />}
|
|
94
|
+
{extra.find((one) => one.id === tab)?.view}
|
|
72
95
|
</main>
|
|
73
96
|
</div>
|
|
74
97
|
);
|
|
@@ -113,6 +136,7 @@ export function NoLab() {
|
|
|
113
136
|
<label>Invitation<input name="invite" placeholder="wss://your-lab.example/sync#…" required /></label>
|
|
114
137
|
<button type="submit">Join</button>
|
|
115
138
|
</Ask>
|
|
139
|
+
<RestoreKey />
|
|
116
140
|
</section>
|
|
117
141
|
</div>
|
|
118
142
|
);
|