rvlib-shipkit 2.9.0 → 2.10.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.
@@ -0,0 +1,124 @@
1
+ // a view's image at the size the page draws it (wiki build/shipkit/review.md, Previews): a webp made once per media
2
+ // file, kept in the repo's cache (`.shipkit/cache/review-previews/<id>/<name>.<size>.webp`, local, never in the store),
3
+ // made again only when its source is newer. The full file is fetched only on zoom
4
+ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync } from 'node:fs'
5
+ import { dirname, join } from 'node:path'
6
+ import { LAYOUT } from '../core/layout.ts'
7
+ import { firstView, isGallery, isPair, thumbFileOf, type Item, type ReviewItem } from './model.ts'
8
+ import { probe, stillAt } from './media.ts'
9
+ import { imageFile } from './store.ts'
10
+
11
+ /** `thumb` a list row's picture, `fit` a view in the card column: the widest each is drawn, at 2x */
12
+ export const PREVIEW_W = { thumb: 480, fit: 1600 } as const
13
+ export type PreviewSize = keyof typeof PREVIEW_W
14
+ export const isPreviewSize = (s: string): s is PreviewSize => s in PREVIEW_W
15
+
16
+ const IMAGE = /\.(png|jpe?g|webp)$/i
17
+
18
+ const JOBS = 3
19
+ let running = 0
20
+ const waiting: (() => void)[] = []
21
+ const making = new Map<string, Promise<string | null>>()
22
+
23
+ async function slot<T>(work: () => Promise<T>): Promise<T> {
24
+ if (running >= JOBS) await new Promise<void>((go) => waiting.push(go))
25
+ running++
26
+ try {
27
+ return await work()
28
+ } finally {
29
+ running--
30
+ waiting.shift()?.()
31
+ }
32
+ }
33
+
34
+ /** the preview folder of a store: `<repo>/.shipkit/cache/review-previews`, the store being `<repo>/.shipkit/review` */
35
+ export const previewDir = (dir: string): string => join(dirname(dirname(dir)), LAYOUT.cache, 'review-previews')
36
+
37
+ /** the preview of an item's image at a size, made on the first ask; null when the name is no image of the item or
38
+ * the image does not read */
39
+ export function previewFile(dir: string, id: string, name: string, size: PreviewSize): Promise<string | null> {
40
+ const src = imageFile(dir, id, name)
41
+ if (!src || !IMAGE.test(name)) return Promise.resolve(null)
42
+ // a poster's preview may come from a lit frame of its clip: its own name, so the black ones made before are not reused
43
+ const out = join(previewDir(dir), id, `${name}.${size}${POSTER.test(name) ? '.lit' : ''}.webp`)
44
+ if (existsSync(out) && statSync(out).mtimeMs >= statSync(src).mtimeMs) return Promise.resolve(out)
45
+ const pending = making.get(out)
46
+ if (pending) return pending
47
+ const job = slot(async () => {
48
+ mkdirSync(dirname(out), { recursive: true })
49
+ const tmp = `${out}.${process.pid}.tmp`
50
+ try {
51
+ const { default: sharp } = await import('sharp')
52
+ const still = POSTER.test(name) ? await litStill(dir, id, name, src, out) : src
53
+ await sharp(still === src ? src : readFileSync(still))
54
+ .resize({ width: PREVIEW_W[size], withoutEnlargement: true })
55
+ .webp({ quality: size === 'thumb' ? 75 : 82 })
56
+ .toFile(tmp)
57
+ } catch (e) {
58
+ console.error(`FAIL: review preview ${size} of ${id}/${name}: ${(e as Error).message}`)
59
+ return null
60
+ }
61
+ renameSync(tmp, out)
62
+ rmSync(`${out}.still.png`, { force: true })
63
+ return out
64
+ }).finally(() => making.delete(out))
65
+ making.set(out, job)
66
+ return job
67
+ }
68
+
69
+
70
+ const POSTER = /^(v\d+-)?poster\.png$/
71
+ /** a picture whose brightest channel averages under this is black: a trailer's first frame fades in from black */
72
+ const BLACK = 12
73
+ /** where in a clip a poster is looked for when its first frame is black, a share of its length */
74
+ const TRIES = [0.1, 0.25, 0.5]
75
+
76
+ const isBlack = async (png: string): Promise<boolean> => {
77
+ const { default: sharp } = await import('sharp')
78
+ // read as bytes: libvips caches by file name, and the still is written again at the same path
79
+ const st = await sharp(readFileSync(png)).stats()
80
+ return Math.max(...st.channels.slice(0, 3).map((c) => c.mean)) < BLACK
81
+ }
82
+
83
+ /** a clip's poster for its preview: the poster itself, or when it is black (a trailer opens on black) the first frame
84
+ * further in that is not; the clip's file is the poster's view's video, or its after on a pair */
85
+ async function litStill(dir: string, id: string, name: string, poster: string, out: string): Promise<string> {
86
+ if (!(await isBlack(poster))) return poster
87
+ const prefix = name.slice(0, name.length - 'poster.png'.length)
88
+ const clip = readdirSync(join(dir, id)).find((f) => new RegExp(`^${prefix}(video|after)\\.(mp4|webm)$`).test(f))
89
+ if (!clip) return poster
90
+ const video = join(dir, id, clip)
91
+ const still = `${out}.still.png`
92
+ try {
93
+ const { duration } = probe(video)
94
+ for (const at of TRIES) {
95
+ await stillAt(video, duration * at, still)
96
+ if (!(await isBlack(still))) return still
97
+ }
98
+ } catch (e) {
99
+ console.error(`FAIL: review preview of ${id}/${name}: no lit frame: ${(e as Error).message}`)
100
+ }
101
+ return poster
102
+ }
103
+
104
+ /** every image a card draws: each view's image or pair, a clip's poster, a sound's waveforms, a gallery's tiles */
105
+ export function imagesOf(i: Item): string[] {
106
+ const names = i.views.flatMap((v) => {
107
+ if (isGallery(v)) return v.gallery.map((g) => g.file)
108
+ const f = v.files
109
+ return [...('image' in f ? [f.image] : isPair(f) ? [f.before, f.after] : []), ...(v.clip ? [v.clip.poster] : []), ...(v.audio ? [v.audio.wave, ...(v.audio.waveBefore ? [v.audio.waveBefore] : [])] : [])]
110
+ })
111
+ return [...new Set(names)].filter((n) => IMAGE.test(n))
112
+ }
113
+
114
+ /** the previews of these cards made ahead, so each opens on them: its list thumb, every image at the fit size. Already
115
+ * made ones cost a stat */
116
+ export async function warmPreviews(dir: string, cards: readonly ReviewItem[]): Promise<void> {
117
+ await Promise.all(
118
+ cards.flatMap((x) => {
119
+ const first = firstView(x.item)
120
+ const thumb = first ? thumbFileOf(first) : ''
121
+ return [...(IMAGE.test(thumb) ? [previewFile(dir, x.item.id, thumb, 'thumb')] : []), ...imagesOf(x.item).map((n) => previewFile(dir, x.item.id, n, 'fit'))]
122
+ }),
123
+ )
124
+ }
@@ -1,17 +1,20 @@
1
1
  // the hub's review routes (wiki build/shipkit/review.md, The hub): the store's list, an item's images and clips, the
