@milesroxas/design-hub 0.6.2 → 0.8.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.
Files changed (56) hide show
  1. package/README.md +16 -6
  2. package/core/review/model.ts +124 -6
  3. package/core/review/policy.test.ts +103 -24
  4. package/core/review/policy.ts +43 -7
  5. package/core/review/service.test.ts +569 -33
  6. package/core/review/service.ts +272 -76
  7. package/core/review/store.ts +24 -4
  8. package/dist/core/review/model.d.ts +59 -4
  9. package/dist/core/review/model.js +98 -4
  10. package/dist/core/review/policy.d.ts +21 -2
  11. package/dist/core/review/policy.js +34 -2
  12. package/dist/core/review/service.d.ts +39 -11
  13. package/dist/core/review/service.js +237 -77
  14. package/dist/core/review/store.d.ts +17 -4
  15. package/dist/core/review/store.js +21 -3
  16. package/dist/scripts/bootstrap.d.ts +16 -14
  17. package/dist/scripts/bootstrap.js +56 -39
  18. package/dist/scripts/comments.d.ts +10 -2
  19. package/dist/scripts/comments.js +18 -7
  20. package/dist/scripts/lib/deploy.d.ts +12 -4
  21. package/dist/scripts/lib/deploy.js +47 -13
  22. package/dist/scripts/lib/vercel.d.ts +8 -2
  23. package/dist/scripts/lib/vercel.js +23 -9
  24. package/dist/scripts/people.d.ts +13 -26
  25. package/dist/scripts/people.js +68 -35
  26. package/dist/scripts/preflight.js +2 -2
  27. package/dist/scripts/share.d.ts +2 -3
  28. package/dist/scripts/share.js +18 -10
  29. package/dist/server/api.d.ts +6 -2
  30. package/dist/server/api.js +65 -24
  31. package/dist/server/fake-upstash.js +3 -2
  32. package/dist/server/local.js +2 -0
  33. package/dist/server/session.d.ts +25 -10
  34. package/dist/server/session.js +69 -52
  35. package/dist/server/upstash.js +4 -3
  36. package/dist/vercel/proxy.d.ts +5 -3
  37. package/dist/vercel/proxy.js +183 -157
  38. package/dist/vite/plugin.js +5 -5
  39. package/kit/prefs.ts +19 -2
  40. package/package.json +2 -2
  41. package/shell/review/Bar.tsx +97 -4
  42. package/shell/review/People.tsx +178 -45
  43. package/shell/review/Pins.tsx +39 -24
  44. package/shell/review/Review.tsx +113 -29
  45. package/shell/review/ThreadCard.tsx +25 -13
  46. package/shell/review/client.ts +64 -23
  47. package/shell/review/review.css +16 -2
  48. package/shell/review/view.test.ts +73 -1
  49. package/shell/review/view.ts +49 -3
  50. package/skills/miles-deploy/SKILL.md +44 -16
  51. package/skills/miles-design-hub/SKILL.md +5 -5
  52. package/skills/miles-new-feature/SKILL.md +1 -1
  53. package/skills/miles-review/SKILL.md +10 -6
  54. package/skills/miles-worktrees/SKILL.md +1 -1
  55. package/templates/conductor/settings.toml +1 -1
  56. package/templates/guide.md +1 -1
@@ -3,12 +3,14 @@
3
3
  // thread in a card beside it. Off, the page carries only the button. It is
4
4
  // harness, not product: it wears the harness material and never borrows the
5
5
  // prototype's chrome. One file per part; this one holds the state and wires them.
6
+ // What a person sees is what the server sent them: Client view asks the server
7
+ // for a Client's list, and the audience filter only narrows Studio's own.
6
8
  import { useStoredState } from '@kit/hooks';
7
- import { areCommentsHidden, setCommentsHidden } from '@kit/prefs';
9
+ import { areCommentsHidden, isClientView, setClientView, setCommentsHidden } from '@kit/prefs';
8
10
  import { Button } from '@kit/ui';
9
11
  import { type Dispatch, useEffect, useMemo, useReducer, useState } from 'react';
10
- import { type Anchor, type Comment, isRoot } from '../../core/review/model';
11
- import { can } from '../../core/review/policy';
12
+ import { type Anchor, type Audience, type Comment, isRoot } from '../../core/review/model';
13
+ import { can, viewOf } from '../../core/review/policy';
12
14
  import { captureAnchor, currentUrl, openAnchor, pinPoint, resumeAnchor } from './anchor';
13
15
  import { Bar } from './Bar';
14
16
  import { Card } from './Card';
