@milesroxas/design-hub 0.7.0 → 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.
- package/core/review/model.ts +42 -0
- package/core/review/policy.test.ts +101 -24
- package/core/review/policy.ts +42 -6
- package/core/review/service.test.ts +172 -6
- package/core/review/service.ts +104 -40
- package/core/review/store.ts +2 -0
- package/dist/core/review/model.d.ts +24 -0
- package/dist/core/review/model.js +32 -0
- package/dist/core/review/policy.d.ts +21 -2
- package/dist/core/review/policy.js +34 -2
- package/dist/core/review/service.d.ts +15 -5
- package/dist/core/review/service.js +83 -42
- package/dist/core/review/store.d.ts +2 -0
- package/dist/core/review/store.js +2 -0
- package/dist/scripts/comments.d.ts +10 -2
- package/dist/scripts/comments.js +18 -7
- package/dist/server/api.js +12 -2
- package/kit/prefs.ts +19 -2
- package/package.json +1 -1
- package/shell/review/Bar.tsx +97 -4
- package/shell/review/Pins.tsx +39 -24
- package/shell/review/Review.tsx +106 -22
- package/shell/review/ThreadCard.tsx +25 -13
- package/shell/review/client.ts +32 -10
- package/shell/review/review.css +14 -2
- package/shell/review/view.test.ts +73 -1
- package/shell/review/view.ts +49 -3
- package/skills/miles-review/SKILL.md +4 -2
package/shell/review/Pins.tsx
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// written. In comment mode they are the way into a thread, so each is a real
|
|
3
3
|
// button in the tab order. The button is the hit area and never changes size;
|
|
4
4
|
// the face inside it is what presses and lifts, so a press near the edge
|
|
5
|
-
// still ends on the pin. An open thread's pin is solid and numbered;
|
|
6
|
-
//
|
|
5
|
+
// still ends on the pin. An open thread's pin is solid and numbered; an
|
|
6
|
+
// open internal one is numbered too, on a lighter face with a dashed edge; a
|
|
7
|
+
// resolved one is pale and carries a check. The number is the thread's own,
|
|
8
|
+
// never its place in the list.
|
|
7
9
|
import { Icon } from '@kit/Icon';
|
|
8
10
|
import { useEffect, useRef } from 'react';
|
|
9
11
|
import type { Comment } from '../../core/review/model';
|
|
@@ -16,15 +18,45 @@ const moveTo = (el: HTMLElement, at: { x: number; y: number } | null) => {
|
|
|
16
18
|
if (at) el.style.transform = `translate(${at.x}px, ${at.y}px)`;
|
|
17
19
|
};
|
|
18
20
|
|
|
21
|
+
/** "Comment 3, internal, resolved, by Rae": the number when it has one, then what the face shows. */
|
|
22
|
+
function pinLabel(c: Comment): string {
|
|
23
|
+
const words = [
|
|
24
|
+
c.number ? `Comment ${c.number}` : 'Comment',
|
|
25
|
+
c.audience === 'internal' && 'internal',
|
|
26
|
+
c.status === 'resolved' && 'resolved',
|
|
27
|
+
];
|
|
28
|
+
return `${words.filter(Boolean).join(', ')}, by ${c.author.name}`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function Pin({ c, active, onOpen }: { c: Comment; active: boolean; onOpen: (id: string) => void }) {
|
|
32
|
+
const resolved = c.status === 'resolved';
|
|
33
|
+
// A Client is never sent an internal thread, so only Studio ever sees this face.
|
|
34
|
+
const internal = c.audience === 'internal';
|
|
35
|
+
return (
|
|
36
|
+
<button
|
|
37
|
+
type="button"
|
|
38
|
+
className="rv-pin"
|
|
39
|
+
data-pin={c.id}
|
|
40
|
+
data-resolved={resolved ? '' : undefined}
|
|
41
|
+
data-internal={internal ? '' : undefined}
|
|
42
|
+
data-active={active ? '' : undefined}
|
|
43
|
+
aria-label={pinLabel(c)}
|
|
44
|
+
aria-pressed={active}
|
|
45
|
+
hidden
|
|
46
|
+
onClick={() => onOpen(c.id)}
|
|
47
|
+
>
|
|
48
|
+
<span className="rv-pin-face">{resolved ? <Icon name="check" size={12} /> : c.number || null}</span>
|
|
49
|
+
</button>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
19
53
|
export function Pins({
|
|
20
54
|
comments,
|
|
21
|
-
number,
|
|
22
55
|
active,
|
|
23
56
|
draft,
|
|
24
57
|
onOpen,
|
|
25
58
|
}: {
|
|
26
59
|
comments: Comment[];
|
|
27
|
-
number: Map<string, number>;
|
|
28
60
|
active: string | null;
|
|
29
61
|
draft: Draft | null;
|
|
30
62
|
onOpen: (id: string) => void;
|
|
@@ -67,26 +99,9 @@ export function Pins({
|
|
|
67
99
|
|
|
68
100
|
return (
|
|
69
101
|
<div ref={layer} className="rv-pins">
|
|
70
|
-
{comments.map((c) =>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return (
|
|
74
|
-
<button
|
|
75
|
-
key={c.id}
|
|
76
|
-
type="button"
|
|
77
|
-
className="rv-pin"
|
|
78
|
-
data-pin={c.id}
|
|
79
|
-
data-resolved={resolved ? '' : undefined}
|
|
80
|
-
data-active={active === c.id ? '' : undefined}
|
|
81
|
-
aria-label={`Comment ${n}${resolved ? ', resolved,' : ''} by ${c.author.name}`}
|
|
82
|
-
aria-pressed={active === c.id}
|
|
83
|
-
hidden
|
|
84
|
-
onClick={() => onOpen(c.id)}
|
|
85
|
-
>
|
|
86
|
-
<span className="rv-pin-face">{resolved ? <Icon name="check" size={12} /> : n}</span>
|
|
87
|
-
</button>
|
|
88
|
-
);
|
|
89
|
-
})}
|
|
102
|
+
{comments.map((c) => (
|
|
103
|
+
<Pin key={c.id} c={c} active={active === c.id} onOpen={onOpen} />
|
|
104
|
+
))}
|
|
90
105
|
{draft?.offset && (
|
|
91
106
|
<span className="rv-pin" data-draft="" data-new="" aria-hidden="true" hidden>
|
|
92
107
|
<span className="rv-pin-face" />
|
package/shell/review/Review.tsx
CHANGED
|
@@ -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] =
|
|
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}
|
|
@@ -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
|
|
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
|
|
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={
|
|
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
|
-
|
|
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 &&
|
|
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
|
)}
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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} /> :
|
|
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
|
-
|
|
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
|
-
|
|
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={
|
|
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
|
-
|
|
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)} />
|
package/shell/review/client.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
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 { Access, 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
10
|
/** off: this site has no review store, so the UI stays out of the way. guest: the session ended since the page loaded. */
|
|
@@ -62,9 +63,18 @@ async function call<T>(
|
|
|
62
63
|
return json;
|
|
63
64
|
}
|
|
64
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
|
+
|
|
65
73
|
export function createReviewStore(prototype: string) {
|
|
66
74
|
let state: State = { status: 'loading', me: null, comments: [], people: null, access: null, error: null };
|
|
67
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;
|
|
68
78
|
const set = (patch: Partial<State>) => {
|
|
69
79
|
state = { ...state, ...patch };
|
|
70
80
|
for (const l of listeners) l();
|
|
@@ -115,24 +125,36 @@ export function createReviewStore(prototype: string) {
|
|
|
115
125
|
},
|
|
116
126
|
get: () => state,
|
|
117
127
|
|
|
118
|
-
|
|
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;
|
|
119
131
|
try {
|
|
120
132
|
const { person } = await call<{ person: Me | null }>('me');
|
|
133
|
+
if (n !== loads) return;
|
|
121
134
|
if (!person) return set({ status: 'guest', me: null });
|
|
122
|
-
const {
|
|
135
|
+
const params = { prototype, ...(viewAs ? { viewAs } : {}) };
|
|
136
|
+
const { comments } = await call<{ comments: Comment[] }>('comments', undefined, params);
|
|
137
|
+
if (n !== loads) return;
|
|
123
138
|
set({ status: 'ready', me: person, comments, error: null });
|
|
124
139
|
} catch (error) {
|
|
125
|
-
|
|
126
|
-
// Retry-After is a store that did not answer: review stays on and shows the error.
|
|
127
|
-
if (error instanceof ApiError && !error.retry && (error.status === 503 || error.status === 404))
|
|
128
|
-
set({ status: 'off' });
|
|
140
|
+
if (isOff(error)) set({ status: 'off' });
|
|
129
141
|
else set({ status: 'ready', error: String((error as Error).message) });
|
|
130
142
|
}
|
|
131
143
|
},
|
|
132
144
|
|
|
133
|
-
|
|
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) =>
|
|
134
147
|
attempt(async () =>
|
|
135
|
-
merge(
|
|
148
|
+
merge(
|
|
149
|
+
(
|
|
150
|
+
await call<{ comment: Comment }>('comment.add', {
|
|
151
|
+
body,
|
|
152
|
+
anchor,
|
|
153
|
+
states,
|
|
154
|
+
...(audience ? { audience } : {}),
|
|
155
|
+
})
|
|
156
|
+
).comment,
|
|
157
|
+
),
|
|
136
158
|
),
|
|
137
159
|
reply: (thread: string, body: string) =>
|
|
138
160
|
attempt(async () =>
|
package/shell/review/review.css
CHANGED
|
@@ -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.
|
|
302
|
-
|
|
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;
|