@milesroxas/design-hub 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -11
- package/core/files.test.ts +76 -0
- package/core/files.ts +131 -0
- package/core/prototype.test.ts +124 -7
- package/core/prototype.ts +133 -24
- package/core/review/model.ts +119 -2
- package/core/review/policy.test.ts +79 -22
- package/core/review/policy.ts +36 -8
- package/core/review/service.test.ts +1464 -340
- package/core/review/service.ts +777 -191
- package/core/review/store.test.ts +91 -0
- package/core/review/store.ts +143 -33
- package/dist/core/files.d.ts +39 -0
- package/dist/core/files.js +107 -0
- package/dist/core/prototype.d.ts +61 -12
- package/dist/core/prototype.js +105 -26
- package/dist/core/review/model.d.ts +76 -2
- package/dist/core/review/model.js +76 -1
- package/dist/core/review/policy.d.ts +11 -4
- package/dist/core/review/policy.js +14 -2
- package/dist/core/review/service.d.ts +197 -45
- package/dist/core/review/service.js +702 -192
- package/dist/core/review/store.d.ts +84 -31
- package/dist/core/review/store.js +66 -33
- package/dist/scripts/bootstrap.d.ts +4 -34
- package/dist/scripts/bootstrap.js +9 -244
- package/dist/scripts/cli.js +6 -0
- package/dist/scripts/client.d.ts +45 -0
- package/dist/scripts/client.js +320 -0
- package/dist/scripts/commands.js +6 -0
- package/dist/scripts/comments.d.ts +8 -26
- package/dist/scripts/comments.js +27 -14
- package/dist/scripts/lib/builds.d.ts +40 -0
- package/dist/scripts/lib/builds.js +198 -0
- package/dist/scripts/lib/cli.js +3 -1
- package/dist/scripts/lib/deploy.d.ts +6 -90
- package/dist/scripts/lib/deploy.js +24 -137
- package/dist/scripts/lib/dns.d.ts +49 -0
- package/dist/scripts/lib/dns.js +141 -0
- package/dist/scripts/lib/fake-host.d.ts +168 -0
- package/dist/scripts/lib/fake-host.js +244 -0
- package/dist/scripts/lib/host.d.ts +87 -0
- package/dist/scripts/lib/host.js +362 -0
- package/dist/scripts/lib/linked.d.ts +51 -0
- package/dist/scripts/lib/linked.js +124 -0
- package/dist/scripts/lib/names.d.ts +35 -0
- package/dist/scripts/lib/names.js +77 -0
- package/dist/scripts/lib/review.d.ts +23 -2
- package/dist/scripts/lib/review.js +32 -15
- package/dist/scripts/lib/studio-deps.d.ts +35 -0
- package/dist/scripts/lib/studio-deps.js +79 -0
- package/dist/scripts/lib/studios.d.ts +70 -0
- package/dist/scripts/lib/studios.js +187 -0
- package/dist/scripts/lib/update.d.ts +33 -0
- package/dist/scripts/lib/update.js +40 -0
- package/dist/scripts/lib/vercel.d.ts +1 -23
- package/dist/scripts/lib/vercel.js +6 -81
- package/dist/scripts/people.d.ts +7 -11
- package/dist/scripts/people.js +51 -46
- package/dist/scripts/preflight.d.ts +8 -1
- package/dist/scripts/preflight.js +36 -19
- package/dist/scripts/project.d.ts +86 -0
- package/dist/scripts/project.js +141 -0
- package/dist/scripts/share.d.ts +105 -30
- package/dist/scripts/share.js +82 -154
- package/dist/scripts/skills.d.ts +18 -2
- package/dist/scripts/skills.js +22 -3
- package/dist/scripts/studio.d.ts +75 -0
- package/dist/scripts/studio.js +401 -0
- package/dist/scripts/upgrade.d.ts +10 -2
- package/dist/scripts/upgrade.js +44 -14
- package/dist/server/api.d.ts +22 -11
- package/dist/server/api.js +114 -46
- package/dist/server/blob.d.ts +10 -0
- package/dist/server/blob.js +53 -0
- package/dist/server/checks.js +2 -2
- package/dist/server/dev.js +4 -4
- package/dist/server/env.d.ts +2 -0
- package/dist/server/env.js +9 -0
- package/dist/server/fake-upstash.js +52 -3
- package/dist/server/hosts.d.ts +11 -0
- package/dist/server/hosts.js +31 -0
- package/dist/server/local.d.ts +7 -1
- package/dist/server/local.js +10 -1
- package/dist/server/mark.d.ts +41 -0
- package/dist/server/mark.js +111 -0
- package/dist/server/session.d.ts +17 -9
- package/dist/server/session.js +22 -45
- package/dist/server/upstash.js +20 -0
- package/dist/vercel/files.d.ts +11 -0
- package/dist/vercel/files.js +68 -0
- package/dist/vercel/index.d.ts +4 -3
- package/dist/vercel/index.js +12 -8
- package/dist/vercel/proxy.d.ts +69 -4
- package/dist/vercel/proxy.js +171 -107
- package/dist/vite/plugin.d.ts +24 -1
- package/dist/vite/plugin.js +46 -2
- package/kit/dials.tsx +2 -2
- package/package.json +2 -1
- package/shell/Guide.tsx +11 -5
- package/shell/Index.tsx +32 -10
- package/shell/Notice.tsx +1 -1
- package/shell/controls.ts +1 -1
- package/shell/hub.ts +5 -1
- package/shell/main.tsx +18 -3
- package/shell/review/Review.tsx +2 -2
- package/shell/review/ThreadCard.tsx +5 -5
- package/shell/review/client.ts +28 -11
- package/shell/review/view.test.ts +19 -0
- package/shell/review/view.ts +25 -0
- package/shell/shell.css +4 -0
- package/shell/studio/ClientHub.tsx +98 -0
- package/shell/studio/hub.css +48 -0
- package/shell/studio/index.html +14 -0
- package/shell/studio/main.tsx +17 -0
- package/skills/miles-deploy/SKILL.md +120 -65
- package/skills/miles-design-hub/SKILL.md +11 -9
- package/skills/miles-review/SKILL.md +5 -7
- package/skills/miles-worktrees/SKILL.md +3 -3
- package/templates/conductor/settings.toml +1 -1
- package/templates/studio/.env.example +9 -0
- package/templates/studio/.vercelignore +5 -0
- package/templates/studio/README.md +84 -0
- package/templates/studio/_gitignore +7 -0
- package/templates/studio/api/files.ts +4 -0
- package/templates/studio/api/review.ts +4 -0
- package/templates/studio/build.mjs +4 -0
- package/templates/studio/package.json +16 -0
- package/templates/studio/proxy.ts +4 -0
- package/templates/studio/studio.json +9 -0
- package/templates/studio/vercel.json +27 -0
package/shell/Index.tsx
CHANGED
|
@@ -22,6 +22,7 @@ import { AUDIENCE_LABEL, audienceIn, emptyState, lensOf, withAudience } from './
|
|
|
22
22
|
import { ClientViewNote } from './ClientViewNote';
|
|
23
23
|
import { type Hub, loadHub, saveAudience } from './hub';
|
|
24
24
|
import { type Entry, guides } from './registry';
|
|
25
|
+
import { signedOut } from './review/client';
|
|
25
26
|
import './shell.css';
|
|
26
27
|
|
|
27
28
|
// The index is built from the server's answer (shell/hub.ts): Studio's view
|
|
@@ -51,7 +52,11 @@ const groupsOf = (list: Entry[]): Group[] => {
|
|
|
51
52
|
return {
|
|
52
53
|
id: `feature-${f}`,
|
|
53
54
|
title: featureTitle(f),
|
|
54
|
-
guide: guides.has(f)
|
|
55
|
+
guide: guides.has(f)
|
|
56
|
+
? import.meta.env.BASE_URL === '/'
|
|
57
|
+
? guideHref(f)
|
|
58
|
+
: `${import.meta.env.BASE_URL}guide/${f}/`
|
|
59
|
+
: undefined,
|
|
55
60
|
items: primary ? [primary] : alternates,
|
|
56
61
|
alternates: primary ? alternates : [],
|
|
57
62
|
explorations: own.filter((e) => e.kind === 'exploration'),
|
|
@@ -96,7 +101,10 @@ function useIndexFilter(entries: Entry[]) {
|
|
|
96
101
|
const RISE_CAP = 8;
|
|
97
102
|
const rise = (i: number) => ({ '--i': Math.min(i, RISE_CAP) }) as CSSProperties;
|
|
98
103
|
|
|
99
|
-
type Loaded =
|
|
104
|
+
type Loaded =
|
|
105
|
+
| { status: 'loading' }
|
|
106
|
+
| { status: 'error'; message: string; signedOut: boolean }
|
|
107
|
+
| { status: 'ready'; hub: Hub };
|
|
100
108
|
|
|
101
109
|
/**
|
|
102
110
|
* The index as the server answers it for this view, and Studio's switch.
|
|
@@ -113,7 +121,8 @@ function useHub(clientView: boolean) {
|
|
|
113
121
|
setLoaded({ status: 'loading' });
|
|
114
122
|
loadHub(clientView).then(
|
|
115
123
|
(hub) => current && setLoaded({ status: 'ready', hub }),
|
|
116
|
-
(error: Error) =>
|
|
124
|
+
(error: Error) =>
|
|
125
|
+
current && setLoaded({ status: 'error', message: error.message, signedOut: signedOut(error) }),
|
|
117
126
|
);
|
|
118
127
|
return () => {
|
|
119
128
|
current = false;
|
|
@@ -213,15 +222,28 @@ function IndexPage({ loaded, controls, head }: { loaded: Loaded; controls: Contr
|
|
|
213
222
|
return (
|
|
214
223
|
<main className="index" aria-busy={loaded.status === 'loading'}>
|
|
215
224
|
<IndexHead>{head}</IndexHead>
|
|
216
|
-
{loaded.status === 'error' ?
|
|
217
|
-
<p className="index-none" role="alert">
|
|
218
|
-
The prototypes did not load: {loaded.message}
|
|
219
|
-
</p>
|
|
220
|
-
) : null}
|
|
225
|
+
{loaded.status === 'error' ? <LoadFailed loaded={loaded} /> : null}
|
|
221
226
|
</main>
|
|
222
227
|
);
|
|
223
228
|
}
|
|
224
229
|
|
|
230
|
+
/** The index did not load: signed out says how to sign in again, as the client's hub does; anything else says why. */
|
|
231
|
+
function LoadFailed({ loaded }: { loaded: Extract<Loaded, { status: 'error' }> }) {
|
|
232
|
+
if (!loaded.signedOut)
|
|
233
|
+
return (
|
|
234
|
+
<p className="index-none" role="alert">
|
|
235
|
+
The prototypes did not load: {loaded.message}
|
|
236
|
+
</p>
|
|
237
|
+
);
|
|
238
|
+
return (
|
|
239
|
+
<section className="index-empty index-signed-out" role="alert">
|
|
240
|
+
<h2>You are signed out</h2>
|
|
241
|
+
<p>Reload the page to see how to sign in again.</p>
|
|
242
|
+
<Button kind="secondary" size="sm" label="Reload" onClick={() => location.reload()} />
|
|
243
|
+
</section>
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
|
|
225
247
|
function IndexHead({ children }: { children?: ReactNode }) {
|
|
226
248
|
return (
|
|
227
249
|
<header className="index-head">
|
|
@@ -305,7 +327,7 @@ function IndexList({
|
|
|
305
327
|
<li key={e.slug} className="index-rise" style={rise(from + i)}>
|
|
306
328
|
<a
|
|
307
329
|
className="index-row"
|
|
308
|
-
href={
|
|
330
|
+
href={`${import.meta.env.BASE_URL}${e.slug}/`}
|
|
309
331
|
data-kind={e.kind}
|
|
310
332
|
data-chosen={leaving === e.slug || undefined}
|
|
311
333
|
onClick={(ev) => onOpen(ev, e.slug)}
|
|
@@ -449,7 +471,7 @@ function Explorations({
|
|
|
449
471
|
<li key={e.slug} className="index-rise" style={rise(at + 1 + i)}>
|
|
450
472
|
<a
|
|
451
473
|
className="index-card"
|
|
452
|
-
href={
|
|
474
|
+
href={`${import.meta.env.BASE_URL}${e.slug}/`}
|
|
453
475
|
data-chosen={leaving === e.slug || undefined}
|
|
454
476
|
onClick={(ev) => onOpen(ev, e.slug)}
|
|
455
477
|
>
|
package/shell/Notice.tsx
CHANGED
|
@@ -7,7 +7,7 @@ export function Notice({ title, body, detail }: { title: string; body: string; d
|
|
|
7
7
|
<h1>{title}</h1>
|
|
8
8
|
<p>{body}</p>
|
|
9
9
|
{detail ? <pre>{detail}</pre> : null}
|
|
10
|
-
<a href=
|
|
10
|
+
<a href={import.meta.env.BASE_URL}>All prototypes</a>
|
|
11
11
|
</main>
|
|
12
12
|
);
|
|
13
13
|
}
|
package/shell/controls.ts
CHANGED
|
@@ -20,7 +20,7 @@ export async function loadControls(prototype: string) {
|
|
|
20
20
|
setControls({ studio: view === 'studio', marks: { dials, variants }, save });
|
|
21
21
|
} catch (error) {
|
|
22
22
|
// No review API at all (a local preview of the build) is Studio's view, as on the index, with nowhere to keep a mark.
|
|
23
|
-
// Any other failure leaves the narrowest view: a Client's, with nothing marked.
|
|
23
|
+
// Any other failure, a session that ended (the gate's 401) among them, leaves the narrowest view: a Client's, with nothing marked.
|
|
24
24
|
setControls({ studio: noApi(error), marks: NO_MARKS, save: null });
|
|
25
25
|
}
|
|
26
26
|
}
|
package/shell/hub.ts
CHANGED
|
@@ -11,7 +11,11 @@ import { call, type Me, noApi } from './review/client';
|
|
|
11
11
|
/** `failed` counts entries that did not load for a reason other than not being there. */
|
|
12
12
|
export type Hub = HubAnswer & { me: Me | null; entries: Entry[]; failed: number };
|
|
13
13
|
|
|
14
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Who is signed in and the index read. With no review API at all (a local
|
|
16
|
+
* preview of the build), Studio's view. Signed out (the gate's 401) is
|
|
17
|
+
* thrown like any other failure, for the index to say so: never Studio's view.
|
|
18
|
+
*/
|
|
15
19
|
export async function readHub(viewAs?: PersonKind): Promise<HubAnswer & { me: Me | null }> {
|
|
16
20
|
try {
|
|
17
21
|
const { person } = await call<{ person: Me | null }>('me');
|
package/shell/main.tsx
CHANGED
|
@@ -34,8 +34,18 @@ if (import.meta.env.DEV && !exporting && params.get('a11y') !== '0') {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// /<slug>/ is a prototype; /guide/<feature>/ is that feature's walkthrough.
|
|
37
|
-
// `
|
|
38
|
-
|
|
37
|
+
// `invite`, `api`, `_gate`, `_p`, `assets`, `guide`, `index.html` and `favicon.svg`
|
|
38
|
+
// belong to the hub (RESERVED in core/prototype.ts; new.ts refuses them).
|
|
39
|
+
// All of it below the build's base (vite/plugin.ts). Each `BASE_URL === '/'`
|
|
40
|
+
// test here and in Index.tsx and Guide.tsx is settled when Vite builds, so a
|
|
41
|
+
// hub built at `/` is byte for byte the one built before there was a base.
|
|
42
|
+
const [slug, sub] = (
|
|
43
|
+
import.meta.env.BASE_URL === '/'
|
|
44
|
+
? location.pathname
|
|
45
|
+
: location.pathname.slice(import.meta.env.BASE_URL.length - 1)
|
|
46
|
+
)
|
|
47
|
+
.split('/')
|
|
48
|
+
.filter(Boolean);
|
|
39
49
|
const Guide = lazy(() => import('./Guide'));
|
|
40
50
|
|
|
41
51
|
/**
|
|
@@ -83,7 +93,12 @@ if (slug === 'guide') {
|
|
|
83
93
|
pageEntry(slug),
|
|
84
94
|
exporting ? exportControls() : loadControls(slug),
|
|
85
95
|
]);
|
|
86
|
-
if (entry?.feature && guides.has(entry.feature))
|
|
96
|
+
if (entry?.feature && guides.has(entry.feature))
|
|
97
|
+
setGuide(
|
|
98
|
+
import.meta.env.BASE_URL === '/'
|
|
99
|
+
? guideHref(entry.feature)
|
|
100
|
+
: `${import.meta.env.BASE_URL}guide/${entry.feature}/`,
|
|
101
|
+
);
|
|
87
102
|
page = hidden ? (
|
|
88
103
|
<HiddenInClientView name={slug} />
|
|
89
104
|
) : (
|
package/shell/review/Review.tsx
CHANGED
|
@@ -14,7 +14,7 @@ import { can, viewOf } from '../../core/review/policy';
|
|
|
14
14
|
import { captureAnchor, currentUrl, openAnchor, pinPoint, resumeAnchor } from './anchor';
|
|
15
15
|
import { Bar } from './Bar';
|
|
16
16
|
import { Card } from './Card';
|
|
17
|
-
import { createReviewStore, type ReviewStore, useReviewState } from './client';
|
|
17
|
+
import { createReviewStore, ownScope, type ReviewStore, useReviewState } from './client';
|
|
18
18
|
import { Field } from './Field';
|
|
19
19
|
import { Launcher } from './Launcher';
|
|
20
20
|
import { People } from './People';
|
|
@@ -300,7 +300,7 @@ function ModeBar({
|
|
|
300
300
|
}}
|
|
301
301
|
resolved={v.resolved}
|
|
302
302
|
resolvedCount={roots.filter((c) => c.status === 'resolved').length}
|
|
303
|
-
canManagePeople={can(s.me, 'people')}
|
|
303
|
+
canManagePeople={can(s.me, ownScope(s.me), 'people')}
|
|
304
304
|
canFilter={lens.asStudio}
|
|
305
305
|
filter={v.filter}
|
|
306
306
|
filterNote={filterNote(v)}
|
|
@@ -11,7 +11,7 @@ import { type KeyboardEvent, useEffect, useState } from 'react';
|
|
|
11
11
|
import { type Audience, type Comment, KINDS, type Kind, LIMITS, threadLabel } from '../../core/review/model';
|
|
12
12
|
import { can } from '../../core/review/policy';
|
|
13
13
|
import { Action, Card } from './Card';
|
|
14
|
-
import { act, type Me, type ReviewStore } from './client';
|
|
14
|
+
import { act, type Me, ownScope, type ReviewStore } from './client';
|
|
15
15
|
import { Field, useTextBox } from './Field';
|
|
16
16
|
|
|
17
17
|
const KIND_LABEL: Record<Kind, string> = { bug: 'Bug', taste: 'Taste', copy: 'Copy' };
|
|
@@ -169,7 +169,7 @@ function Entry({
|
|
|
169
169
|
<div className="rv-msg-main">
|
|
170
170
|
<EntryHead
|
|
171
171
|
comment={comment}
|
|
172
|
-
canEdit={can(me, 'edit', root, comment) && !editing}
|
|
172
|
+
canEdit={can(me, ownScope(me), 'edit', root, comment) && !editing}
|
|
173
173
|
onEdit={() => setEditing(true)}
|
|
174
174
|
/>
|
|
175
175
|
{editing ? (
|
|
@@ -484,9 +484,9 @@ export function ThreadCard({
|
|
|
484
484
|
index={index}
|
|
485
485
|
total={total}
|
|
486
486
|
states={states}
|
|
487
|
-
canResolve={can(me, 'resolve', root)}
|
|
488
|
-
canTriage={can(me, 'triage', root)}
|
|
489
|
-
canDelete={can(me, 'delete', root)}
|
|
487
|
+
canResolve={can(me, ownScope(me), 'resolve', root)}
|
|
488
|
+
canTriage={can(me, ownScope(me), 'triage', root)}
|
|
489
|
+
canDelete={can(me, ownScope(me), 'delete', root)}
|
|
490
490
|
onStep={onStep}
|
|
491
491
|
onClose={onClose}
|
|
492
492
|
onShow={onShow}
|
package/shell/review/client.ts
CHANGED
|
@@ -5,9 +5,17 @@
|
|
|
5
5
|
// answer is merged in place, so a write never refetches the list. The list is
|
|
6
6
|
// what the server sent for this person: nothing here filters it.
|
|
7
7
|
import { useSyncExternalStore } from 'react';
|
|
8
|
-
import type { Access, Anchor, Audience, Comment, Person, PersonKind } from '../../core/review/model';
|
|
8
|
+
import type { Access, Anchor, Audience, Comment, Person, PersonKind, Scope } from '../../core/review/model';
|
|
9
|
+
import { afterFailure, signedOutState } from './view';
|
|
9
10
|
|
|
10
11
|
export type Me = Omit<Person, 'epoch'>;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The scope the page judges its own controls in: the person's own. The
|
|
15
|
+
* server answers nothing outside the real one, so this only decides which
|
|
16
|
+
* buttons show.
|
|
17
|
+
*/
|
|
18
|
+
export const ownScope = (me: Me | null): Scope => ({ client: me?.client ?? '' });
|
|
11
19
|
/** off: this site has no review store, so the UI stays out of the way. guest: the session ended since the page loaded. */
|
|
12
20
|
type Status = 'loading' | 'ready' | 'guest' | 'off';
|
|
13
21
|
|
|
@@ -36,7 +44,7 @@ class ApiError extends Error {
|
|
|
36
44
|
}
|
|
37
45
|
}
|
|
38
46
|
|
|
39
|
-
const API =
|
|
47
|
+
const API = `${import.meta.env.BASE_URL}api/review`;
|
|
40
48
|
|
|
41
49
|
/** For a click handler: the store shows every failure in the panel, so the handler has nothing left to do with one. */
|
|
42
50
|
export const act = (pending: Promise<unknown>) => void pending.catch(() => {});
|
|
@@ -79,8 +87,19 @@ export async function call<T>(
|
|
|
79
87
|
const isOff = (error: unknown) =>
|
|
80
88
|
error instanceof ApiError && !error.retry && (error.status === 503 || error.status === 404);
|
|
81
89
|
|
|
82
|
-
/**
|
|
83
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Signed out: a 401, whether the review API sent it in JSON or the gate in
|
|
92
|
+
* front of it sent its plain text. Read by status, never by body.
|
|
93
|
+
*/
|
|
94
|
+
export const signedOut = (error: unknown) => error instanceof ApiError && error.status === 401;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* No review API at all: none set up (`isOff`), or an answer that is not the
|
|
98
|
+
* API's (a static preview's page). The gate's text 401 is not one: it is a
|
|
99
|
+
* session that ended (`signedOut`).
|
|
100
|
+
*/
|
|
101
|
+
export const noApi = (error: unknown) =>
|
|
102
|
+
isOff(error) || (error instanceof ApiError && error.notJson && !signedOut(error));
|
|
84
103
|
|
|
85
104
|
export function createReviewStore(prototype: string) {
|
|
86
105
|
let state: State = { status: 'loading', me: null, comments: [], people: null, access: null, error: null };
|
|
@@ -109,16 +128,12 @@ export function createReviewStore(prototype: string) {
|
|
|
109
128
|
return p;
|
|
110
129
|
};
|
|
111
130
|
// Every action reports its failure in the store, and rethrows so the caller keeps the user's input.
|
|
131
|
+
// A 401 signs the panel out, as a load that meets one does (afterFailure).
|
|
112
132
|
const attempt = async <T>(run: () => Promise<T>): Promise<T> => {
|
|
113
133
|
try {
|
|
114
134
|
return await run();
|
|
115
135
|
} catch (error) {
|
|
116
|
-
set({
|
|
117
|
-
error:
|
|
118
|
-
error instanceof ApiError && error.problems.length
|
|
119
|
-
? error.problems.join('. ')
|
|
120
|
-
: String((error as Error).message),
|
|
121
|
-
});
|
|
136
|
+
set(afterFailure(error instanceof ApiError ? error : { message: String((error as Error).message) }));
|
|
122
137
|
throw error;
|
|
123
138
|
}
|
|
124
139
|
};
|
|
@@ -149,7 +164,9 @@ export function createReviewStore(prototype: string) {
|
|
|
149
164
|
if (n !== loads) return;
|
|
150
165
|
set({ status: 'ready', me: person, comments, error: null });
|
|
151
166
|
} catch (error) {
|
|
152
|
-
if (
|
|
167
|
+
if (n !== loads) return;
|
|
168
|
+
if (signedOut(error)) set(signedOutState());
|
|
169
|
+
else if (isOff(error)) set({ status: 'off' });
|
|
153
170
|
else set({ status: 'ready', error: String((error as Error).message) });
|
|
154
171
|
}
|
|
155
172
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import assert from 'node:assert/strict';
|
|
2
2
|
import { test } from 'node:test';
|
|
3
3
|
import {
|
|
4
|
+
afterFailure,
|
|
4
5
|
type Draft,
|
|
5
6
|
draftOf,
|
|
6
7
|
filtered,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
lensOf,
|
|
10
11
|
roundOf,
|
|
11
12
|
scopeOf,
|
|
13
|
+
signedOutState,
|
|
12
14
|
stepFrom,
|
|
13
15
|
stepTarget,
|
|
14
16
|
threadOf,
|
|
@@ -225,3 +227,20 @@ test('the bar names a narrowing filter, and says nothing with All or in Client v
|
|
|
225
227
|
);
|
|
226
228
|
assert.equal(filterNote(left), null);
|
|
227
229
|
});
|
|
230
|
+
|
|
231
|
+
test('an action that meets the end of the session signs the panel out, as a load does; any other failure is shown', () => {
|
|
232
|
+
// The gate's plain-text 401, which call() reads as an answer that is not JSON, and the API's own.
|
|
233
|
+
for (const message of ['The review API did not answer with JSON (401).', 'Sign in first.'])
|
|
234
|
+
assert.deepEqual(afterFailure({ status: 401, message, problems: [] }), signedOutState());
|
|
235
|
+
assert.equal(signedOutState().status, 'guest');
|
|
236
|
+
assert.deepEqual(
|
|
237
|
+
afterFailure({ status: 400, message: 'Bad request.', problems: ['body: empty', 'too long'] }),
|
|
238
|
+
{
|
|
239
|
+
error: 'body: empty. too long',
|
|
240
|
+
},
|
|
241
|
+
);
|
|
242
|
+
assert.deepEqual(afterFailure({ status: 403, message: 'Not yours.', problems: [] }), {
|
|
243
|
+
error: 'Not yours.',
|
|
244
|
+
});
|
|
245
|
+
assert.deepEqual(afterFailure({ message: 'Failed to fetch' }), { error: 'Failed to fetch' });
|
|
246
|
+
});
|
package/shell/review/view.ts
CHANGED
|
@@ -145,3 +145,28 @@ export const scopeOf = (card: Card | null): Scope => {
|
|
|
145
145
|
const d = draftOf(card);
|
|
146
146
|
return d && !d.target ? 'page' : 'pin';
|
|
147
147
|
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The store once the session has ended: signed out, with nothing of the
|
|
151
|
+
* person's left in it. A load and an action that meet a 401 both set it, so
|
|
152
|
+
* the panel shows the same signed-out card whichever found out first.
|
|
153
|
+
*/
|
|
154
|
+
export const signedOutState = () => ({
|
|
155
|
+
status: 'guest' as const,
|
|
156
|
+
me: null,
|
|
157
|
+
comments: [] as never[],
|
|
158
|
+
people: null,
|
|
159
|
+
error: null,
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
/** A failed call, as the store reads it. `status` is absent when no answer came back at all. */
|
|
163
|
+
export type Failure = { status?: number; message: string; problems?: string[] };
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* What an action's failure leaves in the store. A 401 is the session that
|
|
167
|
+
* ended, whether the review API sent it in JSON or the gate in front of it
|
|
168
|
+
* sent its plain text: read by status, never by body. Anything else is the
|
|
169
|
+
* error the panel shows, its problems when the server named them.
|
|
170
|
+
*/
|
|
171
|
+
export const afterFailure = (f: Failure) =>
|
|
172
|
+
f.status === 401 ? signedOutState() : { error: f.problems?.length ? f.problems.join('. ') : f.message };
|
package/shell/shell.css
CHANGED
|
@@ -112,6 +112,10 @@
|
|
|
112
112
|
.index-empty { display: flex; flex-direction: column; gap: 4px; min-height: 56px; }
|
|
113
113
|
.index-empty h2 { font-size: 14px; font-weight: 600; }
|
|
114
114
|
.index-empty p { color: var(--text-tertiary); max-width: 52ch; text-wrap: pretty; }
|
|
115
|
+
.index-signed-out { align-items: flex-start; }
|
|
116
|
+
.index-signed-out .btn { position: relative; margin-top: 12px; }
|
|
117
|
+
/* The 38px button reaches 44px to the touch, as on the client's hub; nothing sits within 3px of it. */
|
|
118
|
+
.index-signed-out .btn::before { content: ''; position: absolute; inset: -3px 0; }
|
|
115
119
|
|
|
116
120
|
.index-foot { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border-secondary); color: var(--text-primary); }
|
|
117
121
|
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { Icon } from '@kit/Icon';
|
|
2
|
+
import { Button } from '@kit/ui';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { call, type Me } from '../review/client';
|
|
5
|
+
|
|
6
|
+
/** What the hub shows of a project: the server sends no more. */
|
|
7
|
+
type Listed = { slug: string; name: string };
|
|
8
|
+
|
|
9
|
+
type Loaded =
|
|
10
|
+
| { status: 'loading' }
|
|
11
|
+
| { status: 'error'; signedOut: boolean }
|
|
12
|
+
| { status: 'ready'; me: Me | null; projects: Listed[] };
|
|
13
|
+
|
|
14
|
+
/** Who is signed in and this host's projects. */
|
|
15
|
+
function useProjects(): Loaded {
|
|
16
|
+
const [loaded, setLoaded] = useState<Loaded>({ status: 'loading' });
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
let current = true;
|
|
19
|
+
Promise.all([call<{ person: Me | null }>('me'), call<{ projects: Listed[] }>('projects')]).then(
|
|
20
|
+
([{ person }, { projects }]) => current && setLoaded({ status: 'ready', me: person, projects }),
|
|
21
|
+
// By status, not body: the review API's 401 is JSON, the gate's in front of it is text.
|
|
22
|
+
(error: { status?: number }) =>
|
|
23
|
+
current && setLoaded({ status: 'error', signedOut: error.status === 401 }),
|
|
24
|
+
);
|
|
25
|
+
return () => {
|
|
26
|
+
current = false;
|
|
27
|
+
};
|
|
28
|
+
}, []);
|
|
29
|
+
return loaded;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function ClientHub() {
|
|
33
|
+
const loaded = useProjects();
|
|
34
|
+
return (
|
|
35
|
+
<main className="hub">
|
|
36
|
+
<header className="hub-head">
|
|
37
|
+
<h1>Projects</h1>
|
|
38
|
+
<p className="hub-voice">What the studio has shared here, each in its own hub.</p>
|
|
39
|
+
</header>
|
|
40
|
+
<Body loaded={loaded} />
|
|
41
|
+
{loaded.status === 'ready' && loaded.me ? (
|
|
42
|
+
<footer className="hub-foot">
|
|
43
|
+
Signed in as {loaded.me.name}, {loaded.me.team}
|
|
44
|
+
</footer>
|
|
45
|
+
) : null}
|
|
46
|
+
</main>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function Body({ loaded }: { loaded: Loaded }) {
|
|
51
|
+
if (loaded.status === 'loading')
|
|
52
|
+
return (
|
|
53
|
+
<ul className="hub-list" aria-busy="true" aria-label="Loading projects">
|
|
54
|
+
<li className="hub-skeleton" />
|
|
55
|
+
<li className="hub-skeleton" />
|
|
56
|
+
</ul>
|
|
57
|
+
);
|
|
58
|
+
if (loaded.status === 'error') return <Failed signedOut={loaded.signedOut} />;
|
|
59
|
+
if (!loaded.projects.length)
|
|
60
|
+
return (
|
|
61
|
+
<section className="hub-empty">
|
|
62
|
+
<h2>Nothing shared yet</h2>
|
|
63
|
+
<p>When the studio shares a project with you, it shows here.</p>
|
|
64
|
+
</section>
|
|
65
|
+
);
|
|
66
|
+
return (
|
|
67
|
+
<ul className="hub-list">
|
|
68
|
+
{loaded.projects.map((p) => (
|
|
69
|
+
<li key={p.slug}>
|
|
70
|
+
<a className="hub-row" href={`/${p.slug}/`}>
|
|
71
|
+
<span className="hub-name">{p.name}</span>
|
|
72
|
+
<Icon name="arrow-right" size={16} className="hub-arrow" />
|
|
73
|
+
</a>
|
|
74
|
+
</li>
|
|
75
|
+
))}
|
|
76
|
+
</ul>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** A failure in plain words: a reload brings the sign-in page back, or tries the list again. */
|
|
81
|
+
function Failed({ signedOut }: { signedOut: boolean }) {
|
|
82
|
+
return (
|
|
83
|
+
<section className="hub-empty" role="alert">
|
|
84
|
+
<h2>{signedOut ? 'You are signed out' : 'The projects did not load'}</h2>
|
|
85
|
+
<p>
|
|
86
|
+
{signedOut
|
|
87
|
+
? 'Reload the page to see how to sign in again.'
|
|
88
|
+
: 'Try again in a minute. If it keeps happening, tell the studio.'}
|
|
89
|
+
</p>
|
|
90
|
+
<Button
|
|
91
|
+
kind="secondary"
|
|
92
|
+
size="sm"
|
|
93
|
+
label={signedOut ? 'Reload' : 'Try again'}
|
|
94
|
+
onClick={() => location.reload()}
|
|
95
|
+
/>
|
|
96
|
+
</section>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* The client hub: one column of project rows in the index's measure and
|
|
2
|
+
rhythm (shell.css, The index), on the hub's neutral system look. A studio
|
|
3
|
+
site has no tokens.css, so the few motion values the hub and kit/ui read
|
|
4
|
+
are set here, the same as the template's. */
|
|
5
|
+
:root {
|
|
6
|
+
--ease-out: cubic-bezier(0.23, 1, 0.32, 1);
|
|
7
|
+
--ease-in: cubic-bezier(0.4, 0, 1, 1);
|
|
8
|
+
--ease-press: cubic-bezier(0.33, 1, 0.68, 1);
|
|
9
|
+
--ease-hover: cubic-bezier(0.25, 0.46, 0.45, 0.94);
|
|
10
|
+
--dur-press: 160ms;
|
|
11
|
+
--dur-press-in: 90ms;
|
|
12
|
+
--dur-press-out: 160ms;
|
|
13
|
+
--dur-hover: 120ms;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
body { background: var(--bg-primary); }
|
|
17
|
+
|
|
18
|
+
.hub { width: min(744px, 100% - 8px); margin: 0 auto; padding: 96px 0 128px; display: flex; flex-direction: column; }
|
|
19
|
+
.hub-head, .hub-empty, .hub-foot { padding-inline: 12px; }
|
|
20
|
+
|
|
21
|
+
.hub-head { display: flex; flex-direction: column; gap: 8px; margin-bottom: 40px; }
|
|
22
|
+
.hub-head h1 { font-size: 18px; line-height: 28px; font-weight: 600; text-wrap: balance; }
|
|
23
|
+
.hub-voice { font: 400 18px/28px var(--font-voice); letter-spacing: -0.01em; color: var(--text-secondary); max-width: 44ch; text-wrap: pretty; }
|
|
24
|
+
|
|
25
|
+
.hub-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
|
|
26
|
+
.hub-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 56px; padding: 12px; border-radius: var(--radius-md); color: var(--text-primary); text-decoration: none; transition: background-color var(--dur-hover) var(--ease-hover), transform var(--dur-press-out) var(--ease-press); }
|
|
27
|
+
.hub-name { min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
|
|
28
|
+
.hub-arrow { color: var(--fg-quaternary); transition: color var(--dur-hover) var(--ease-hover), translate var(--dur-hover) var(--ease-out); }
|
|
29
|
+
@media (hover: hover) and (pointer: fine) {
|
|
30
|
+
.hub-row:hover { background: var(--bg-primary_hover); }
|
|
31
|
+
.hub-row:hover .hub-arrow { color: var(--fg-secondary); translate: 2px 0; }
|
|
32
|
+
}
|
|
33
|
+
.hub-row:active { transform: scale(0.97); transition-duration: var(--dur-hover), var(--dur-press-in); }
|
|
34
|
+
|
|
35
|
+
/* Two rows' worth while the list loads, so the page keeps its shape. Tertiary, so it reads on the page in both modes. */
|
|
36
|
+
.hub-skeleton { height: 56px; border-radius: var(--radius-md); background: var(--bg-tertiary); }
|
|
37
|
+
|
|
38
|
+
.hub-empty { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-height: 56px; }
|
|
39
|
+
.hub-empty h2 { font-size: 14px; line-height: 20px; font-weight: 600; }
|
|
40
|
+
.hub-empty p { color: var(--text-tertiary); max-width: 52ch; text-wrap: pretty; }
|
|
41
|
+
.hub-empty .btn { position: relative; margin-top: 12px; }
|
|
42
|
+
/* The 38px button reaches 44px to the touch; nothing sits within 3px of it. */
|
|
43
|
+
.hub-empty .btn::before { content: ''; position: absolute; inset: -3px 0; }
|
|
44
|
+
|
|
45
|
+
.hub-foot { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--border-secondary); color: var(--text-tertiary); }
|
|
46
|
+
|
|
47
|
+
:root[data-motion="reduce"] .hub-row:active { transform: none; }
|
|
48
|
+
:root[data-motion="reduce"] .hub-row:hover .hub-arrow { translate: none; }
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en" class="sys">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
|
6
|
+
<meta name="robots" content="noindex, nofollow" />
|
|
7
|
+
<title>Projects</title>
|
|
8
|
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
9
|
+
</head>
|
|
10
|
+
<body>
|
|
11
|
+
<div id="root"></div>
|
|
12
|
+
<script type="module" src="./main.tsx"></script>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// A studio site's client hub, at the root of a client's host: every project
|
|
2
|
+
// of that client, each a link to its own hub at /<project>/. Built by
|
|
3
|
+
// `studioConfig` (vite/plugin.ts). It wears the hub's neutral system look,
|
|
4
|
+
// and lists only what the server sends for this host, which is one client's.
|
|
5
|
+
import '@kit/base.css';
|
|
6
|
+
import '@kit/prefs';
|
|
7
|
+
import '../system.css';
|
|
8
|
+
import './hub.css';
|
|
9
|
+
import { StrictMode } from 'react';
|
|
10
|
+
import { createRoot } from 'react-dom/client';
|
|
11
|
+
import { ClientHub } from './ClientHub';
|
|
12
|
+
|
|
13
|
+
createRoot(document.getElementById('root')!).render(
|
|
14
|
+
<StrictMode>
|
|
15
|
+
<ClientHub />
|
|
16
|
+
</StrictMode>,
|
|
17
|
+
);
|