@@ -23,7 +25,10 @@ import { ThreadCard } from './ThreadCard';
23
25
  import {
24
26
  type Draft,
25
27
  draftOf,
28
+ filtered,
29
+ filterNote,
26
30
  initialView,
31
+ lensOf,
27
32
  roundOf,
28
33
  scopeOf,
29
34
  stepTarget,
@@ -37,6 +42,10 @@ import './review.css';
37
42
  type Props = { prototype: string; feature: string; states: string[] };
38
43
  type State = ReturnType<ReviewStore['get']>;
39
44
  type Where = { prototype: string; feature: string };
45
+ type Lens = ReturnType<typeof lensOf>;
46
+
47
+ /** Studio in Client view: the same person, judged by the rules as a Client, so Studio's controls step aside. */
48
+ const asClient = (s: State): State => (s.me ? { ...s, me: { ...s.me, kind: 'client' } } : s);
40
49
 
41
50
  /** The page's path, query and hash, kept current as hash routes change. */
42
51
  function useCurrentUrl(): string {
@@ -80,20 +89,32 @@ function useSpot(): [Spot, (s: Spot) => void] {
80
89
  return [isSpot(stored) ? stored : DEFAULT_SPOT, setStored];
81
90
  }
82
91
 
92
+ /**
93
+ * The view, its remembered parts kept in kit/prefs, and the list loaded for
94
+ * it: Client view asks the server for a Client's list, which for a Client
95
+ * changes nothing.
96
+ */
97
+ function useView(store: ReviewStore): [View, Dispatch<ViewAction>] {
98
+ const [v, dispatch] = useReducer(view, undefined, () => initialView(areCommentsHidden(), isClientView()));
99
+ useEffect(() => {
100
+ resumeAnchor((id) => dispatch({ type: 'open', id }));
101
+ }, []);
102
+ useEffect(() => {
103
+ void store.load(v.clientView ? 'client' : undefined);
104
+ }, [store, v.clientView]);
105
+ useEffect(() => setCommentsHidden(v.hidden), [v.hidden]);
106
+ useEffect(() => setClientView(v.clientView), [v.clientView]);
107
+ useEscape(v.commenting, dispatch);
108
+ return [v, dispatch];
109
+ }
110
+
83
111
  export function Review({ prototype, feature, states }: Props) {
84
112
  const store = useMemo(() => createReviewStore(prototype), [prototype]);
85
113
  const s = useReviewState(store);
86
- const [v, dispatch] = useReducer(view, undefined, () => initialView(areCommentsHidden()));
114
+ const [v, dispatch] = useView(store);
87
115
  const [spot, setSpot] = useSpot();
88
116
  const url = useCurrentUrl();
89
117
 
90
- useEffect(() => {
91
- void store.load();
92
- resumeAnchor((id) => dispatch({ type: 'open', id }));
93
- }, [store]);
94
- useEffect(() => setCommentsHidden(v.hidden), [v.hidden]);
95
- useEscape(v.commenting, dispatch);
96
-
97
118
  const shown = s.status === 'ready' || s.status === 'guest';
98
119
  useToastLift(shown && !v.hidden && spot === 'bottom-right');
99
120
  if (!shown) return null;
@@ -119,6 +140,7 @@ export function Review({ prototype, feature, states }: Props) {
119
140
  <Launcher
120
141
  hidden={v.hidden}
121
142
  commenting={v.commenting}
143
+ // Every open thread the person was sent, never the filtered list: a narrowed filter cannot hide one.
122
144
  openCount={roots.filter((c) => c.status === 'open').length}
123
145
  spot={spot}
124
146
  onSpot={setSpot}
@@ -129,16 +151,16 @@ export function Review({ prototype, feature, states }: Props) {
129
151
  );
130
152
  }
131
153
 
132
- /** With no person behind the session, comment mode is this card and nothing else. */
154
+ /**
155
+ * The session ended after the page loaded (a revoke, a sign out everywhere,
156
+ * or the end of their access): comment mode is this card and nothing else.
157
+ */
133
158
  function GuestCard({ onClose }: { onClose: () => void }) {
134
159
  return (
135
160
  <Card at={null} label="Comments" onDismiss={onClose}>
136
161
  <div className="rv-note">
137
- <strong>Comments need an invite</strong>
138
- <p>
139
- You are viewing with the shared password. Ask the team for an invite link to read and leave
140
- comments.
141
- </p>
162
+ <strong>You are signed out</strong>
163
+ <p>Ask the studio for a new link to read and leave comments.</p>
142
164
  </div>
143
165
  </Card>
144
166
  );
@@ -156,11 +178,13 @@ type ModeProps = {
156
178
  };
157
179
 
158
180
  /** Everything comment mode puts on the page: the surface, the pins, the bar and the one card. */
159
- function Commenting({ store, s, v, dispatch, url, where, states, roots }: ModeProps) {
160
- const number = new Map(roots.map((c, i) => [c.id, i + 1]));
181
+ function Commenting({ store, s: real, v, dispatch, url, where, states, roots }: ModeProps) {
182
+ const lens = lensOf(viewOf(real.me) === 'studio', v);
183
+ const s = lens.clientView ? asClient(real) : real;
161
184
  const currentId = threadOf(v.card);
162
185
  const current = roots.find((c) => c.id === currentId);
163
- const round = roundOf(roots, v.resolved, currentId);
186
+ const shown = filtered(roots, v);
187
+ const round = roundOf(shown, v.resolved, currentId);
164
188
  const draft = draftOf(v.card);
165
189
  const open = (id: string) => dispatch({ type: 'open', id });
166
190
  // Opening a thread from the arrows brings its element into view; its card follows the pin.
@@ -177,7 +201,6 @@ function Commenting({ store, s, v, dispatch, url, where, states, roots }: ModePr
177
201
  <PickLayer onPick={(d) => dispatch({ type: 'draft', draft: d })} onOpen={open} />
178
202
  <Pins
179
203
  comments={round.filter((c) => c.anchor?.url === url)}
180
- number={number}
181
204
  active={currentId}
182
205
  draft={draft}
183
206
  onOpen={open}
@@ -185,10 +208,11 @@ function Commenting({ store, s, v, dispatch, url, where, states, roots }: ModePr
185
208
  <ModeBar
186
209
  store={store}
187
210
  s={s}
211
+ lens={lens}
188
212
  v={v}
189
213
  dispatch={dispatch}
190
214
  round={round}
191
- roots={roots}
215
+ roots={shown}
192
216
  index={current ? round.indexOf(current) : -1}
193
217
  onStep={step}
194
218
  />
@@ -199,7 +223,7 @@ function Commenting({ store, s, v, dispatch, url, where, states, roots }: ModePr
199
223
  s={s}
200
224
  root={current}
201
225
  round={round}
202
- number={number}
226
+ mark={lens.asStudio}
203
227
  url={url}
204
228
  states={states}
205
229
  open={open}
@@ -207,7 +231,16 @@ function Commenting({ store, s, v, dispatch, url, where, states, roots }: ModePr
207
231
  onClose={() => dispatch({ type: 'close' })}
208
232
  />
209
233
  )}
210
- {draft && <DraftCard store={store} draft={draft} where={where} states={states} dispatch={dispatch} />}
234
+ {draft && (
235
+ <DraftCard
236
+ store={store}
237
+ draft={draft}
238
+ where={where}
239
+ states={states}
240
+ audience={draftAudience(lens)}
241
+ dispatch={dispatch}
242
+ />
243
+ )}
211
244
  {v.card?.type === 'people' && (
212
245
  <PeopleCard store={store} s={s} onClose={() => dispatch({ type: 'close' })} />
213
246
  )}
@@ -230,7 +263,7 @@ function PeopleCard({ store, s, onClose }: { store: ReviewStore; s: State; onClo
230
263
  onClick={onClose}
231
264
  />
232
265
  </header>
233
- <People store={store} me={s.me} people={s.people} />
266
+ <People store={store} me={s.me} people={s.people} access={s.access} />
234
267
  </Card>
235
268
  );
236
269
  }
@@ -239,6 +272,7 @@ function PeopleCard({ store, s, onClose }: { store: ReviewStore; s: State; onClo
239
272
  function ModeBar({
240
273
  store,
241
274
  s,
275
+ lens,
242
276
  v,
243
277
  dispatch,
244
278
  round,
@@ -246,6 +280,7 @@ function ModeBar({
246
280
  index,
247
281
  onStep,
248
282
  }: Pick<ModeProps, 'store' | 's' | 'v' | 'dispatch' | 'roots'> & {
283
+ lens: Lens;
249
284
  round: Comment[];
250
285
  index: number;
251
286
  onStep: (by: number) => void;
@@ -266,6 +301,13 @@ function ModeBar({
266
301
  resolved={v.resolved}
267
302
  resolvedCount={roots.filter((c) => c.status === 'resolved').length}
268
303
  canManagePeople={can(s.me, 'people')}
304
+ canFilter={lens.asStudio}
305
+ filter={v.filter}
306
+ filterNote={filterNote(v)}
307
+ onFilter={(filter) => dispatch({ type: 'filter', filter })}
308
+ canClientView={lens.asStudio || lens.clientView}
309
+ clientView={lens.clientView}
310
+ onClientView={(on) => dispatch({ type: 'clientView', on })}
269
311
  error={s.error}
270
312
  onResolved={() => dispatch({ type: 'resolved' })}
271
313
  onPeople={() => {
@@ -285,7 +327,7 @@ function OpenThread({
285
327
  s,
286
328
  root,
287
329
  round,
288
- number,
330
+ mark,
289
331
  url,
290
332
  states,
291
333
  open,
@@ -296,7 +338,7 @@ function OpenThread({
296
338
  s: State;
297
339
  root: Comment;
298
340
  round: Comment[];
299
- number: Map<string, number>;
341
+ mark: boolean;
300
342
  url: string;
301
343
  states: string[];
302
344
  open: (id: string) => void;
@@ -311,7 +353,7 @@ function OpenThread({
311
353
  me={s.me}
312
354
  root={root}
313
355
  replies={s.comments.filter((c) => c.thread === root.id && c.id !== root.id)}
314
- n={number.get(root.id) ?? 0}
356
+ mark={mark}
315
357
  index={round.indexOf(root)}
316
358
  total={round.length}
317
359
  states={states}
@@ -324,19 +366,59 @@ function OpenThread({
324
366
  );
325
367
  }
326
368
 
369
+ /**
370
+ * Who a new thread is for. Studio chooses, internal first. In Client view it
371
+ * is client-facing, as a Client's would be. A Client sends none: the server
372
+ * makes theirs client-facing.
373
+ */
374
+ type DraftAudience = 'choose' | 'client' | null;
375
+ const draftAudience = (lens: Lens): DraftAudience => {
376
+ if (lens.asStudio) return 'choose';
377
+ return lens.clientView ? 'client' : null;
378
+ };
379
+
380
+ const AUDIENCES: { value: Audience; label: string; title: string }[] = [
381
+ { value: 'internal', label: 'Internal', title: 'Only Studio sees it' },
382
+ { value: 'client', label: 'Client-facing', title: 'Everyone sees it, the client included' },
383
+ ];
384
+
385
+ /** Studio's choice on a new thread. Fixed once posted: to tell the client later, write a new one. */
386
+ function AudienceChoice({ value, onChange }: { value: Audience; onChange: (a: Audience) => void }) {
387
+ return (
388
+ // biome-ignore lint/a11y/useSemanticElements: a fieldset brings a border and a legend the card does not want
389
+ <div className="rv-toggle rv-audience" role="group" aria-label="Who sees it">
390
+ {AUDIENCES.map((a) => (
391
+ <button
392
+ key={a.value}
393
+ type="button"
394
+ aria-pressed={value === a.value}
395
+ title={a.title}
396
+ onClick={() => onChange(a.value)}
397
+ >
398
+ {a.label}
399
+ </button>
400
+ ))}
401
+ </div>
402
+ );
403
+ }
404
+
327
405
  function DraftCard({
328
406
  store,
329
407
  draft,
330
408
  where,
331
409
  states,
410
+ audience,
332
411
  dispatch,
333
412
  }: {
334
413
  store: ReviewStore;
335
414
  draft: Draft;
336
415
  where: Where;
337
416
  states: string[];
417
+ audience: DraftAudience;
338
418
  dispatch: Dispatch<ViewAction>;
339
419
  }) {
420
+ const [chosen, setChosen] = useState<Audience>('internal');
421
+ const sent = audience === 'choose' ? chosen : audience;
340
422
  return (
341
423
  <Card at={draftPoint(draft)} label="New comment" onDismiss={() => dispatch({ type: 'close' })}>
342
424
  <header className="rv-card-head">
@@ -352,6 +434,7 @@ function DraftCard({
352
434
  onClick={() => dispatch({ type: 'close' })}
353
435
  />
354
436
  </header>
437
+ {audience === 'choose' && <AudienceChoice value={chosen} onChange={setChosen} />}
355
438
  <div className="rv-card-foot">
356
439
  <Field
357
440
  label="New comment"
@@ -359,7 +442,8 @@ function DraftCard({
359
442
  send="Post"
360
443
  autoFocus
361
444
  onSend={async (body) => {
362
- const c = await store.add(body, captureAnchor(where, draft.target, draftPoint(draft)), states);
445
+ const anchor = captureAnchor(where, draft.target, draftPoint(draft));
446
+ const c = await store.add(body, anchor, states, sent);
363
447
  dispatch({ type: 'open', id: c.id });
364
448
  }}
365
449
  onCancel={() => dispatch({ type: 'close' })}
@@ -2,11 +2,13 @@
2
2
  // the reply box owns the foot at full width; the thread's one decision,
3
3
  // Resolve, sits in the head beside what the comment is on. Kind and state
4
4
  // show as tags once set and are changed from ⋯. A resolved thread wears a
5
- // check, a band naming who resolved it, and Reopen where Resolve was.
5
+ // check, a band naming who resolved it, and Reopen where Resolve was. Studio
6
+ // also sees who the thread is for, Internal or Client-facing, as a quiet mark
7
+ // in the head; a Client sees no such words.
6
8
  import { Icon } from '@kit/Icon';
7
9
  import { Button, type MenuEntry, useMenu } from '@kit/ui';
8
10
  import { type KeyboardEvent, useEffect, useState } from 'react';
9
- import { type Comment, KINDS, type Kind, LIMITS } from '../../core/review/model';
11
+ import { type Audience, type Comment, KINDS, type Kind, LIMITS } from '../../core/review/model';
10
12
  import { can } from '../../core/review/policy';
11
13
  import { Action, Card } from './Card';
12
14
  import { act, type Me, type ReviewStore } from './client';
@@ -14,6 +16,7 @@ import { Field, useTextBox } from './Field';
14
16
  import { describe } from './PickLayer';
15
17
 
16
18
  const KIND_LABEL: Record<Kind, string> = { bug: 'Bug', taste: 'Taste', copy: 'Copy' };
19
+ const AUDIENCE_LABEL: Record<Audience, string> = { internal: 'Internal', client: 'Client-facing' };
17
20
  const relative = new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' });
18
21
  const STEPS: [Intl.RelativeTimeFormatUnit, number][] = [
19
22
  ['year', 31_536_000],
@@ -158,11 +161,13 @@ function Tags({ tags }: { tags: string[] }) {
158
161
  function Entry({
159
162
  store,
160
163
  me,
164
+ root,
161
165
  comment,
162
166
  tags = [],
163
167
  }: {
164
168
  store: ReviewStore;
165
169
  me: Me | null;
170
+ root: Comment;
166
171
  comment: Comment;
167
172
  tags?: string[];
168
173
  }) {
@@ -173,7 +178,7 @@ function Entry({
173
178
  <div className="rv-msg-main">
174
179
  <EntryHead
175
180
  comment={comment}
176
- canEdit={can(me, 'edit', comment) && !editing}
181
+ canEdit={can(me, 'edit', root, comment) && !editing}
177
182
  onEdit={() => setEditing(true)}
178
183
  />
179
184
  {editing ? (
@@ -379,7 +384,8 @@ function ResolvedBand({ root }: { root: Comment }) {
379
384
  type HeadProps = {
380
385
  store: ReviewStore;
381
386
  root: Comment;
382
- n: number;
387
+ /** Show who the thread is for: Studio only, and not in Client view. */
388
+ mark: boolean;
383
389
  index: number;
384
390
  total: number;
385
391
  states: string[];
@@ -396,7 +402,7 @@ type HeadProps = {
396
402
  function ThreadHead({
397
403
  store,
398
404
  root,
399
- n,
405
+ mark,
400
406
  index,
401
407
  total,
402
408
  states,
@@ -411,9 +417,14 @@ function ThreadHead({
411
417
  return (
412
418
  <header className="rv-card-head">
413
419
  <span className="rv-no" aria-hidden="true">
414
- {root.status === 'resolved' ? <Icon name="check" size={12} /> : n}
420
+ {root.status === 'resolved' ? <Icon name="check" size={12} /> : root.number || null}
415
421
  </span>
416
422
  <span className="rv-about rv-ellipsis">{about(root)}</span>
423
+ {mark && (
424
+ <span className="rv-aud" data-audience={root.audience}>
425
+ {AUDIENCE_LABEL[root.audience]}
426
+ </span>
427
+ )}
417
428
  <Stepper index={index} total={total} onStep={onStep} />
418
429
  {canResolve && <ResolveButton store={store} root={root} />}
419
430
  <ThreadMenu
@@ -442,7 +453,7 @@ export function ThreadCard({
442
453
  me,
443
454
  root,
444
455
  replies,
445
- n,
456
+ mark,
446
457
  index,
447
458
  total,
448
459
  states,
@@ -455,7 +466,7 @@ export function ThreadCard({
455
466
  me: Me | null;
456
467
  root: Comment;
457
468
  replies: Comment[];
458
- n: number;
469
+ mark: boolean;
459
470
  index: number;
460
471
  total: number;
461
472
  states: string[];
@@ -466,22 +477,23 @@ export function ThreadCard({
466
477
  }) {
467
478
  const [confirming, setConfirming] = useState(false);
468
479
  const resolved = root.status === 'resolved';
480
+ const words = [root.number ? `Comment ${root.number}` : 'Comment', mark && AUDIENCE_LABEL[root.audience]];
469
481
  return (
470
482
  <Card
471
483
  at={at}
472
- label={`Comment ${n}${resolved ? ', resolved' : ''}`}
484
+ label={[...words, resolved && 'resolved'].filter(Boolean).join(', ')}
473
485
  resolved={resolved}
474
486
  onDismiss={onClose}
475
487
  >
476
488
  <ThreadHead
477
489
  store={store}
478
490
  root={root}
479
- n={n}
491
+ mark={mark}
480
492
  index={index}
481
493
  total={total}
482
494
  states={states}
483
495
  canResolve={can(me, 'resolve', root)}
484
- canTriage={can(me, 'triage')}
496
+ canTriage={can(me, 'triage', root)}
485
497
  canDelete={can(me, 'delete', root)}
486
498
  onStep={onStep}
487
499
  onClose={onClose}
@@ -490,9 +502,9 @@ export function ThreadCard({
490
502
  />
491
503
  <ResolvedBand root={root} />
492
504
  <div className="rv-card-body">
493
- <Entry store={store} me={me} comment={root} tags={tagsOf(root)} />
505
+ <Entry store={store} me={me} root={root} comment={root} tags={tagsOf(root)} />
494
506
  {replies.map((r) => (
495
- <Entry key={r.id} store={store} me={me} comment={r} />
507
+ <Entry key={r.id} store={store} me={me} root={root} comment={r} />
496
508
  ))}
497
509
  </div>
498
510
  <Foot store={store} root={root} confirming={confirming} onKeep={() => setConfirming(false)} />
@@ -1,12 +1,13 @@
1
1
  // The review UI's one store: who is signed in, this prototype's comments and,
2
2
  // for Studio, the people. Components read it with useSyncExternalStore and
3
3
  // call its actions; every call goes to /api/review (server/api.ts), and each
4
- // answer is merged in place, so a write never refetches the list.
4
+ // answer is merged in place, so a write never refetches the list. The list is
5
+ // what the server sent for this person: nothing here filters it.
5
6
  import { useSyncExternalStore } from 'react';
6
- import type { Anchor, Comment, Person, PersonKind } from '../../core/review/model';
7
+ import type { Access, Anchor, Audience, Comment, Person, PersonKind } from '../../core/review/model';
7
8
 
8
9
  export type Me = Omit<Person, 'epoch'>;
9
- /** off: this site has no review store, so the UI stays out of the way. */
10
+ /** off: this site has no review store, so the UI stays out of the way. guest: the session ended since the page loaded. */
10
11
  type Status = 'loading' | 'ready' | 'guest' | 'off';
11
12
 
12
13
  type State = {
@@ -14,16 +15,21 @@ type State = {
14
15
  me: Me | null;
15
16
  comments: Comment[];
16
17
  people: Me[] | null;
18
+ /** The project default access length, loaded with the people. */
19
+ access: Access | null;
17
20
  error: string | null;
18
21
  };
19
22
 
20
23
  class ApiError extends Error {
21
24
  status: number;
22
25
  problems: string[];
23
- constructor(status: number, message: string, problems: string[] = []) {
26
+ /** A 503 with Retry-After: the store did not answer, and review is on. */
27
+ retry: boolean;
28
+ constructor(status: number, message: string, problems: string[] = [], retry = false) {
24
29
  super(message);
25
30
  this.status = status;
26
31
  this.problems = problems;
32
+ this.retry = retry;
27
33
  }
28
34
  }
29
35
 
@@ -48,6 +54,8 @@ async function call<T>(
48
54
  const json = (await response.json().catch(() => null)) as
49
55
  | ({ error?: string; problems?: string[] } & T)
50
56
  | null;
57
+ if (response.status === 503 && response.headers.has('retry-after'))
58
+ throw new ApiError(503, 'The review store did not answer. Reload in a minute.', [], true);
51
59
  if (!json)
52
60
  throw new ApiError(response.status, `The review API did not answer with JSON (${response.status}).`);
53
61
  if (!response.ok)
@@ -55,9 +63,18 @@ async function call<T>(
55
63
  return json;
56
64
  }
57
65
 
66
+ /**
67
+ * 503 is a site without a review store; 404 is a static preview with no API at all. A 503 with
68
+ * Retry-After is a store that did not answer: review stays on and shows the error.
69
+ */
70
+ const isOff = (error: unknown) =>
71
+ error instanceof ApiError && !error.retry && (error.status === 503 || error.status === 404);
72
+
58
73
  export function createReviewStore(prototype: string) {
59
- let state: State = { status: 'loading', me: null, comments: [], people: null, error: null };
74
+ let state: State = { status: 'loading', me: null, comments: [], people: null, access: null, error: null };
60
75
  const listeners = new Set<() => void>();
76
+ /** Counts loads, so an answer to an older one (Client view turned on and off fast) is dropped. */
77
+ let loads = 0;
61
78
  const set = (patch: Partial<State>) => {
62
79
  state = { ...state, ...patch };
63
80
  for (const l of listeners) l();
@@ -93,6 +110,13 @@ export function createReviewStore(prototype: string) {
93
110
  throw error;
94
111
  }
95
112
  };
113
+ /** A command that answers with a person and their link: merges the person, resolves to the whole URL. */
114
+ const linkOf = (pending: Promise<{ person: Me; link: string }>) =>
115
+ attempt(async () => {
116
+ const r = await pending;
117
+ mergePerson(r.person);
118
+ return new URL(r.link, location.origin).href;
119
+ });
96
120
 
97
121
  return {
98
122
  subscribe(listener: () => void) {
@@ -101,23 +125,36 @@ export function createReviewStore(prototype: string) {
101
125
  },
102
126
  get: () => state,
103
127
 
104
- async load() {
128
+ /** Who is signed in and the comments; `viewAs: 'client'` is Studio's Client view, which the server applies. */
129
+ async load(viewAs?: PersonKind) {
130
+ const n = ++loads;
105
131
  try {
106
132
  const { person } = await call<{ person: Me | null }>('me');
133
+ if (n !== loads) return;
107
134
  if (!person) return set({ status: 'guest', me: null });
108
- const { comments } = await call<{ comments: Comment[] }>('comments', undefined, { prototype });
135
+ const params = { prototype, ...(viewAs ? { viewAs } : {}) };
136
+ const { comments } = await call<{ comments: Comment[] }>('comments', undefined, params);
137
+ if (n !== loads) return;
109
138
  set({ status: 'ready', me: person, comments, error: null });
110
139
  } catch (error) {
111
- // 503 is a site without a review store; 404 is a static preview with no API at all.
112
- if (error instanceof ApiError && (error.status === 503 || error.status === 404))
113
- set({ status: 'off' });
140
+ if (isOff(error)) set({ status: 'off' });
114
141
  else set({ status: 'ready', error: String((error as Error).message) });
115
142
  }
116
143
  },
117
144
 
118
- add: (body: string, anchor: Anchor, states: string[]) =>
145
+ /** A new thread; `audience` is Studio's choice, and the server sets a Client's whatever is sent. */
146
+ add: (body: string, anchor: Anchor, states: string[], audience: Audience | null) =>
119
147
  attempt(async () =>
120
- merge((await call<{ comment: Comment }>('comment.add', { body, anchor, states })).comment),
148
+ merge(
149
+ (
150
+ await call<{ comment: Comment }>('comment.add', {
151
+ body,
152
+ anchor,
153
+ states,
154
+ ...(audience ? { audience } : {}),
155
+ })
156
+ ).comment,
157
+ ),
121
158
  ),
122
159
  reply: (thread: string, body: string) =>
123
160
  attempt(async () =>
@@ -143,19 +180,23 @@ export function createReviewStore(prototype: string) {
143
180
  set({ comments: state.comments.filter((c) => !removed.includes(c.id)) });
144
181
  }),
145
182
 
146
- loadPeople: () => attempt(async () => set({ people: (await call<{ people: Me[] }>('people')).people })),
147
- invite: (name: string, team: string, kind: PersonKind) =>
148
- attempt(async () => {
149
- const r = await call<{ person: Me; link: string }>('people.invite', { name, team, kind });
150
- mergePerson(r.person);
151
- return new URL(r.link, location.origin).href;
152
- }),
153
- reissue: (id: string) =>
183
+ loadPeople: () =>
154
184
  attempt(async () => {
155
- const r = await call<{ person: Me; link: string }>('people.reissue', { id });
156
- mergePerson(r.person);
157
- return new URL(r.link, location.origin).href;
185
+ const [{ people }, { access }] = await Promise.all([
186
+ call<{ people: Me[] }>('people'),
187
+ call<{ access: Access }>('access'),
188
+ ]);
189
+ set({ people, access });
158
190
  }),
191
+ /** A new person; `access` null takes the default for their kind. Resolves to their link. */
192
+ addPerson: (name: string, team: string, kind: PersonKind, access: Access | null) =>
193
+ linkOf(call('people.add', { name, team, kind, ...(access ? { access } : {}) })),
194
+ /** Another one-time link, for another device. */
195
+ newLink: (id: string) => linkOf(call('people.link', { id })),
196
+ /** Ends every session and unused link; resolves to the one new link. */
197
+ signOut: (id: string) => linkOf(call('people.signOut', { id })),
198
+ setAccess: (id: string, access: Access) =>
199
+ attempt(async () => mergePerson((await call<{ person: Me }>('people.access', { id, access })).person)),
159
200
  revoke: (id: string) =>
160
201
  attempt(async () => mergePerson((await call<{ person: Me }>('people.revoke', { id })).person)),
161
202
  clearError: () => set({ error: null }),
@@ -296,10 +296,15 @@
296
296
  box-shadow: var(--rv-raised);
297
297
  color: oklch(0.92 0.04 23);
298
298
  }
299
+ /* Client view on: the same pill in the layer's own material, never the error's red. */
300
+ .rv-alert.rv-viewing { background: var(--harness-bg); color: var(--rv-fg-strong); }
301
+ .rv-alert.rv-viewing .icon { flex: none; color: var(--harness-fg-muted); }
299
302
 
300
303
  /* ---------- pins ---------- */
301
- /* Open: solid and numbered. Resolved: smaller, pale, a check where the number
302
- was. The open card's pin turns to its other face, so it reads as selected. */
304
+ /* Open: solid and numbered. Internal (Studio only): numbered, on a lighter
305
+ grey with a dashed edge, so it reads apart without a hue. Resolved: smaller,
306
+ pale, a check where the number was. The open card's pin turns to its other
307
+ face, so it reads as selected. */
303
308
  .rv-pins { position: fixed; inset: 0; z-index: var(--rv-z-page); pointer-events: none; }
304
309
  .rv-pin {
305
310
  position: absolute;
@@ -342,6 +347,8 @@
342
347
  .rv-pin[data-resolved] { width: 20px; height: 20px; top: -20px; }
343
348
  .rv-pin[data-resolved] .rv-pin-face { border-color: oklch(1 0 0 / 0.9); background: oklch(0.88 0 0); color: oklch(0.42 0 0); box-shadow: 0 1px 4px oklch(0 0 0 / 0.25); }
344
349
  .rv-pin[data-resolved][data-active] .rv-pin-face { background: var(--rv-pin); color: var(--rv-done); border-color: oklch(1 0 0); }
350
+ .rv-pin[data-internal]:not([data-resolved]) .rv-pin-face { background: oklch(0.44 0 0); border-style: dashed; }
351
+ .rv-pin[data-internal][data-active]:not([data-resolved]) .rv-pin-face { background: oklch(1 0 0); color: var(--rv-pin); border-color: var(--rv-pin); }
345
352
  .rv-pin[data-new] { pointer-events: none; }
346
353
  .rv-pin[data-new] .rv-pin-face { background: oklch(1 0 0); border-color: var(--rv-pin); }
347
354
 
@@ -374,6 +381,11 @@
374
381
  .rv-card-head .rv-title + .rv-muted { margin-left: 6px; }
375
382
  .rv-about { flex: 1; min-width: 0; margin-left: 4px; color: var(--harness-fg-muted); font-size: 12px; }
376
383
  .rv-step { margin: 0 2px; font-size: 12px; }
384
+ /* Who the thread is for, Studio only: a hairline tag, quieter than kind and state. */
385
+ .rv-aud { flex: none; display: inline-flex; align-items: center; height: 18px; padding: 0 6px; border-radius: 6px; box-shadow: inset 0 0 0 1px oklch(1 0 0 / 0.14); color: var(--harness-fg-muted); font-size: 11px; font-weight: 500; white-space: nowrap; }
386
+ /* Studio's choice on a new thread: the bar's toggle, small, under the head. */
387
+ .rv-toggle.rv-audience { align-self: flex-start; height: 28px; margin: 8px 10px 0 14px; }
388
+ .rv-toggle.rv-audience button { width: auto; height: 24px; padding: 0 10px; border-radius: 12px; font-size: 12px; }
377
389
  .rv-no {
378
390
  display: inline-grid;
379
391
  flex: none;
@@ -524,6 +536,8 @@
524
536
  .rv-share-row .input { flex: 1; min-width: 0; }
525
537
  /* Copy and Copied are one width, so the row holds still when the word changes. */
526
538
  .rv .btn.rv-copy { flex: none; width: 68px; padding: 0; }
539
+ /* How links behave: one quiet line of small print under the form. */
540
+ .rv-disclosure { font-size: 12px; line-height: 16px; }
527
541
  .rv-people { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
528
542
  .rv-people li { display: flex; flex-direction: column; gap: 4px; padding: 10px 0; border-bottom: 1px solid var(--harness-border); }
529
543
  .rv-people li:last-child { border-bottom: 0; }