@vibes.diy/prompts 14.3.287 → 14.3.288
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/llms/chess-variants.md +30 -3
- package/llms/fireproof.md +2 -0
- package/llms/stripe.md +32 -13
- package/llms/ui-quiz.md +87 -70
- package/llms/ui-storefront.md +57 -24
- package/package.json +5 -5
package/llms/chess-variants.md
CHANGED
|
@@ -7,9 +7,10 @@ stands on the board-games skill, which owns the board's look, turns, seats and w
|
|
|
7
7
|
Standard chess on 8×8 is the chess skill's (`chess.js` and Stockfish); this doc replaces both for
|
|
8
8
|
every other game:
|
|
9
9
|
|
|
10
|
-
1. **The rules come from ffish**, Fairy-Stockfish's rules library, in a Web Worker
|
|
11
|
-
|
|
12
|
-
writes a move generator, even for a
|
|
10
|
+
1. **The rules come from ffish**, Fairy-Stockfish's rules library, in a Web Worker, whether the
|
|
11
|
+
opponent is the computer or a friend on another phone. It knows about 120 variants by name and
|
|
12
|
+
reads a new one from a few lines of text, so an app never writes a move generator, even for a
|
|
13
|
+
piece nobody has played before.
|
|
13
14
|
2. **The computer opponent is fairy-stockfish-single**, the Fairy-Stockfish engine built to run on
|
|
14
15
|
one thread, in a second Web Worker. It plays every variant the rules worker knows, at any
|
|
15
16
|
strength, and keeps the page responsive while it thinks.
|
|
@@ -80,6 +81,23 @@ flagRegionBlack = *1
|
|
|
80
81
|
promotionPieceTypes = q
|
|
81
82
|
```
|
|
82
83
|
|
|
84
|
+
**A piece that moves differently swaps its letter onto another piece type.** Bishops that also
|
|
85
|
+
jump like knights are the built-in archbishop (bishop plus knight) wearing the bishop's letter:
|
|
86
|
+
|
|
87
|
+
```ini
|
|
88
|
+
[leapingbishops:chess]
|
|
89
|
+
bishop = -
|
|
90
|
+
archbishop = b
|
|
91
|
+
promotionPieceTypes = qrbn
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Name the promotion pieces again after a swap: removing `bishop` also drops it from promotion, and
|
|
95
|
+
`b` in `promotionPieceTypes` now means the archbishop.
|
|
96
|
+
|
|
97
|
+
The built-in types cover most club ideas: `archbishop` (B+N), `chancellor` (R+N), `amazon` (Q+N),
|
|
98
|
+
`centaur` (K+N), `commoner` (moves like a king but is not one), `wazir`, `fers`, `alfil`. Anything else
|
|
99
|
+
is a `customPiece` in Betza notation. Variants.ini lists every type and its letter.
|
|
100
|
+
|
|
83
101
|
The section name is the variant's id for `new ff.Board("pawnwars")` and for the engine's
|
|
84
102
|
`UCI_Variant`. Load the same string into both workers.
|
|
85
103
|
|
|
@@ -103,6 +121,15 @@ vibe's page does not have. `VibesDIY/fairy-stockfish-single` is the same engine
|
|
|
103
121
|
- **Credit it.** ffish and the engine are GPL-3 and run unmodified in their own workers; a muted
|
|
104
122
|
line under the board says "Rules and engine: Fairy-Stockfish (GPL-3)".
|
|
105
123
|
|
|
124
|
+
## Two players on two phones
|
|
125
|
+
|
|
126
|
+
A friend on their own phone is the board-games turn rule: one game doc holds the `variant`, the
|
|
127
|
+
`moves` list and the two seats, and only the seat whose turn it is writes. Each phone asks its
|
|
128
|
+
rules worker for the position after `moves` and accepts a move only when it is in `legal`, the same
|
|
129
|
+
as against the computer; there is just no engine worker. `access.js` cannot run ffish, so it checks
|
|
130
|
+
the seat, the turn, that `variant` is unchanged, and that the new `moves` is the old list with
|
|
131
|
+
exactly one move appended (every earlier move identical), so a turn can only add to the game.
|
|
132
|
+
|
|
106
133
|
## Drawing the board — any size
|
|
107
134
|
|
|
108
135
|
Draw the board-games SVG board from the FEN, whatever its size: `parseBoard(fen)` in the example
|
package/llms/fireproof.md
CHANGED
|
@@ -21,6 +21,8 @@ Each document has an `_id`, which can be auto-generated or set explicitly. Auto-
|
|
|
21
21
|
|
|
22
22
|
Use granular documents, e.g. one document per user action, so saving a form or clicking a button should typically create or update a single document, or just a few documents. Avoid patterns that require a single document to grow without bound.
|
|
23
23
|
|
|
24
|
+
A flow someone moves through in steps (a quiz, a wizard, a game run, a bag or cart, a booking) is data from its first step. Write its parent record with the first step, then save each answer, pick, move or line as its own document carrying the parent's id (`attemptId`, `orderId`, `bagId`) the moment it is made, with a deterministic `_id` such as `` `${attemptId}:${step}` `` so a repeat rewrites one row. The parent's open record and a `useLiveQuery` on that id rebuild the screen, so a reload, another device or the person's own agent lands where they were. Scores, types and totals are computed from those rows; a snapshot stored on the parent when the flow finishes sits beside them and never replaces them. React state holds only what means nothing outside this screen: the open tab, the choice not yet confirmed, a hover.
|
|
25
|
+
|
|
24
26
|
`useLiveQuery` populates and refreshes the UI reactively as data arrives, so render an inviting empty state while a list has nothing in it. Writes are optimistic and local: `put()`/`save()`/`del()` land in the local replica instantly, and transport or offline failures queue and retry on their own. The server's access rules have the final word: a refused write converges **server-wins** to the server's version, and the **platform** tells the visitor — in the app's own `forbidden("…")` words when it gave some, its own line otherwise, and "saved on this device" when a signed-out visitor's save waits for sign-in. So write plainly and let the store be the feedback: render from `useLiveQuery`/`useDocument`, gate write surfaces up front with `useVibe(dbName).can.create/edit/delete` so only allowed actions render, and keep `try/catch` for a save carrying `_files` (covered with the image uploader below). A toggle shows the whole shape — flip it at once, follow its receipt beside the control, and the list re-reads itself:
|
|
25
27
|
|
|
26
28
|
```jsx
|
package/llms/stripe.md
CHANGED
|
@@ -1078,15 +1078,17 @@ and `rev`, a fresh random string on every write, which is the version the
|
|
|
1078
1078
|
Pay link names. Its lines take one of two shapes, and a shop picks the one
|
|
1079
1079
|
that fits:
|
|
1080
1080
|
|
|
1081
|
-
- **Lines on the bag.** `lines: [{ productId, qty }]` on the bag itself, and
|
|
1082
|
-
every change is one put of the whole bag with a new `rev`. Right for most
|
|
1083
|
-
shops: one record, one write, nothing to keep in step.
|
|
1084
1081
|
- **A record per line.** Each line is its own `type: "line"` record with
|
|
1085
1082
|
`bagId`, `productId`, `qty` and whatever options it carries (size, milk,
|
|
1086
1083
|
engraving), and every line write also puts the bag with a new `rev` and
|
|
1087
|
-
`touchedAt`. Right
|
|
1088
|
-
|
|
1089
|
-
|
|
1084
|
+
`touchedAt`. Right for most shops: each line can be read, counted and
|
|
1085
|
+
changed on its own, the shop can tally a product across bags, and anyone
|
|
1086
|
+
helping the buyer adds a line without rewriting the rest. The line carries
|
|
1087
|
+
the `touchedAt` of the bag write that went with it, so a line newer than
|
|
1088
|
+
the bag was written after the link and is not in it.
|
|
1089
|
+
- **Lines on the bag.** `lines: [{ productId, qty }]` on the bag itself, and
|
|
1090
|
+
every change is one put of the whole bag with a new `rev`. Right only for a
|
|
1091
|
+
bag of one or two fixed things that nobody reads line by line.
|
|
1090
1092
|
|
|
1091
1093
|
A line's options are the shop's to price: `priceBag` reads them off the line
|
|
1092
1094
|
and adds what the owner's product record says they cost, so a modifier is
|
|
@@ -1187,9 +1189,17 @@ answer, and the page puts the bag on it.
|
|
|
1187
1189
|
### `App.jsx`
|
|
1188
1190
|
```jsx partial
|
|
1189
1191
|
// The buyer's open bag: theirs alone (access.js routes it to their own channel), and the newest one
|
|
1190
|
-
// no paid order names.
|
|
1192
|
+
// no paid order names. Its lines are records naming it by bagId; every Add puts one line and the
|
|
1193
|
+
// bag with a fresh rev.
|
|
1191
1194
|
const { docs: bags } = useLiveQuery("type", { key: "bag" });
|
|
1192
1195
|
const bag = me && bags.filter((b) => b.buyerHandle === me.userHandle && !orders.some((o) => o.bagId === b._id && o.status === "paid")).sort((a, b) => b.touchedAt - a.touchedAt)[0];
|
|
1196
|
+
const { docs: bagLines } = useLiveQuery("bagId", { key: bag?._id ?? "" });
|
|
1197
|
+
const savedLines = bagLines.filter((l) => l.type === "line" && l.buyerHandle === me?.userHandle);
|
|
1198
|
+
// A bag this page started that the live query has not returned yet: two quick Adds share it.
|
|
1199
|
+
const startedBag = useRef(null);
|
|
1200
|
+
useEffect(() => {
|
|
1201
|
+
if (bag) startedBag.current = null; // the query has it now, and a paid bag must not be reused
|
|
1202
|
+
}, [bag?._id]);
|
|
1193
1203
|
// A guest's bag: page state kept in localStorage, emptied when their payment comes back paid.
|
|
1194
1204
|
const [guestLines, setGuestLines] = useState(() => {
|
|
1195
1205
|
try {
|
|
@@ -1207,12 +1217,21 @@ useEffect(() => {
|
|
|
1207
1217
|
useEffect(() => {
|
|
1208
1218
|
if (!me && back?.status === "paid") setGuestLines([]);
|
|
1209
1219
|
}, [me, back?.status]);
|
|
1210
|
-
const lines = (
|
|
1211
|
-
const add = (productId) => {
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1220
|
+
const lines = (me ? savedLines : guestLines).filter((l) => forSale.some((p) => p._id === l.productId));
|
|
1221
|
+
const add = async (productId) => {
|
|
1222
|
+
if (!me) {
|
|
1223
|
+
const next = guestLines.some((l) => l.productId === productId) ? guestLines.map((l) => (l.productId === productId ? { ...l, qty: l.qty + 1 } : l)) : [...guestLines, { productId, qty: 1 }];
|
|
1224
|
+
return setGuestLines(next);
|
|
1225
|
+
}
|
|
1226
|
+
// One line per product, its id derived from the bag and the product, so a second Add is a new
|
|
1227
|
+
// quantity on the same line, options and all. The bag takes its new rev FIRST, so a Pay link to
|
|
1228
|
+
// the old version is refused before its line changes; the line shares the bag's touchedAt, so
|
|
1229
|
+
// /pay counts it in this version.
|
|
1230
|
+
const bagId = bag?._id ?? (startedBag.current ??= "bag-" + crypto.randomUUID());
|
|
1231
|
+
const touchedAt = Date.now();
|
|
1232
|
+
const line = savedLines.find((l) => l.productId === productId);
|
|
1233
|
+
await database.put({ ...(bag ?? { _id: bagId, type: "bag", buyerHandle: me.userHandle }), rev: crypto.randomUUID(), touchedAt });
|
|
1234
|
+
await database.put({ ...(line ?? { _id: `${bagId}:${productId}`, type: "line", bagId, buyerHandle: me.userHandle, productId }), qty: (line?.qty ?? 0) + 1, touchedAt });
|
|
1216
1235
|
};
|
|
1217
1236
|
// The same address anyone helping the buyer would hand them. The subtotal is a preview; /pay prices it.
|
|
1218
1237
|
const payUrl = bag && setup?.pay && `${setup.pay}?bag=${encodeURIComponent(bag._id)}&rev=${encodeURIComponent(bag.rev)}&mode=${setup.mode}`;
|
package/llms/ui-quiz.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Quiz
|
|
2
2
|
|
|
3
|
-
A short multiple-choice quiz that keeps score: an astronomy club's star-chart check, a refresher round before a test, a pub quiz warm-up, a training check for new staff. Reach for it when the app asks a handful of questions one at a time, says right or wrong after each answer, ends on a score and lets people come back to beat it.
|
|
3
|
+
A short multiple-choice quiz that keeps score: an astronomy club's star-chart check, a refresher round before a test, a pub quiz warm-up, a training check for new staff. Reach for it when the app asks a handful of questions one at a time, says right or wrong after each answer, ends on a score and lets people come back to beat it. Every answer is its own document the moment it is checked, keyed to its attempt, so a reload or another device opens the quiz at the question the person reached, their past attempts are there on the next visit, and the score is computed from the answers.
|
|
4
4
|
|
|
5
5
|
Built from @vibes.diy/ui components; persisted state lives in Fireproof. Every write surface is gated on `useVibe(dbName).can`.
|
|
6
6
|
|
|
7
7
|
## The block
|
|
8
8
|
|
|
9
|
-
One view with one job: answer the questions, then keep the score. A `Heading` and a muted line open the page. The quiz sits on a `Card`: an `Eyebrow` with the question number beside an `info` `Badge` counting correct answers so far (it steps aside on the result, which states the score once), and a `Progress` (`info`) across the top. Each question is a `Heading level={2}` over a `RadioGroup`; `Check answer` is the view's one lead, then the answer shows as a `Badge` (`up` right, `down` wrong) with the right option in muted `Text`, and the lead becomes `Next question`. The result swaps in an `IconTile` (`up` for a pass, `warn` otherwise), the score and a recap of every question with its own `up` or `down` `Badge`. `
|
|
9
|
+
One view with one job: answer the questions, then keep the score. A `Heading` and a muted line open the page. The quiz sits on a `Card`: an `Eyebrow` with the question number beside an `info` `Badge` counting correct answers so far (it steps aside on the result, which states the score once), and a `Progress` (`info`) across the top. Each question is a `Heading level={2}` over a `RadioGroup`; `Check answer` is the view's one lead, then the answer shows as a `Badge` (`up` right, `down` wrong) with the right option in muted `Text`, and the lead becomes `Next question`. The result swaps in an `IconTile` (`up` for a pass, `warn` otherwise), the score and a recap of every question with its own `up` or `down` `Badge`. A quiet `Play again` sits beside a line saying the attempt is kept. A signed-in person's finished attempts sit below as `RowCard`s, newest first, each with a `Badge` toned by how it went. Keeping answers waits on its `can` verdict from `useVibe("quiz")`, the database the attempts live in: a `Skeleton` inside an `aria-busy` wrapper while it resolves, a `Sign in to keep your answers` lead wired to `useViewer().requestLogin()` for a visitor who has not signed in, and a sentence in the app's own words when keeping is closed. Anyone can take the quiz without signing in; a visitor's answers stay on the page, and the copy invites them to sign in so every answer is kept as they go.
|
|
10
10
|
|
|
11
11
|
### `App.jsx`
|
|
12
12
|
```jsx
|
|
@@ -71,67 +71,87 @@ const when = (ms) => new Date(ms).toLocaleDateString(undefined, { month: "short"
|
|
|
71
71
|
|
|
72
72
|
export default function App() {
|
|
73
73
|
const { database, useLiveQuery } = useFireproof("quiz");
|
|
74
|
-
const { docs } = useLiveQuery("type", { key: "attempt" });
|
|
74
|
+
const { docs: attempts } = useLiveQuery("type", { key: "attempt" });
|
|
75
75
|
const { can, me } = useVibe("quiz");
|
|
76
76
|
const { requestLogin } = useViewer();
|
|
77
77
|
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
const [choice, setChoice] = useState("");
|
|
81
|
-
const [revealed, setRevealed] = useState(false);
|
|
82
|
-
const [results, setResults] = useState([]);
|
|
83
|
-
const [saving, setSaving] = useState(false);
|
|
84
|
-
const [savedResults, setSavedResults] = useState(undefined);
|
|
85
|
-
|
|
86
|
-
const question = QUESTIONS[step];
|
|
87
|
-
const score = results.filter(Boolean).length;
|
|
88
|
-
const done = results.length === TOTAL;
|
|
89
|
-
const lastRight = results[results.length - 1];
|
|
90
|
-
|
|
91
|
-
// One document per saved attempt; this person's, newest first.
|
|
78
|
+
// This person's attempts, newest first. One without `finishedAt` is the quiz they are partway
|
|
79
|
+
// through: a reload, another device or another tab opens it at the question they reached.
|
|
92
80
|
const mine = me
|
|
93
|
-
?
|
|
94
|
-
.filter((d) => d.quiz === QUIZ_ID && d.authorHandle === me.userHandle)
|
|
95
|
-
.sort((a, b) => b.createdAt - a.createdAt)
|
|
96
|
-
.slice(0, 5)
|
|
81
|
+
? attempts.filter((d) => d.quiz === QUIZ_ID && d.authorHandle === me.userHandle).sort((a, b) => b.createdAt - a.createdAt)
|
|
97
82
|
: [];
|
|
83
|
+
const open = mine.find((a) => !a.finishedAt);
|
|
84
|
+
const finished = mine.filter((a) => a.finishedAt).slice(0, 5);
|
|
98
85
|
|
|
99
|
-
|
|
100
|
-
|
|
86
|
+
const [choice, setChoice] = useState("");
|
|
87
|
+
// The answer just checked, kept on screen until Next; the saved row is the record.
|
|
88
|
+
const [shown, setShown] = useState(null);
|
|
89
|
+
// The attempt whose result is on screen once its last answer lands.
|
|
90
|
+
const [doneId, setDoneId] = useState(null);
|
|
91
|
+
// A new attempt's id is made once, so the gate and both puts check one complete record.
|
|
92
|
+
const [newAttemptId, setNewAttemptId] = useState(() => "attempt-" + crypto.randomUUID());
|
|
93
|
+
const [pageAnswers, setPageAnswers] = useState([]);
|
|
101
94
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
95
|
+
// One `answer` document per question, keyed by its attempt: the attempt's answers are a query, and
|
|
96
|
+
// every score, recap and later view (which question trips people up) is computed from them.
|
|
97
|
+
const attemptId = open?._id ?? doneId ?? newAttemptId;
|
|
98
|
+
const { docs: rows } = useLiveQuery("attemptId", { key: attemptId });
|
|
99
|
+
const saved = rows.filter((d) => d.type === "answer").sort((a, b) => a.step - b.step);
|
|
100
|
+
|
|
101
|
+
// The answer this Check would save, complete, so the verdict is on the exact record the put writes.
|
|
102
|
+
const nextStep = shown ? shown.step : saved.length;
|
|
103
|
+
const candidate = {
|
|
104
|
+
_id: `${attemptId}:${nextStep}`,
|
|
105
|
+
type: "answer",
|
|
106
|
+
attemptId,
|
|
107
|
+
quiz: QUIZ_ID,
|
|
108
|
+
step: nextStep,
|
|
109
|
+
choice,
|
|
110
|
+
right: choice === QUESTIONS[nextStep]?.answer,
|
|
111
|
+
authorHandle: me?.userHandle,
|
|
112
|
+
};
|
|
113
|
+
// A signed-in person keeps each answer as it is made, when `can` says so. A visitor plays in the page.
|
|
114
|
+
const canKeep = can.create(candidate);
|
|
115
|
+
const keeping = Boolean(me) && !canKeep.pending && canKeep.ok;
|
|
116
|
+
const answers = keeping ? saved : pageAnswers;
|
|
117
|
+
|
|
118
|
+
const step = shown ? shown.step : answers.length;
|
|
119
|
+
const done = !shown && answers.length === TOTAL;
|
|
120
|
+
const question = QUESTIONS[step];
|
|
121
|
+
const score = answers.filter((a) => a.right).length;
|
|
122
|
+
// Next waits until the checked answer is a row (and, on the last question, until the attempt is
|
|
123
|
+
// finished), so the next question is read from the saved answers rather than racing them.
|
|
124
|
+
const landed = !shown || !keeping || (shown.step === TOTAL - 1 ? doneId !== null : saved.length > shown.step);
|
|
106
125
|
|
|
107
|
-
function
|
|
108
|
-
|
|
126
|
+
async function check() {
|
|
127
|
+
const entry = { step, choice, right: choice === question.answer };
|
|
128
|
+
setShown(entry);
|
|
109
129
|
setChoice("");
|
|
110
|
-
|
|
130
|
+
if (!keeping) return setPageAnswers((a) => [...a, entry]);
|
|
131
|
+
// The attempt is written with its first answer, so the person's place exists from step one.
|
|
132
|
+
const attempt = open ?? { _id: attemptId, type: "attempt", quiz: QUIZ_ID, authorHandle: me.userHandle, createdAt: Date.now() };
|
|
133
|
+
if (!open) await database.put(attempt);
|
|
134
|
+
// A deterministic id per question: checking the same question twice rewrites one row, never two.
|
|
135
|
+
await database.put({ ...candidate, ...entry, answeredAt: Date.now() });
|
|
136
|
+
if (step === TOTAL - 1) {
|
|
137
|
+
// The score stored on the attempt is a snapshot beside the answers, for lists that read attempts alone.
|
|
138
|
+
const correct = score + (entry.right ? 1 : 0);
|
|
139
|
+
await database.put({ ...attempt, correct, total: TOTAL, finishedAt: Date.now() });
|
|
140
|
+
setDoneId(attempt._id);
|
|
141
|
+
}
|
|
111
142
|
}
|
|
112
143
|
|
|
113
144
|
function playAgain() {
|
|
114
|
-
setStep(0);
|
|
115
145
|
setChoice("");
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
async function saveScore() {
|
|
122
|
-
setSaving(true);
|
|
123
|
-
try {
|
|
124
|
-
await database.put({ type: "attempt", quiz: QUIZ_ID, correct: score, total: TOTAL, authorHandle: me?.userHandle, createdAt: Date.now() });
|
|
125
|
-
// Marks this exact attempt as saved, so the button can't post it twice.
|
|
126
|
-
setSavedResults(results);
|
|
127
|
-
} finally {
|
|
128
|
-
setSaving(false);
|
|
129
|
-
}
|
|
146
|
+
setShown(null);
|
|
147
|
+
setDoneId(null);
|
|
148
|
+
setNewAttemptId("attempt-" + crypto.randomUUID());
|
|
149
|
+
setPageAnswers([]);
|
|
130
150
|
}
|
|
131
151
|
|
|
132
152
|
let ending;
|
|
133
|
-
if (
|
|
134
|
-
else if (
|
|
153
|
+
if (keeping) ending = <Text muted>Kept. It is in your attempts below.</Text>;
|
|
154
|
+
else if (canKeep.pending)
|
|
135
155
|
ending = (
|
|
136
156
|
<div aria-busy="true">
|
|
137
157
|
<Skeleton variant="row" />
|
|
@@ -141,18 +161,12 @@ export default function App() {
|
|
|
141
161
|
ending = (
|
|
142
162
|
<Stack gap={2}>
|
|
143
163
|
<Text size="sm" muted>
|
|
144
|
-
Sign in
|
|
164
|
+
Sign in and every answer is kept as you go, so you can pick up where you left off.
|
|
145
165
|
</Text>
|
|
146
|
-
<Button onClick={requestLogin}>Sign in to
|
|
166
|
+
<Button onClick={requestLogin}>Sign in to keep your answers</Button>
|
|
147
167
|
</Stack>
|
|
148
168
|
);
|
|
149
|
-
else
|
|
150
|
-
else
|
|
151
|
-
ending = (
|
|
152
|
-
<Button loading={saving} onClick={saveScore}>
|
|
153
|
-
Save score
|
|
154
|
-
</Button>
|
|
155
|
-
);
|
|
169
|
+
else ending = <Text muted>Scores aren't being kept right now. Play on for practice.</Text>;
|
|
156
170
|
|
|
157
171
|
const passed = score >= PASS;
|
|
158
172
|
|
|
@@ -171,7 +185,7 @@ export default function App() {
|
|
|
171
185
|
<Eyebrow>{done ? "Finished" : `Question ${step + 1} of ${TOTAL}`}</Eyebrow>
|
|
172
186
|
{!done && <Badge tone="info">{score} correct</Badge>}
|
|
173
187
|
</Row>
|
|
174
|
-
<Progress value={
|
|
188
|
+
<Progress value={answers.length} max={TOTAL} tone="info" label="Quiz progress" />
|
|
175
189
|
</Stack>
|
|
176
190
|
|
|
177
191
|
{done ? (
|
|
@@ -188,7 +202,7 @@ export default function App() {
|
|
|
188
202
|
<Stack gap={2}>
|
|
189
203
|
{QUESTIONS.map((item, i) => (
|
|
190
204
|
<Row key={item.q} gap={2} wrap={false}>
|
|
191
|
-
<Badge tone={
|
|
205
|
+
<Badge tone={answers[i]?.right ? "up" : "down"}>{answers[i]?.right ? "Right" : "Missed"}</Badge>
|
|
192
206
|
<Text size="sm" muted truncate>
|
|
193
207
|
{item.q}
|
|
194
208
|
</Text>
|
|
@@ -205,18 +219,20 @@ export default function App() {
|
|
|
205
219
|
) : (
|
|
206
220
|
<Stack gap={4}>
|
|
207
221
|
<Heading level={2}>{question.q}</Heading>
|
|
208
|
-
<RadioGroup label="Your answer" value={choice} onChange={setChoice} options={question.options} disabled={
|
|
209
|
-
{
|
|
222
|
+
<RadioGroup label="Your answer" value={shown ? shown.choice : choice} onChange={setChoice} options={question.options} disabled={Boolean(shown)} />
|
|
223
|
+
{shown && (
|
|
210
224
|
<Row gap={2} wrap={false}>
|
|
211
|
-
<Badge tone={
|
|
212
|
-
{!
|
|
225
|
+
<Badge tone={shown.right ? "up" : "down"}>{shown.right ? "Correct" : "Not quite"}</Badge>
|
|
226
|
+
{!shown.right && <Text muted>The answer is “{answerLabel(question)}”.</Text>}
|
|
213
227
|
</Row>
|
|
214
228
|
)}
|
|
215
229
|
<Row justify="end">
|
|
216
|
-
{
|
|
217
|
-
<Button onClick={
|
|
230
|
+
{shown ? (
|
|
231
|
+
<Button disabled={!landed} onClick={() => setShown(null)}>
|
|
232
|
+
Next question
|
|
233
|
+
</Button>
|
|
218
234
|
) : (
|
|
219
|
-
<Button disabled={!choice} onClick={check}>
|
|
235
|
+
<Button disabled={!choice || (Boolean(me) && canKeep.pending)} onClick={check}>
|
|
220
236
|
Check answer
|
|
221
237
|
</Button>
|
|
222
238
|
)}
|
|
@@ -226,11 +242,11 @@ export default function App() {
|
|
|
226
242
|
</Stack>
|
|
227
243
|
</Card>
|
|
228
244
|
|
|
229
|
-
{
|
|
245
|
+
{finished.length > 0 && (
|
|
230
246
|
<Stack gap={3}>
|
|
231
247
|
<Heading level={2}>Your attempts</Heading>
|
|
232
248
|
<Stack gap={2}>
|
|
233
|
-
{
|
|
249
|
+
{finished.map((a) => (
|
|
234
250
|
<RowCard key={a._id}>
|
|
235
251
|
<Row justify="between" wrap={false}>
|
|
236
252
|
<Text>
|
|
@@ -238,7 +254,7 @@ export default function App() {
|
|
|
238
254
|
</Text>
|
|
239
255
|
<Row gap={2} wrap={false}>
|
|
240
256
|
<Text size="sm" muted>
|
|
241
|
-
{when(a.
|
|
257
|
+
{when(a.finishedAt)}
|
|
242
258
|
</Text>
|
|
243
259
|
<Badge tone={a.correct === a.total ? "up" : a.correct >= PASS ? "info" : "warn"}>
|
|
244
260
|
{a.correct === a.total ? "Perfect" : a.correct >= PASS ? "Passed" : "Practise"}
|
|
@@ -258,8 +274,9 @@ export default function App() {
|
|
|
258
274
|
|
|
259
275
|
## Adapting
|
|
260
276
|
|
|
261
|
-
- Change the questions, not the flow: each one is `{ q, options: [{ value, label }], answer }
|
|
262
|
-
- Keep
|
|
277
|
+
- Change the questions, not the flow: each one is `{ q, options: [{ value, label }], answer }`; the attempt document is written with the first answer, each answer is its own `answer` document with `attemptId`, `step`, the `choice` and whether it was `right`, and the attempt gains `finishedAt` and a score snapshot with the last one.
|
|
278
|
+
- Keep the person's own picks, not only the result: a personality quiz saves each answer's `choice` (and the trait it scores) and computes the type from the answers, so a reload resumes, a retake can be compared answer by answer, and a later view can show which questions moved the result.
|
|
279
|
+
- Keep one attempt document per run and compute everything else (best score, average, a class board) from them at read time; a single "best score" document that each attempt rewrites loses scores when two people finish at once.
|
|
263
280
|
- Store what a later view might group or sort by on the attempt (`quiz` for which quiz, `correct`, `total`, a `level`), and give each quiz its own `QUIZ_ID` so several quizzes can share one database.
|
|
264
281
|
- A board of everyone's scores names each player with `useViewer()`'s `ViewerTag` from the stored `authorHandle`. Scores people would rather keep to themselves (a staff assessment, a medical exam drill) need an access function that limits who can read them before they are shown to anyone else.
|
|
265
282
|
- A new write surface gets its own verdict: `can.create(draft)` with the fields the write stamps, `can.edit(doc)` or `can.delete(doc)` on the document it changes, always on `useVibe` of the database it writes.
|
package/llms/ui-storefront.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Storefront
|
|
2
2
|
|
|
3
|
-
A small shop: product cards to browse, a category filter and a search, a bag that adds things up, and a checkout that places the order. It fits a potter's ceramics, a bakery's preorders, a club's merch table or a school fair's stall. Reach for it whenever the app's core is a short catalogue that people pick from and then order. The catalogue is the owner's: each thing for sale is a `product` record the owner adds on the app's own Products screen, with its name, price, a short line, a category and a photo, so changing what the shop sells is an edit in the app, never a rebuild.
|
|
3
|
+
A small shop: product cards to browse, a category filter and a search, a bag that adds things up, and a checkout that places the order. It fits a potter's ceramics, a bakery's preorders, a club's merch table or a school fair's stall. Reach for it whenever the app's core is a short catalogue that people pick from and then order. The catalogue is the owner's: each thing for sale is a `product` record the owner adds on the app's own Products screen, with its name, price, a short line, a category and a photo, so changing what the shop sells is an edit in the app, never a rebuild. A signed-in buyer's bag is saved as they shop: an open order and one line document per product, keyed by the order's id, so the bag is there after a reload or on another device, and placing it moves that same order to received. The shop can see what to make, line by line, and the buyer can see what they ordered. It records orders; taking card payment is the `stripe` skill, which reads these same product records.
|
|
4
4
|
|
|
5
5
|
Built from @vibes.diy/ui components; persisted state lives in Fireproof. Every write surface is gated on `useVibe(dbName).can`.
|
|
6
6
|
|
|
@@ -10,7 +10,7 @@ Two screens, one job each. The **Shop** fills the bag and places the order: a `N
|
|
|
10
10
|
|
|
11
11
|
The **Products** screen is the owner's, behind `can.create` on a product draft: a form for the name, price, short line, category and photo, then one row per product whose price edits in place and whose `On sale` checkbox puts it in front of buyers or takes it away. The catalogue starts empty, and an owner who opens an empty shop lands on this screen with "Add the first thing you sell"; a visitor sees a warm `Empty` until the first product goes on sale. Every price is a whole number in the currency's smallest unit (cents for usd, whole yen for jpy) beside its `currency`, the unit card payments charge in, and the page shows, edits and adds prices through that unit.
|
|
12
12
|
|
|
13
|
-
An order is
|
|
13
|
+
An order is a document with its lines beside it: each `line` carries the `orderId`, the product, the quantity and, once placed, the title and unit price it was bought at, and the order holds the totals, the currency and the buyer's handle, so a later price change never rewrites an order already placed and every line can be read, counted and fixed on its own; the person's own orders list under the bag, each with a `Badge` for its status (`info` received, `warn` ready to collect, `up` collected). Checkout waits on its `can` verdict from `useVibe("orders")`: a `Skeleton` inside an `aria-busy` wrapper while it resolves, a sentence in the app's own words when ordering is closed, and for a visitor who has not signed in a `Sign in to place your order` lead wired to `useViewer().requestLogin()`, with the bag they filled kept in place. Sign-in is required here, unlike a local-first note, because a signed-out write stays on the device until sign-in: an order placed that way would never reach the shop. That sign-in lead belongs to the pay-when-you-collect order alone: a shop that takes card payment with the `stripe` skill shows Pay to every visitor, signed in or not, because Stripe's own page takes the buyer's email and sends the receipt, and it asks for sign-in only when the owner asked for it.
|
|
14
14
|
|
|
15
15
|
### `App.jsx`
|
|
16
16
|
```jsx
|
|
@@ -213,9 +213,29 @@ export default function App() {
|
|
|
213
213
|
|
|
214
214
|
const [category, setCategory] = useState("all");
|
|
215
215
|
const [query, setQuery] = useState("");
|
|
216
|
-
//
|
|
217
|
-
|
|
216
|
+
// A signed-in buyer's bag is their order in the making: an `order` with status "open" and one
|
|
217
|
+
// `line` document per product, keyed by its orderId. Every Add writes its line at once, so the bag
|
|
218
|
+
// is there after a reload and on their phone, and placing the order moves the same id along.
|
|
219
|
+
const mine = me ? orders.filter((o) => o.authorHandle === me.userHandle).sort((a, b) => b.createdAt - a.createdAt) : [];
|
|
220
|
+
const open = mine.find((o) => o.status === "open");
|
|
221
|
+
const placed = mine.filter((o) => o.status !== "open");
|
|
222
|
+
const { docs: lineDocs } = useLiveQuery("orderId", { key: open?._id ?? "" });
|
|
223
|
+
// The verdict for the order this bag becomes, carrying the fields change() stamps on it.
|
|
224
|
+
const orderDraft = { type: "order", status: "open", authorHandle: me?.userHandle };
|
|
225
|
+
const canOrder = can.create(orderDraft);
|
|
226
|
+
// A line write and the move to received are their own decisions, each checked on the record it writes.
|
|
227
|
+
// The line verdict reads one representative line; access.js holds every line to its buyer the same way.
|
|
228
|
+
const canLine = can.create({ type: "line", orderId: open?._id ?? "order-new", productId: "", qty: 1, authorHandle: me?.userHandle });
|
|
229
|
+
const canPlace = open ? can.edit({ ...open, status: "received" }) : canOrder;
|
|
230
|
+
const keeping = Boolean(me) && !canOrder.pending && canOrder.ok && canLine.ok;
|
|
231
|
+
// A visitor's bag stays in the page until they sign in; then their saved lines join it.
|
|
232
|
+
const [pageBag, setPageBag] = useState({});
|
|
233
|
+
const savedBag = Object.fromEntries(lineDocs.filter((l) => l.type === "line").map((l) => [l.productId, l.qty]));
|
|
234
|
+
const bag = keeping ? { ...pageBag, ...savedBag } : pageBag;
|
|
218
235
|
const [placing, setPlacing] = useState(false);
|
|
236
|
+
// The id of an order this page has started but the live query has not returned yet, so two
|
|
237
|
+
// quick Adds land on one order instead of opening two.
|
|
238
|
+
const startedOrder = useRef(null);
|
|
219
239
|
|
|
220
240
|
// One currency per bag: the shop sells in CURRENCY, so a record priced in another stays off the shelf.
|
|
221
241
|
const forSale = products.filter((p) => p.onSale && p.currency === CURRENCY).sort((a, b) => a.createdAt - b.createdAt);
|
|
@@ -230,26 +250,39 @@ export default function App() {
|
|
|
230
250
|
const count = lines.reduce((n, l) => n + l.qty, 0);
|
|
231
251
|
const subtotal = lines.reduce((n, l) => n + l.unitAmount * l.qty, 0);
|
|
232
252
|
const shipping = subtotal === 0 || subtotal >= FREE_SHIPPING ? 0 : SHIPPING;
|
|
233
|
-
const mine = me ? orders.filter((o) => o.authorHandle === me.userHandle).sort((a, b) => b.createdAt - a.createdAt) : [];
|
|
234
253
|
|
|
235
|
-
//
|
|
236
|
-
|
|
237
|
-
const
|
|
254
|
+
// One line per product, its id derived from the order and the product, so the same product
|
|
255
|
+
// twice is one line with a new quantity; a line at zero stays as a row and drops out of the bag.
|
|
256
|
+
const lineFor = (orderId, productId, qty) => ({ _id: `${orderId}:${productId}`, type: "line", orderId, productId, qty, authorHandle: me.userHandle, updatedAt: Date.now() });
|
|
238
257
|
|
|
239
|
-
function change(id, delta) {
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
const { [id]: _gone, ...rest } =
|
|
243
|
-
return qty === 0 ? rest : { ...rest, [id]: qty };
|
|
244
|
-
}
|
|
258
|
+
async function change(id, delta) {
|
|
259
|
+
const qty = Math.min(MAX_QTY, Math.max(0, (bag[id] ?? 0) + delta));
|
|
260
|
+
if (!keeping) {
|
|
261
|
+
const { [id]: _gone, ...rest } = pageBag;
|
|
262
|
+
return setPageBag(qty === 0 ? rest : { ...rest, [id]: qty });
|
|
263
|
+
}
|
|
264
|
+
// The order is written with its first line, so the bag exists from the first Add.
|
|
265
|
+
const orderId = open?._id ?? startedOrder.current;
|
|
266
|
+
if (orderId) return database.put(lineFor(orderId, id, qty));
|
|
267
|
+
const fresh = "order-" + crypto.randomUUID();
|
|
268
|
+
startedOrder.current = fresh;
|
|
269
|
+
await database.put({ _id: fresh, ...orderDraft, currency: CURRENCY, createdAt: Date.now() });
|
|
270
|
+
await database.put(lineFor(fresh, id, qty));
|
|
245
271
|
}
|
|
246
272
|
|
|
247
273
|
async function placeOrder() {
|
|
248
274
|
setPlacing(true);
|
|
249
275
|
try {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
276
|
+
const orderId = open?._id ?? startedOrder.current ?? "order-" + crypto.randomUUID();
|
|
277
|
+
const order = open ?? { _id: orderId, ...orderDraft, currency: CURRENCY, createdAt: Date.now() };
|
|
278
|
+
// Each line keeps the title and unit price it was bought at, so a later price change never
|
|
279
|
+
// rewrites a placed order; the order keeps a snapshot of the totals beside its lines.
|
|
280
|
+
for (const l of lines) await database.put({ ...lineFor(orderId, l.productId, l.qty), title: l.title, unitAmount: l.unitAmount });
|
|
281
|
+
// A saved line whose product went off sale is not in this order: it goes to zero with it.
|
|
282
|
+
for (const l of lineDocs) if (l.type === "line" && l.qty > 0 && !lines.some((x) => x.productId === l.productId)) await database.put({ ...l, qty: 0, updatedAt: Date.now() });
|
|
283
|
+
await database.put({ ...order, status: "received", subtotal, shipping, total: subtotal + shipping, itemCount: count, placedAt: Date.now() });
|
|
284
|
+
setPageBag({});
|
|
285
|
+
startedOrder.current = null;
|
|
253
286
|
toast.success("Order placed. We'll be in touch about collection.");
|
|
254
287
|
} finally {
|
|
255
288
|
setPlacing(false);
|
|
@@ -257,7 +290,7 @@ export default function App() {
|
|
|
257
290
|
}
|
|
258
291
|
|
|
259
292
|
let checkout;
|
|
260
|
-
if (
|
|
293
|
+
if (canPlace.pending)
|
|
261
294
|
checkout = (
|
|
262
295
|
<div aria-busy="true">
|
|
263
296
|
<Skeleton variant="row" />
|
|
@@ -269,7 +302,7 @@ export default function App() {
|
|
|
269
302
|
Sign in to place your order
|
|
270
303
|
</Button>
|
|
271
304
|
);
|
|
272
|
-
else if (!
|
|
305
|
+
else if (!canPlace.ok) checkout = <Text muted>The shop isn't taking orders right now. Check back soon.</Text>;
|
|
273
306
|
else
|
|
274
307
|
checkout = (
|
|
275
308
|
<Button block disabled={count === 0} loading={placing} onClick={placeOrder}>
|
|
@@ -429,16 +462,16 @@ export default function App() {
|
|
|
429
462
|
</Stack>
|
|
430
463
|
</Card>
|
|
431
464
|
|
|
432
|
-
{
|
|
465
|
+
{placed.length > 0 && (
|
|
433
466
|
<Card variant="tight">
|
|
434
467
|
<Stack gap={3}>
|
|
435
468
|
<Heading level={3}>Your orders</Heading>
|
|
436
|
-
{
|
|
469
|
+
{placed.map((o) => (
|
|
437
470
|
<Row key={o._id} justify="between" wrap={false}>
|
|
438
471
|
<Stack gap={1}>
|
|
439
472
|
<Text num>{money(o.total, o.currency ?? CURRENCY)}</Text>
|
|
440
473
|
<Text size="sm" muted>
|
|
441
|
-
{new Date(o.createdAt).toLocaleDateString()} · {plural(o.
|
|
474
|
+
{new Date(o.placedAt ?? o.createdAt).toLocaleDateString()} · {plural(o.itemCount ?? 0, "item", "items")}
|
|
442
475
|
</Text>
|
|
443
476
|
</Stack>
|
|
444
477
|
<Badge tone={ORDER_STATUS[o.status]?.tone ?? "info"}>{ORDER_STATUS[o.status]?.label ?? "Received"}</Badge>
|
|
@@ -465,8 +498,8 @@ export default function App() {
|
|
|
465
498
|
|
|
466
499
|
- The catalogue is records, so a shop with three things and a shop with forty are the same code. It ships empty: example products for a first look go in the app's seed data, which the owner clears, and the owner adds the real ones on **Products**. Swap `CATEGORIES`, `BADGES`, the shipping rule and `CURRENCY` for the shop's own.
|
|
467
500
|
- Product records belong to the owner: `access.js` takes a `product` only from the owner (`ctx.requireRole("owner")`), with an `amount` that is a positive whole number, a three-letter lowercase `currency` and an `onSale` true or false, and puts it on a channel every visitor reads. Keep the `orders` database and the field names `title`, `amount`, `currency` and `onSale`: they are the `stripe` skill's, so its checkout reads these records and prices this bag unchanged.
|
|
468
|
-
- Keep
|
|
469
|
-
- Orders hold who bought what, so `access.js` and the app's sharing should keep each order between its buyer and the shop: a buyer creates and reads their own, the shop reads them all and moves each through `ORDER_STATUS` behind `can.edit(order)`.
|
|
501
|
+
- Keep each line a snapshot of its title, unit price and quantity once placed, and the order a snapshot of its totals: an order is a record of what was agreed, so a later price change must not touch it. Lines are their own documents keyed by `orderId`, never an array on the order, so the shop can count a product across orders, a buyer's agent can fill the same bag, and one line can change without rewriting the rest.
|
|
502
|
+
- Orders hold who bought what, so `access.js` and the app's sharing should keep each order between its buyer and the shop: a buyer creates and reads their own orders and lines (a `line` routes with the order its `orderId` names), the shop reads them all and moves each through `ORDER_STATUS` behind `can.edit(order)`.
|
|
470
503
|
- Card payment is the `stripe` skill, and it comes in when the person asks to take money: its checkout replaces `Place order` with one `pay(...)` that sends each product and its quantity, `backend.js` prices every line from these records, and the order becomes the one `/checkout` writes. Anyone pays: the `Sign in to place your order` lead goes away with `Place order`, and a guest's bag stays on the page until they pay. Until then, keep the pay-when-you-collect line truthful, and offer `▸ [pay] Take card payments with Stripe` as the capability option.
|
|
471
504
|
- A new write surface gets its own verdict: `can.create(draft)` with the fields the write stamps, `can.edit(doc)` or `can.delete(doc)` on the document it changes, always on `useVibe` of the database it writes.
|
|
472
505
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibes.diy/prompts",
|
|
3
|
-
"version": "14.3.
|
|
3
|
+
"version": "14.3.288",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"exports": {
|
|
@@ -39,10 +39,10 @@
|
|
|
39
39
|
"license": "Apache-2.0",
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@adviser/cement": "~0.5.34",
|
|
42
|
-
"@vibes.diy/api-types": "14.3.
|
|
43
|
-
"@vibes.diy/call-ai-v2": "14.3.
|
|
44
|
-
"@vibes.diy/identity": "14.3.
|
|
45
|
-
"@vibes.diy/use-vibes-types": "14.3.
|
|
42
|
+
"@vibes.diy/api-types": "14.3.288",
|
|
43
|
+
"@vibes.diy/call-ai-v2": "14.3.288",
|
|
44
|
+
"@vibes.diy/identity": "14.3.288",
|
|
45
|
+
"@vibes.diy/use-vibes-types": "14.3.288",
|
|
46
46
|
"arktype": "~2.2.9",
|
|
47
47
|
"json-schema-faker": "~0.6.3"
|
|
48
48
|
},
|