2
2
  // owner's verdicts, replies and read marks appended to its thread. The trailer view's routes: trailer-routes.ts. Paths are
3
3
  // relative to the repo hub's base. null: not a path of these
4
- import { existsSync, mkdirSync, mkdtempSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs'
4
+ import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
5
5
  import { tmpdir } from 'node:os'
6
6
  import { dirname, extname, join } from 'node:path'
7
7
  import { isAnimFormat, isAnimLabels, isAnimMode, pairAnimation } from './anim.ts'
8
8
  import { startAuto } from './auto.ts'
9
9
  import { bad, KEEP, NO_STORE, ranged, TYPES } from './http.ts'
10
- import type { Rect, Subject } from './model.ts'
10
+ import { viewFilesOf, type Rect, type ReviewItem, type Subject } from './model.ts'
11
11
  import { pasteHosts } from './paste.ts'
12
12
  import { openReview, partFile, viewOfItem } from './project.ts'
13
+ import { isPreviewSize, previewFile, warmPreviews } from './previews.ts'
13
14
  import { roleOf } from './role.ts'
14
- import { addMessage, imageFile, markRead, raiseItem, rateSubject, readAllCached, readItem, specOf, storeDir, storeStamp, threadImage, writeVerdict } from './store.ts'
15
+ import { addMessage, imageFile, itemOfRef, markRead, raiseItem, rateSubject, readAllCached, readItem, specOf, storeDir, storeStamp, threadImage, writeVerdict } from './store.ts'
16
+ import { boardOf, pageOf, queryOf, threadIndex, threadOfId, threadView, type ThreadIndex } from './cells.ts'
17
+ import { membersOf, threadsOf, type Thread } from './threads.ts'
15
18
  import { trailerRoutes } from './trailer-routes.ts'
16
19
  import { specData, type ReviewUnit } from './unit.ts'
17
20
  import { liveWatchers } from './watchers.ts'
@@ -53,50 +56,53 @@ function dataUrlFile(url: unknown): { file: string; done(): void } | null {
53
56
 
54
57
  const obj = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v)
55
58
 
56
- // ── the list's thumbnails: a 480 px webp of an item's image, cached beside the items (readAll skips dot names) ──
59
+ let listing: { dir: string; tag: string; body: string; zipped: Uint8Array<ArrayBuffer> | null } | null = null
57
60
 
58
- const THUMB_W = 480
59
- const THUMB_JOBS = 3
60
- let running = 0
61
- const waiting: (() => void)[] = []
62
- const making = new Map<string, Promise<string | null>>()
61
+ // ── the paged list and one thread: an index over the store's threads, built again when a file moved or a minute
62
+ // passed (a claim goes stale on the clock); its build number is every answer's ETag ──
63
63
 
64
- async function slot<T>(work: () => Promise<T>): Promise<T> {
65
- if (running >= THUMB_JOBS) await new Promise<void>((go) => waiting.push(go))
66
- running++
67
- try {
68
- return await work()
69
- } finally {
70
- running--
71
- waiting.shift()?.()
72
- }
64
+ const INDEX_MS = 60_000
65
+ const BOOT = Date.now().toString(36)
66
+ let builds = 0
67
+ interface Indexed {
68
+ stamp: string
69
+ at: number
70
+ tag: string
71
+ ix: ThreadIndex
72
+ threads: Thread[]
73
+ broken: { id: string; error: string }[]
73
74
  }
75
+ /** one index per store: the daemon serves every house repo, and two open pages must not rebuild each other's */
76
+ const threadIx = new Map<string, Indexed>()
74
77
 
75
- export function thumbFile(dir: string, id: string, name: string): Promise<string | null> {
76
- const src = imageFile(dir, id, name)
77
- if (!src || !/\.(png|jpe?g|webp)$/.test(name)) return Promise.resolve(null)
78
- const out = join(dir, '.thumbs', id, `${name}.webp`)
79
- if (existsSync(out) && statSync(out).mtimeMs >= statSync(src).mtimeMs) return Promise.resolve(out)
80
- const pending = making.get(out)
81
- if (pending) return pending
82
- const job = slot(async () => {
83
- mkdirSync(join(dir, '.thumbs', id), { recursive: true })
84
- const tmp = `${out}.${process.pid}.tmp`
85
- try {
86
- const { default: sharp } = await import('sharp')
87
- await sharp(src).resize({ width: THUMB_W, withoutEnlargement: true }).webp({ quality: 75 }).toFile(tmp)
88
- } catch (e) {
89
- console.error(`FAIL: review thumbnail of ${id}/${name}: ${(e as Error).message}`)
90
- return null
91
- }
92
- renameSync(tmp, out)
93
- return out
94
- }).finally(() => making.delete(out))
95
- making.set(out, job)
96
- return job
78
+ function indexOf(dir: string): Indexed {
79
+ const stamp = storeStamp(dir)
80
+ const held = threadIx.get(dir)
81
+ if (held && held.stamp === stamp && Date.now() - held.at < INDEX_MS) return held
82
+ const all = readAllCached(dir)
83
+ const ix = threadIndex(all.items)
84
+ const made: Indexed = { stamp, at: Date.now(), tag: `"${BOOT}.${++builds}"`, ix, threads: threadsOf(all.items), broken: all.broken }
85
+ threadIx.set(dir, made)
86
+ // the cards that need someone open on their previews: made in the background, one stat each once made
87
+ void warmPreviews(
88
+ dir,
89
+ ix.entries.filter((e) => e.row.active).map((e) => e.t.head),
90
+ )
91
+ return made
97
92
  }
98
93
 
99
- let listing: { dir: string; tag: string; body: string; zipped: Uint8Array<ArrayBuffer> | null } | null = null
94
+ /** the media files the thread's views name that the store no longer holds (a clip deleted to free the disk) */
95
+ const missingOf = (dir: string, members: readonly ReviewItem[]): string[] =>
96
+ members.flatMap((x) => viewFilesOf(x.item).flatMap((n) => (existsSync(join(dir, x.item.id, n)) ? [] : [`${x.item.id}/${n}`])))
97
+
98
+ /** a json answer with its ETag, 304 when the page holds it; gzipped when the page takes it */
99
+ function tagged(req: Request, tag: string, body: () => unknown): Response {
100
+ const headers = { 'Content-Type': 'application/json', ETag: tag, 'Cache-Control': 'no-cache', Vary: 'Accept-Encoding' }
101
+ if (req.headers.get('If-None-Match') === tag) return new Response(null, { status: 304, headers: { ETag: tag } })
102
+ const text = JSON.stringify(body())
103
+ if (text.length < 4096 || !/\bgzip\b/.test(req.headers.get('Accept-Encoding') ?? '')) return new Response(text, { headers })
104
+ return new Response(Bun.gzipSync(new TextEncoder().encode(text)), { headers: { ...headers, 'Content-Encoding': 'gzip' } })
105
+ }
100
106
 
101
107
  async function reviewRoute(req: Request, path: string, dir: string, unit: ReviewUnit | null): Promise<Response | null> {
102
108
  if (path === '/api/review' && req.method === 'GET') {
@@ -109,6 +115,29 @@ async function reviewRoute(req: Request, path: string, dir: string, unit: Review
109
115
  listing.zipped ??= Bun.gzipSync(new TextEncoder().encode(listing.body))
110
116
  return new Response(listing.zipped, { headers: { ...headers, 'Content-Encoding': 'gzip' } })
111
117
  }
118
+ if (path === '/api/review/threads' && req.method === 'GET') {
119
+ const x = indexOf(dir)
120
+ const q = new URL(req.url).searchParams
121
+ return tagged(req, x.tag, () => pageOf(x.ix, queryOf(q), x.broken))
122
+ }
123
+ const one = /^\/api\/review\/threads\/([^/]+)$/.exec(path)
124
+ if (one && req.method === 'GET') {
125
+ const x = indexOf(dir)
126
+ const ref = decodeURIComponent(one[1] ?? '')
127
+ let id = ref
128
+ try {
129
+ id = itemOfRef(dir, ref)?.item.id ?? ref
130
+ } catch (e) {
131
+ return bad(e)
132
+ }
133
+ const t = threadOfId(id, x.threads)
134
+ if (!t) return bad(`no item ${ref}`, 404)
135
+ return tagged(req, x.tag, () => ({ ...threadView(t, readAllCached(dir).items, x.threads, id), missing: missingOf(dir, membersOf(t)) }))
136
+ }
137
+ if (path === '/api/review/board' && req.method === 'GET') {
138
+ const x = indexOf(dir)
139
+ return tagged(req, x.tag, () => ({ role: roleOf(dir), rows: boardOf(readAllCached(dir).items) }))
140
+ }
112
141
  if (path === '/api/review/watchers' && req.method === 'GET') return Response.json(liveWatchers(dir), { headers: NO_STORE })
113
142
  // the unit's words, the dispatcher's holder: what the page draws the list's filters, labels and board with
114
143
  if (path === '/api/review/spec' && req.method === 'GET') {
@@ -164,9 +193,12 @@ async function reviewRoute(req: Request, path: string, dir: string, unit: Review
164
193
  const f = threadImage(dir, t[1] ?? '', t[2] ?? '')
165
194
  return f ? new Response(Bun.file(f), { headers: { 'Content-Type': TYPES[extname(f)] ?? 'application/octet-stream', ...KEEP } }) : bad('no such image', 404)
166
195
  }
167
- const th = /^\/api\/review\/([^/]+)\/thumb\/([^/]+)$/.exec(path)
168
- if (th && req.method === 'GET') {
169
- const f = await thumbFile(dir, th[1] ?? '', th[2] ?? '')
196
+ // a view's image at the size the page draws it; `thumb/<name>` is the preview's thumb size
197
+ const pv = /^\/api\/review\/([^/]+)\/(?:preview\/([^/]+)|thumb)\/([^/]+)$/.exec(path)
198
+ if (pv && req.method === 'GET') {
199
+ const size = pv[2] ?? 'thumb'
200
+ if (!isPreviewSize(size)) return bad(`preview size ${size}: thumb or fit`, 404)
201
+ const f = await previewFile(dir, pv[1] ?? '', pv[3] ?? '', size)
170
202
  return f ? new Response(Bun.file(f), { headers: { 'Content-Type': 'image/webp', ...KEEP } }) : bad('no such image', 404)
171
203
  }
172
204
  const m = /^\/api\/review\/([^/]+)\/([^/]+)$/.exec(path)
@@ -179,7 +211,12 @@ async function reviewRoute(req: Request, path: string, dir: string, unit: Review
179
211
  return r.ok ? Response.json(r.message, { headers: NO_STORE }) : Response.json({ error: r.errors.join('\n'), errors: r.errors }, { status: 400, headers: NO_STORE })
180
212
  }
181
213
  if (name === 'reply') return Response.json(addMessage(dir, id, 'owner', ((await req.json()) as { text?: unknown }).text), { headers: NO_STORE })
182
- if (name === 'read') return Response.json({ read: markRead(dir, id, 'owner') }, { headers: NO_STORE })
214
+ if (name === 'read') {
215
+ // the page names the words it drew: a word that came after them stays unread
216
+ const b = (await req.json().catch(() => ({}))) as { of?: unknown }
217
+ const of = Array.isArray(b.of) ? b.of.filter((m): m is string => typeof m === 'string') : undefined
218
+ return Response.json({ read: markRead(dir, id, 'owner', 'owner', new Date(), of) }, { headers: NO_STORE })
219
+ }
183
220
  // the card's folder, or one of its files, shown in the Finder: only names the store's own checks accept
184
221
  if (name === 'reveal') {
185
222
  const b = (await req.json().catch(() => ({}))) as { file?: unknown }
@@ -481,11 +481,12 @@ export function addMessage(dir: string, id: string, who: string, text: unknown,
481
481
  return appendMessage(dir, id, { who, text: t.text }, { ...(image !== undefined ? { image } : {}), now })
482
482
  }
483
483
 
484
- /** `party` read what the other party wrote on an item: one `seen` message naming them; how many it read */
485
- export function markRead(dir: string, id: string, party: Party, who: string = party === 'owner' ? 'owner' : agentName(), now = new Date()): number {
484
+ /** `party` read what the other party wrote on an item: one `seen` message naming them; how many it read. `only`: the
485
+ * messages a page drew, so a word that came after it is never marked read */
486
+ export function markRead(dir: string, id: string, party: Party, who: string = party === 'owner' ? 'owner' : agentName(), now = new Date(), only?: readonly string[]): number {
486
487
  const x = ID_RE.test(id) ? readItem(dir, id) : null
487
488
  if (!x) return 0
488
- const of = toAcknowledge(x, party)
489
+ const of = toAcknowledge(x, party).filter((m) => only === undefined || only.includes(m))
489
490
  if (of.length > 0) appendMessage(dir, id, { who, op: 'seen', of }, { now })
490
491
  return of.length
491
492
  }
@@ -930,9 +931,9 @@ function watchOf(dir: string): Watched | null {
930
931
  if (watched.has(key)) return watched.get(key) ?? null
931
932
  const w: Watched = { moved: 0, dirty: new Set(), held: null, all: null }
932
933
  try {
933
- // a thumbnail or an item's lock is no change of the list
934
+ // an item's lock is no change of the list
934
935
  const watcher = watch(key, { recursive: true }, (_, name) => {
935
- if (name && (name.startsWith('.thumbs') || name.endsWith('.lock'))) return
936
+ if (name?.endsWith('.lock')) return
936
937
  w.moved++
937
938
  if (name) w.dirty.add(name.split('/')[0] ?? '')
938
939
  else w.held = null
@@ -1,11 +1,11 @@
1
- // what the repo's review unit says of the open item, drawn from DATA the hub computed (review/project.ts viewOfItem): its
1
+ // what the repo's review unit says of one version, drawn from DATA the hub computed (review/project.ts viewOfItem): its
2
2
  // kind's facts, links, a text or its change as a diff, its parts (a card each: logo, media beside the text, its change),
3
3
  // and « live », the kind's url in a frame, off until he opens it; and a pair's animation to download. The page never
4
- // runs the repo's code
4
+ // runs the repo's code, and asks for a version's data only once its cell shows
5
5
  import { makeAutoObservable, runInAction } from 'mobx'
6
6
  import { observer } from 'mobx-react-lite'
7
7
  import { useEffect } from 'react'
8
- import { isGallery, isPair, viewName, type ReviewItem } from '../../../review/model.ts'
8
+ import { isGallery, isPair, viewName, type Item } from '../../../review/model.ts'
9
9
  import type { PartData } from '../../../review/project.ts'
10
10
  import type { Fact, Link, PartTone, ViewText } from '../../../review/unit.ts'
11
11
 
@@ -39,19 +39,19 @@ export class KindViewSt {
39
39
  makeAutoObservable<this, 'st'>(this, { st: false })
40
40
  }
41
41
 
42
- /** the view of item `x`, read when its stamp (its last message) moved */
43
- read(x: ReviewItem): void {
44
- const key = `${x.item.id}@${x.thread.at(-1)?.id ?? ''}`
42
+ /** the view of item `id`, read again when its stamp (its last message) moved */
43
+ read(id: string, stamp: string): void {
44
+ const key = `${id}@${stamp}`
45
45
  if (this.views.has(key)) return
46
46
  this.views.set(key, { facts: [], links: [], live: null, text: null, parts: [] })
47
- void fetch(this.st.fileUrl(x.item.id, 'view'))
47
+ void fetch(this.st.fileUrl(id, 'view'))
48
48
  .then(async (r) => (r.ok ? ((await r.json()) as KindData) : { error: ((await r.json().catch(() => ({}))) as { error?: string }).error ?? `HTTP ${r.status}` }))
49
49
  .catch((e: Error) => ({ error: e.message }))
50
50
  .then((v) => runInAction(() => this.views.set(key, v)))
51
51
  }
52
52
 
53
- of(x: ReviewItem): KindData | { error: string } | undefined {
54
- return this.views.get(`${x.item.id}@${x.thread.at(-1)?.id ?? ''}`)
53
+ of(id: string, stamp: string): KindData | { error: string } | undefined {
54
+ return this.views.get(`${id}@${stamp}`)
55
55
  }
56
56
 
57
57
  toggleLive(): void {
@@ -72,9 +72,9 @@ export class KindViewSt {
72
72
  }
73
73
  }
74
74
 
75
- animUrl(x: ReviewItem, view: number): string {
75
+ animUrl(id: string, view: number): string {
76
76
  const a = this.anim
77
- return `${this.st.fileUrl(x.item.id, 'anim')}?view=${view}&mode=${a.mode}&format=${a.format}&labels=${a.labels}`
77
+ return `${this.st.fileUrl(id, 'anim')}?view=${view}&mode=${a.mode}&format=${a.format}&labels=${a.labels}`
78
78
  }
79
79
  }
80
80
 
@@ -112,12 +112,11 @@ const diffWords = (before: string, after: string) => diffSeq(before.split(/(\s+)
112
112
 
113
113
  const TONE = { ' ': 'var(--dim)', '-': 'var(--red, #e5484d)', '+': 'var(--green, #46a758)' } as const
114
114
 
115
- /** the kind's data view of the open item, under its facts */
116
- export const KindView = observer(({ app, x }: { app: Urls; x: ReviewItem }) => {
115
+ /** the kind's data view of one version, under its words; `stamp` its last message, so an answer reads it again */
116
+ export const KindView = observer(({ app, item, stamp }: { app: Urls; item: Item; stamp: string }) => {
117
117
  const k = kindViewOf(app)
118
- const last = x.thread.at(-1)?.id
119
- useEffect(() => k.read(x), [k, x, last])
120
- const v = k.of(x)
118
+ useEffect(() => k.read(item.id, stamp), [k, item.id, stamp])
119
+ const v = k.of(item.id, stamp)
121
120
  if (v === undefined) return null
122
121
  if ('error' in v) return <div className="rv-err rv-pre">the repo's view of this item: {v.error}</div>
123
122
  const t = v.text
@@ -143,7 +142,7 @@ export const KindView = observer(({ app, x }: { app: Urls; x: ReviewItem }) => {
143
142
  ))}
144
143
  </pre>
145
144
  ) : null}
146
- {v.parts.map((p, i) => <PartCard key={i} app={app} x={x} n={i} p={p} />)}
145
+ {v.parts.map((p, i) => <PartCard key={i} app={app} id={item.id} n={i} p={p} />)}
147
146
  {v.live !== null ? (
148
147
  <div>
149
148
  <button className="ghost" onClick={() => k.toggleLive()}>{k.live ? 'hide live' : 'live'}</button>
@@ -187,9 +186,9 @@ const Side = ({ before, after, side }: { before: string; after: string; side: '-
187
186
  )
188
187
 
189
188
  /** a part of the subject as a card: its logo and name, its change, its media beside its text or the text's change */
190
- const PartCard = ({ app, x, n, p }: { app: Urls; x: ReviewItem; n: number; p: PartData }) => {
189
+ const PartCard = ({ app, id, n, p }: { app: Urls; id: string; n: number; p: PartData }) => {
191
190
  const t = p.text
192
- const src = app.fileUrl(x.item.id, `part-${n}`)
191
+ const src = app.fileUrl(id, `part-${n}`)
193
192
  return (
194
193
  <div className="rv-part">
195
194
  <div className="rv-parthead">
@@ -216,8 +215,8 @@ const PartCard = ({ app, x, n, p }: { app: Urls; x: ReviewItem; n: number; p: Pa
216
215
  }
217
216
 
218
217
  /** a pair of images as a looping animation to download: the mode, the format, the corner labels */
219
- export const AnimPanel = observer(({ app, x }: { app: Urls; x: ReviewItem }) => {
220
- const pairs = x.item.views.flatMap((v, i) => (!isGallery(v) && isPair(v.files) && !v.clip && !v.audio ? [{ i, name: viewName(v, i) }] : []))
218
+ export const AnimPanel = observer(({ app, item }: { app: Urls; item: Item }) => {
219
+ const pairs = item.views.flatMap((v, i) => (!isGallery(v) && isPair(v.files) && !v.clip && !v.audio ? [{ i, name: viewName(v, i) }] : []))
221
220
  if (pairs.length === 0) return null
222
221
  const k = kindViewOf(app)
223
222
  const a = k.anim
@@ -234,7 +233,7 @@ export const AnimPanel = observer(({ app, x }: { app: Urls; x: ReviewItem }) =>
234
233
  {pick('mode', [['cut', 'cut'], ['fade', 'fade'], ['wipe', 'wipe']], a.mode)}
235
234
  {pick('format', [['mp4', 'MP4'], ['gif', 'GIF']], a.format)}
236
235
  {pick('labels', [['en', 'EN'], ['fr', 'FR'], ['none', 'no labels']], a.labels)}
237
- <a href={k.animUrl(x, view)} download>download</a>
236
+ <a href={k.animUrl(item.id, view)} download>download</a>
238
237
  </div>
239
238
  )
240
239
  })
@@ -2,7 +2,8 @@
2
2
  // spinner, who listens, the thumbnail. Colours come from review.css, which reads hub.css tokens
3
3
  import { observer } from 'mobx-react-lite'
4
4
  import { useEffect, useState } from 'react'
5
- import { firstView, thumbFileOf, type ReviewItem, type ReviewStatus, type ShownStatus, type Side } from '../../../review/model.ts'
5
+ import type { ThreadRow } from '../../../review/cells.ts'
6
+ import type { ReviewStatus, ShownStatus, Side } from '../../../review/model.ts'
6
7
  import type { ReviewSt } from './review-st.ts'
7
8
 
8
9
  /** a status's tone, as a class review.css colours: its tint, its line, its badge */
@@ -64,8 +65,7 @@ export const AutoTag = ({ rule }: { rule: string }) => (
64
65
  )
65
66
 
66
67
  /** a lane reworking the card: a slow spinner and « in work · L147 » in the lane's colour; nothing when nobody does */
67
- export const Rework = observer(({ rv, x }: { rv: ReviewSt; x: ReviewItem }) => {
68
- const r = rv.reworkOf(x)
68
+ export const Rework = ({ r }: { r: ThreadRow['rework'] }) => {
69
69
  const [, redraw] = useState(0)
70
70
  const until = r?.until
71
71
  useEffect(() => {
@@ -73,7 +73,7 @@ export const Rework = observer(({ rv, x }: { rv: ReviewSt; x: ReviewItem }) => {
73
73
  const t = setTimeout(() => redraw((n) => n + 1), Math.max(0, until - Date.now()) + 1000)
74
74
  return () => clearTimeout(t)
75
75
  }, [until])
76
- if (!r) return null
76
+ if (!r || Date.now() > r.until) return null
77
77
  return (
78
78
  <div className="rv-reworkrow">
79
79
  <span className="rv-rework" style={{ ['--lane' as string]: laneColor(r.lane) }} title={`${r.lane} reworks this card since ${when(r.since)}`}>
@@ -82,11 +82,11 @@ export const Rework = observer(({ rv, x }: { rv: ReviewSt; x: ReviewItem }) => {
82
82
  </span>
83
83
  </div>
84
84
  )
85
- })
85
+ }
86
86
 
87
87
  /** who listens: the pid of each live `sk review watch` that reads his answer on these cards, or « nobody listens » */
88
- export const Listeners = observer(({ rv, cards }: { rv: ReviewSt; cards: readonly ReviewItem[] }) => {
89
- const ws = rv.listenersOf(cards)
88
+ export const Listeners = observer(({ rv, heads }: { rv: ReviewSt; heads: readonly { lane?: string | undefined; session?: string | undefined }[] }) => {
89
+ const ws = rv.listenersOf(heads)
90
90
  const on = ws.length > 0
91
91
  return (
92
92
  <span
@@ -102,11 +102,10 @@ export const Listeners = observer(({ rv, cards }: { rv: ReviewSt; cards: readonl
102
102
  )
103
103
  })
104
104
 
105
- /** an item's thumbnail: its first view's image, else a speech mark (a note with no image) */
106
- export const ThumbOf = ({ rv, x }: { rv: ReviewSt; x: ReviewItem }) => {
107
- const first = firstView(x.item)
108
- if (!first) return <div className="rv-thumbnone">✎</div>
109
- return <img className="rv-thumbimg" src={rv.thumbUrl(x, thumbFileOf(first))} alt="" loading="lazy" />
105
+ /** a thread's thumbnail in the list: its head's first view at the list's size, else a speech mark (a note with no image) */
106
+ export const ThumbOf = ({ rv, row }: { rv: ReviewSt; row: ThreadRow }) => {
107
+ if (!row.thumb) return <div className="rv-thumbnone">✎</div>
108
+ return <img className="rv-thumbimg" src={rv.thumbUrl(row.head, row.thumb)} alt="" loading="lazy" />
110
109
  }
111
110
 
112
111
  /** the page's empty pane: one line of dim words */
@@ -1,7 +1,8 @@
1
1
  // the dispatcher's board (wiki build/shipkit/review.md, Raised items): what the owner, a player or a rule raised, by state,
2
- // each with its topic and its worker, a stale claim marked; who holds the dispatcher role. A row opens its item
2
+ // each with its topic and its worker, a stale claim marked (`GET /api/review/board`); who holds the dispatcher role. A row
3
+ // opens its item
3
4
  import { observer } from 'mobx-react-lite'
4
- import { isMarkItem, isStale, stateOf, topicLabel, type State } from '../../../review/model.ts'
5
+ import { topicLabel, type State } from '../../../review/model.ts'
5
6
  import type { ReviewSt } from './review-st.ts'
6
7
 
7
8
  const STATES: { state: State; label: string }[] = [
@@ -14,33 +15,34 @@ const STATES: { state: State; label: string }[] = [
14
15
 
15
16
  export const ReviewBoard = observer(({ rv }: { rv: ReviewSt }) => {
16
17
  const spec = rv.spec
17
- const now = new Date()
18
- const rows = rv.items.filter((x) => x.item.origin.by !== 'agent' && !isMarkItem(x)).map((x) => ({ x, st: stateOf(x, rv.followed.has(x.item.id)) }))
18
+ const rows = rv.boardRows
19
19
  const role = spec?.role
20
+ const open = rv.card?.data?.members ?? []
20
21
  return (
21
22
  <div className="rv-listscroll rv-board">
22
23
  <div className="rv-count">{role ? `dispatcher: ${role.name}, since ${role.since.slice(0, 16).replace('T', ' ')}` : 'dispatcher: nobody (sk review dispatcher --as <name>)'}</div>
24
+ {rows === null ? <div className="rv-empty"><span className="spin" /> reading the board…</div> : null}
23
25
  {STATES.map(({ state, label }) => {
24
- const of = rows.filter((r) => r.st.state === state)
26
+ const of = (rows ?? []).filter((r) => r.state === state)
25
27
  if (of.length === 0) return null
26
28
  return (
27
29
  <div key={state}>
28
30
  <div className="rv-divider">{label} · {of.length}</div>
29
- {of.map(({ x, st }) => (
30
- <div key={x.item.id} className={`rv-boardrow${rv.open?.item.id === x.item.id ? ' on' : ''}`} onClick={() => rv.pick(x.item.id)}>
31
- <div className="rv-linkedtitle">{x.item.title}</div>
31
+ {of.map((r) => (
32
+ <div key={r.id} className={`rv-boardrow${open.includes(r.id) ? ' on' : ''}`} onClick={() => rv.pick(r.id)}>
33
+ <div className="rv-linkedtitle">{r.title}</div>
32
34
  <div className="rv-dim">
33
- {st.topic ? topicLabel(st.topic, spec ?? undefined) : 'no topic'}
34
- {st.worker ? ` · ${st.worker}` : ''}
35
- {isStale(x, now) ? ' · stale claim' : ''}
36
- {x.item.origin.by === 'player' ? ` · ${x.item.origin.server}#${x.item.origin.serverId}` : x.item.origin.by === 'auto' ? ` · auto ${x.item.origin.rule}` : ''}
35
+ {r.topic ? topicLabel(r.topic, spec ?? undefined) : 'no topic'}
36
+ {r.worker ? ` · ${r.worker}` : ''}
37
+ {r.stale ? ' · stale claim' : ''}
38
+ {r.from ? ` · ${r.from}` : ''}
37
39
  </div>
38
40
  </div>
39
41
  ))}
40
42
  </div>
41
43
  )
42
44
  })}
43
- {rows.every((r) => r.st.state === 'closed') ? <div className="rv-empty">Nothing raised is open.</div> : null}
45
+ {rows !== null && rows.every((r) => r.state === 'closed') ? <div className="rv-empty">Nothing raised is open.</div> : null}
44
46
  </div>
45
47
  )
46
48
  })