@milesroxas/design-hub 0.7.0 → 0.8.1
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 +53 -0
- package/core/review/policy.test.ts +101 -24
- package/core/review/policy.ts +42 -6
- package/core/review/service.test.ts +217 -7
- package/core/review/service.ts +122 -40
- package/core/review/store.ts +5 -0
- package/dist/core/review/model.d.ts +33 -0
- package/dist/core/review/model.js +39 -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 +99 -42
- package/dist/core/review/store.d.ts +5 -0
- package/dist/core/review/store.js +5 -0
- package/dist/scripts/comments.d.ts +10 -2
- package/dist/scripts/comments.js +20 -8
- 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 +42 -25
- package/shell/review/Review.tsx +112 -24
- package/shell/review/ThreadCard.tsx +29 -25
- package/shell/review/client.ts +32 -10
- package/shell/review/review.css +41 -16
- 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,11 +2,14 @@
|
|
|
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 on amber, the colour of an internal note, its
|
|
7
|
+
// colour alone telling it apart; a resolved one is pale and carries a check.
|
|
8
|
+
// The number is the thread's own, never its place in the list. The label read
|
|
9
|
+
// out (Comment I2) keeps the I, so two threads never sound alike.
|
|
7
10
|
import { Icon } from '@kit/Icon';
|
|
8
11
|
import { useEffect, useRef } from 'react';
|
|
9
|
-
import type
|
|
12
|
+
import { type Comment, threadLabel } from '../../core/review/model';
|
|
10
13
|
import { pinPoint } from './anchor';
|
|
11
14
|
import { draftPoint } from './PickLayer';
|
|
12
15
|
import type { Draft } from './view';
|
|
@@ -16,15 +19,46 @@ const moveTo = (el: HTMLElement, at: { x: number; y: number } | null) => {
|
|
|
16
19
|
if (at) el.style.transform = `translate(${at.x}px, ${at.y}px)`;
|
|
17
20
|
};
|
|
18
21
|
|
|
22
|
+
/** "Comment I3, internal, resolved, by Rae": the label when it has one, then what the face shows. */
|
|
23
|
+
function pinLabel(c: Comment): string {
|
|
24
|
+
const label = threadLabel(c);
|
|
25
|
+
const words = [
|
|
26
|
+
label ? `Comment ${label}` : 'Comment',
|
|
27
|
+
c.audience === 'internal' && 'internal',
|
|
28
|
+
c.status === 'resolved' && 'resolved',
|
|
29
|
+
];
|
|
30
|
+
return `${words.filter(Boolean).join(', ')}, by ${c.author.name}`;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function Pin({ c, active, onOpen }: { c: Comment; active: boolean; onOpen: (id: string) => void }) {
|
|
34
|
+
const resolved = c.status === 'resolved';
|
|
35
|
+
// A Client is never sent an internal thread, so only Studio ever sees this face.
|
|
36
|
+
const internal = c.audience === 'internal';
|
|
37
|
+
return (
|
|
38
|
+
<button
|
|
39
|
+
type="button"
|
|
40
|
+
className="rv-pin"
|
|
41
|
+
data-pin={c.id}
|
|
42
|
+
data-resolved={resolved ? '' : undefined}
|
|
43
|
+
data-internal={internal ? '' : undefined}
|
|
44
|
+
data-active={active ? '' : undefined}
|
|
45
|
+
aria-label={pinLabel(c)}
|
|
46
|
+
aria-pressed={active}
|
|
47
|
+
hidden
|
|
48
|
+
onClick={() => onOpen(c.id)}
|
|
49
|
+
>
|
|
50
|
+
<span className="rv-pin-face">{resolved ? <Icon name="check" size={12} /> : c.number || null}</span>
|
|
51
|
+
</button>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
19
55
|
export function Pins({
|
|
20
56
|
comments,
|
|
21
|
-
number,
|
|
22
57
|
active,
|
|
23
58
|
draft,
|
|
24
59
|
onOpen,
|
|
25
60
|
}: {
|
|
26
61
|
comments: Comment[];
|
|
27
|
-
number: Map<string, number>;
|
|
28
62
|
active: string | null;
|
|
29
63
|
draft: Draft | null;
|
|
30
64
|
onOpen: (id: string) => void;
|
|
@@ -67,26 +101,9 @@ export function Pins({
|
|
|
67
101
|
|
|
68
102
|
return (
|
|
69
103
|
<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
|
-
})}
|
|
104
|
+
{comments.map((c) => (
|
|
105
|
+
<Pin key={c.id} c={c} active={active === c.id} onOpen={onOpen} />
|
|
106
|
+
))}
|
|
90
107
|
{draft?.offset && (
|
|
91
108
|
<span className="rv-pin" data-draft="" data-new="" aria-hidden="true" hidden>
|
|
92
109
|
<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,24 +366,69 @@ 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, in the head beside the title. 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
|
+
// The highlight shows sighted people what it is on; the label tells everyone else.
|
|
424
|
+
<Card
|
|
425
|
+
at={draftPoint(draft)}
|
|
426
|
+
label={`New comment on ${describe(draft.target)}`}
|
|
427
|
+
onDismiss={() => dispatch({ type: 'close' })}
|
|
428
|
+
>
|
|
342
429
|
<header className="rv-card-head">
|
|
343
430
|
<h2 className="rv-title">New comment</h2>
|
|
344
|
-
<
|
|
431
|
+
{audience === 'choose' && <AudienceChoice value={chosen} onChange={setChosen} />}
|
|
345
432
|
<span className="rv-spacer" />
|
|
346
433
|
<Button
|
|
347
434
|
kind="tertiary"
|
|
@@ -359,7 +446,8 @@ function DraftCard({
|
|
|
359
446
|
send="Post"
|
|
360
447
|
autoFocus
|
|
361
448
|
onSend={async (body) => {
|
|
362
|
-
const
|
|
449
|
+
const anchor = captureAnchor(where, draft.target, draftPoint(draft));
|
|
450
|
+
const c = await store.add(body, anchor, states, sent);
|
|
363
451
|
dispatch({ type: 'open', id: c.id });
|
|
364
452
|
}}
|
|
365
453
|
onCancel={() => dispatch({ type: 'close' })}
|
|
@@ -2,18 +2,20 @@
|
|
|
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, threadLabel } 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';
|
|
13
15
|
import { Field, useTextBox } from './Field';
|
|
14
|
-
import { describe } from './PickLayer';
|
|
15
16
|
|
|
16
17
|
const KIND_LABEL: Record<Kind, string> = { bug: 'Bug', taste: 'Taste', copy: 'Copy' };
|
|
18
|
+
const AUDIENCE_LABEL: Record<Audience, string> = { internal: 'Internal', client: 'Client-facing' };
|
|
17
19
|
const relative = new Intl.RelativeTimeFormat('en', { numeric: 'auto', style: 'short' });
|
|
18
20
|
const STEPS: [Intl.RelativeTimeFormatUnit, number][] = [
|
|
19
21
|
['year', 31_536_000],
|
|
@@ -30,14 +32,6 @@ function ago(iso: string): string {
|
|
|
30
32
|
return 'just now';
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
/** What the comment is on, in a few words. */
|
|
34
|
-
function about(root: Comment): string {
|
|
35
|
-
const target = root.anchor?.target;
|
|
36
|
-
if (!target) return 'On the page';
|
|
37
|
-
const el = document.querySelector(target);
|
|
38
|
-
return el ? `On ${describe(el)}` : 'On another view';
|
|
39
|
-
}
|
|
40
|
-
|
|
41
35
|
function Avatar({ name }: { name: string }) {
|
|
42
36
|
const initials = name
|
|
43
37
|
.split(/[\s-]+/)
|
|
@@ -158,11 +152,13 @@ function Tags({ tags }: { tags: string[] }) {
|
|
|
158
152
|
function Entry({
|
|
159
153
|
store,
|
|
160
154
|
me,
|
|
155
|
+
root,
|
|
161
156
|
comment,
|
|
162
157
|
tags = [],
|
|
163
158
|
}: {
|
|
164
159
|
store: ReviewStore;
|
|
165
160
|
me: Me | null;
|
|
161
|
+
root: Comment;
|
|
166
162
|
comment: Comment;
|
|
167
163
|
tags?: string[];
|
|
168
164
|
}) {
|
|
@@ -173,7 +169,7 @@ function Entry({
|
|
|
173
169
|
<div className="rv-msg-main">
|
|
174
170
|
<EntryHead
|
|
175
171
|
comment={comment}
|
|
176
|
-
canEdit={can(me, 'edit', comment) && !editing}
|
|
172
|
+
canEdit={can(me, 'edit', root, comment) && !editing}
|
|
177
173
|
onEdit={() => setEditing(true)}
|
|
178
174
|
/>
|
|
179
175
|
{editing ? (
|
|
@@ -379,7 +375,8 @@ function ResolvedBand({ root }: { root: Comment }) {
|
|
|
379
375
|
type HeadProps = {
|
|
380
376
|
store: ReviewStore;
|
|
381
377
|
root: Comment;
|
|
382
|
-
|
|
378
|
+
/** Show who the thread is for: Studio only, and not in Client view. */
|
|
379
|
+
mark: boolean;
|
|
383
380
|
index: number;
|
|
384
381
|
total: number;
|
|
385
382
|
states: string[];
|
|
@@ -392,11 +389,11 @@ type HeadProps = {
|
|
|
392
389
|
onDelete: () => void;
|
|
393
390
|
};
|
|
394
391
|
|
|
395
|
-
/**
|
|
392
|
+
/** Its number and who it is for, then its one decision and the rest. The pin beside the card already shows what it is on. */
|
|
396
393
|
function ThreadHead({
|
|
397
394
|
store,
|
|
398
395
|
root,
|
|
399
|
-
|
|
396
|
+
mark,
|
|
400
397
|
index,
|
|
401
398
|
total,
|
|
402
399
|
states,
|
|
@@ -410,10 +407,15 @@ function ThreadHead({
|
|
|
410
407
|
}: HeadProps) {
|
|
411
408
|
return (
|
|
412
409
|
<header className="rv-card-head">
|
|
413
|
-
<span className="rv-no" aria-hidden="true">
|
|
414
|
-
{root.status === 'resolved' ? <Icon name="check" size={12} /> :
|
|
410
|
+
<span className="rv-no" data-audience={root.audience} aria-hidden="true">
|
|
411
|
+
{root.status === 'resolved' ? <Icon name="check" size={12} /> : root.number || null}
|
|
415
412
|
</span>
|
|
416
|
-
|
|
413
|
+
{mark && (
|
|
414
|
+
<span className="rv-aud" data-audience={root.audience}>
|
|
415
|
+
{AUDIENCE_LABEL[root.audience]}
|
|
416
|
+
</span>
|
|
417
|
+
)}
|
|
418
|
+
<span className="rv-spacer" />
|
|
417
419
|
<Stepper index={index} total={total} onStep={onStep} />
|
|
418
420
|
{canResolve && <ResolveButton store={store} root={root} />}
|
|
419
421
|
<ThreadMenu
|
|
@@ -442,7 +444,7 @@ export function ThreadCard({
|
|
|
442
444
|
me,
|
|
443
445
|
root,
|
|
444
446
|
replies,
|
|
445
|
-
|
|
447
|
+
mark,
|
|
446
448
|
index,
|
|
447
449
|
total,
|
|
448
450
|
states,
|
|
@@ -455,7 +457,7 @@ export function ThreadCard({
|
|
|
455
457
|
me: Me | null;
|
|
456
458
|
root: Comment;
|
|
457
459
|
replies: Comment[];
|
|
458
|
-
|
|
460
|
+
mark: boolean;
|
|
459
461
|
index: number;
|
|
460
462
|
total: number;
|
|
461
463
|
states: string[];
|
|
@@ -466,22 +468,24 @@ export function ThreadCard({
|
|
|
466
468
|
}) {
|
|
467
469
|
const [confirming, setConfirming] = useState(false);
|
|
468
470
|
const resolved = root.status === 'resolved';
|
|
471
|
+
const label = threadLabel(root);
|
|
472
|
+
const words = [label ? `Comment ${label}` : 'Comment', mark && AUDIENCE_LABEL[root.audience]];
|
|
469
473
|
return (
|
|
470
474
|
<Card
|
|
471
475
|
at={at}
|
|
472
|
-
label={
|
|
476
|
+
label={[...words, resolved && 'resolved'].filter(Boolean).join(', ')}
|
|
473
477
|
resolved={resolved}
|
|
474
478
|
onDismiss={onClose}
|
|
475
479
|
>
|
|
476
480
|
<ThreadHead
|
|
477
481
|
store={store}
|
|
478
482
|
root={root}
|
|
479
|
-
|
|
483
|
+
mark={mark}
|
|
480
484
|
index={index}
|
|
481
485
|
total={total}
|
|
482
486
|
states={states}
|
|
483
487
|
canResolve={can(me, 'resolve', root)}
|
|
484
|
-
canTriage={can(me, 'triage')}
|
|
488
|
+
canTriage={can(me, 'triage', root)}
|
|
485
489
|
canDelete={can(me, 'delete', root)}
|
|
486
490
|
onStep={onStep}
|
|
487
491
|
onClose={onClose}
|
|
@@ -490,9 +494,9 @@ export function ThreadCard({
|
|
|
490
494
|
/>
|
|
491
495
|
<ResolvedBand root={root} />
|
|
492
496
|
<div className="rv-card-body">
|
|
493
|
-
<Entry store={store} me={me} comment={root} tags={tagsOf(root)} />
|
|
497
|
+
<Entry store={store} me={me} root={root} comment={root} tags={tagsOf(root)} />
|
|
494
498
|
{replies.map((r) => (
|
|
495
|
-
<Entry key={r.id} store={store} me={me} comment={r} />
|
|
499
|
+
<Entry key={r.id} store={store} me={me} root={root} comment={r} />
|
|
496
500
|
))}
|
|
497
501
|
</div>
|
|
498
502
|
<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 () =>
|