rvlib-shipkit 2.9.0 → 2.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.
Files changed (75) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/package.json +1 -1
  3. package/src/cli/cmd_Media.ts +164 -0
  4. package/src/cli/cmd_Review.ts +2 -1
  5. package/src/cli/family-pages.ts +1 -0
  6. package/src/cli/registry.ts +2 -0
  7. package/src/collections/pings.ts +6 -4
  8. package/src/core/app-icon.ts +17 -4
  9. package/src/core/scratch-objects.ts +56 -0
  10. package/src/core/trace-audit.ts +13 -1
  11. package/src/home/home-paths.ts +4 -0
  12. package/src/home/home-routes.ts +36 -2
  13. package/src/home/hubs.ts +5 -0
  14. package/src/home/inbox-shape.ts +182 -0
  15. package/src/home/inbox.ts +48 -0
  16. package/src/home/run-daemon.ts +12 -2
  17. package/src/home/serve-web.ts +155 -16
  18. package/src/ledger/git-scan.ts +73 -25
  19. package/src/ledger/repo-view.ts +2 -22
  20. package/src/media-kinds.ts +7 -0
  21. package/src/media-store/content.ts +51 -0
  22. package/src/media-store/daemon.ts +91 -0
  23. package/src/media-store/db.ts +74 -0
  24. package/src/media-store/fact.ts +9 -0
  25. package/src/media-store/kind.ts +44 -0
  26. package/src/media-store/purge.ts +139 -0
  27. package/src/media-store/remote.ts +93 -0
  28. package/src/media-store/space.ts +124 -0
  29. package/src/media-store/sync.ts +101 -0
  30. package/src/media-store/upload.ts +98 -0
  31. package/src/repo-config.ts +4 -0
  32. package/src/review/anim.ts +6 -5
  33. package/src/review/cells.ts +552 -0
  34. package/src/review/format.ts +1 -1
  35. package/src/review/media-kind.ts +84 -0
  36. package/src/review/media-read.ts +48 -0
  37. package/src/review/model.ts +43 -5
  38. package/src/review/previews.ts +153 -0
  39. package/src/review/routes.ts +105 -47
  40. package/src/review/store.ts +106 -45
  41. package/src/review/trailer-desk.ts +79 -46
  42. package/src/review/trailer-media.ts +163 -0
  43. package/src/review/trailer-routes.ts +5 -2
  44. package/src/serve/hub-app/home-st.ts +39 -9
  45. package/src/serve/hub-app/home.html +2 -1
  46. package/src/serve/hub-app/hub-app.tsx +7 -23
  47. package/src/serve/hub-app/icons.tsx +2 -0
  48. package/src/serve/hub-app/inbox-st.ts +144 -0
  49. package/src/serve/hub-app/inbox-view.tsx +205 -0
  50. package/src/serve/hub-app/inbox.css +73 -0
  51. package/src/serve/hub-app/item-view.tsx +19 -0
  52. package/src/serve/hub-app/keys.ts +4 -3
  53. package/src/serve/hub-app/palette-st.ts +2 -1
  54. package/src/serve/hub-app/project-list.tsx +1 -0
  55. package/src/serve/hub-app/projects-svc.ts +1 -1
  56. package/src/serve/hub-app/repo-st.ts +1 -1
  57. package/src/serve/hub-app/review/kind-view.tsx +21 -22
  58. package/src/serve/hub-app/review/kit.tsx +11 -12
  59. package/src/serve/hub-app/review/review-board.tsx +15 -13
  60. package/src/serve/hub-app/review/review-cells.tsx +241 -0
  61. package/src/serve/hub-app/review/review-kit.ts +79 -0
  62. package/src/serve/hub-app/review/review-list.tsx +87 -122
  63. package/src/serve/hub-app/review/review-page.tsx +22 -79
  64. package/src/serve/hub-app/review/review-st.ts +269 -698
  65. package/src/serve/hub-app/review/review-thread.tsx +302 -0
  66. package/src/serve/hub-app/review/review-views.tsx +322 -253
  67. package/src/serve/hub-app/review/thread-st.ts +770 -0
  68. package/src/serve/hub-app/review.css +235 -91
  69. package/src/serve/hub-runtime.ts +9 -4
  70. package/src/serve/serve-hub.ts +4 -1
  71. package/src/serve/warm-cell.ts +6 -1
  72. package/src/trailer/footage.ts +6 -2
  73. package/src/trailer/passage.ts +4 -2
  74. package/src/trailer/prune.ts +6 -10
  75. package/src/serve/hub-app/review/review-answer.tsx +0 -249
@@ -1,47 +1,15 @@
1
- // a repo's review page as state (wiki build/shipkit/review.md, The review page): the cards on disk, the open one, the
2
- // filters, and his draft per card (rectangles, reactions and comments not sent yet), kept in the browser until it is
3
- // sent. The list is read while the page shows, every 2 s, answered 304 when the store did not move
4
- import { makeAutoObservable, reaction, runInAction } from 'mobx'
5
- import {
6
- asOptions,
7
- isApproved,
8
- isChoice,
9
- isGallery,
10
- isPair,
11
- laneOf,
12
- moveOf,
13
- pasteBlock,
14
- reworkOf,
15
- STARS,
16
- STATUS_LABEL,
17
- stateOf,
18
- unreadBy,
19
- verdictOf,
20
- type MediaView,
21
- type Message,
22
- type Move,
23
- type Rect,
24
- type ReviewItem,
25
- type ReviewReaction,
26
- type ReviewStatus,
27
- type ShownStatus,
28
- type Side,
29
- type Spec,
30
- } from '../../../review/model.ts'
31
- import { answererOf, chainOf, childrenOf, conversationOf, followedIds, isActive, membersOf, orderedThreads, statusOf, threadOfItem, waitingOnOwner, waits, type Thread } from '../../../review/threads.ts'
32
- import { reach } from '../reach.ts'
33
- import type { RepoSt } from '../repo-st.ts'
34
- import type { Role } from '../../../review/role.ts'
1
+ // a repo's review page as state (wiki build/shipkit/review.md, The review page): the list as pages of threads
2
+ // (`GET /api/review/threads`, the filters and the search asked of the server), the open card as a thread
3
+ // (thread-st.ts), the watches, the board, his prefs. Every read is polled every 2 s while the page shows and answered
4
+ // 304 when the store did not move. His drafts are kept in the browser until they are sent
5
+ import { makeAutoObservable, observableRef, reaction, runInAction } from 'mobx'
6
+ import { PAGE, type BoardRow, type ThreadPage, type ThreadRow } from '../../../review/cells.ts'
7
+ import { MOVE_LABEL, pasteBlock, STATUS_LABEL, type Move, type ShownStatus, type Spec } from '../../../review/model.ts'
35
8
  import type { PasteHosts } from '../../../review/paste.ts'
36
- import { ClipSt } from './clip-st.ts'
37
-
38
- interface Draft {
39
- rects: Rect[]
40
- comment: string
41
- reactions?: ReviewReaction[]
42
- /** the option he picked, on a choice card */
43
- pick?: number
44
- }
9
+ import type { Role } from '../../../review/role.ts'
10
+ import type { RepoSt } from '../repo-st.ts'
11
+ import { copyText, etagLoader, kept, postJson, ZOOMS, type Zoom } from './review-kit.ts'
12
+ import { ThreadSt, type Draft } from './thread-st.ts'
45
13
 
46
14
  /** a live `sk review watch`: its process, the session or lane it keeps, when it started */
47
15
  export interface Watcher {
@@ -51,63 +19,25 @@ export interface Watcher {
51
19
  started: string
52
20
  }
53
21
 
54
- export interface Listing {
55
- items: ReviewItem[]
56
- broken: { id: string; error: string }[]
57
- }
58
-
59
- /** the zoom of a view: fit the column (and the window's height), or a share of the image's own pixels */
60
- export const ZOOMS = ['fit', '1', '1.5', '2'] as const
61
- export type Zoom = (typeof ZOOMS)[number]
62
-
63
22
  /** how a pair of images shows: side by side, the curtain, one over the other, the after alone */
64
23
  export type CompareMode = 'side' | 'swipe' | 'onion' | 'mod'
65
24
  export const COMPARE_MODES: readonly CompareMode[] = ['side', 'swipe', 'onion', 'mod']
66
25
  /** the side a rectangle lands on: the after alone draws on the after */
67
- export const drawnSide = (mode: CompareMode, drawn: Side): Side => (mode === 'mod' ? 'after' : drawn)
26
+ export const drawnSide = (mode: CompareMode, drawn: 'before' | 'after'): 'before' | 'after' => (mode === 'mod' ? 'after' : drawn)
68
27
 
69
- /** below this width the page is the phone's: one column at a time, the verdicts in a bar under the thumb */
70
28
  /** a repo's review unit as the page reads it: the words of its kinds and topics, its dispatcher and who holds the role */
71
29
  export type RepoSpec = Spec & { role: Role | null; sources: string[]; auto: { id: string; every: string }[]; where?: PasteHosts | null }
72
30
 
31
+ /** below this width the page is the phone's: one pane at a time, the verdicts in a bar under the thumb */
73
32
  export const PHONE_PX = 768
74
- /** below this width of the review page itself (the project list and the sidebar already took theirs), `auto` stacks
75
- * the card over the answer in one column beside the list */
76
- export const STACK_PX = 900
77
- /** where the card sits against its answer: on top of it, left of it, or by the page's width */
78
- export const CARD_PLACES = ['top', 'left', 'auto'] as const
79
- export type CardPlace = (typeof CARD_PLACES)[number]
33
+ /** the thread column at least this wide shows the contents strip beside the cells, else behind a button */
34
+ export const RAIL_PX = 1020
80
35
  export type PhonePane = 'list' | 'card'
81
36
  export type PairSide = 'before' | 'after' | 'swipe'
82
37
 
83
38
  const POLL_MS = 2000
84
- /** a sound's clock steps a tenth of a second */
85
- const SOUND_FPS = 10
86
- /** ← → on a sound jump this many seconds */
87
- const SOUND_JUMP = 2
88
-
89
- const sameSpot = (r: ReviewReaction, view: number, tile: number | undefined): boolean => r.view === view && r.tile === tile
90
- /** a draft card's frame on its file urls: a new frame is a new url, past the browser's cache of the old one */
91
- const frameTag = (x: ReviewItem | null | undefined): string => (x?.item.wip ? `?f=${x.item.wip.frame}` : '')
92
-
93
- /** what a reload must not lose, under keys of this repo: a blocked storage only loses persistence */
94
- const store = {
95
- get(k: string): string | null {
96
- try {
97
- return localStorage.getItem(k)
98
- } catch {
99
- return null
100
- }
101
- },
102
- put(k: string, v: string | null): void {
103
- try {
104
- if (v === null) localStorage.removeItem(k)
105
- else localStorage.setItem(k, v)
106
- } catch {
107
- // as above
108
- }
109
- },
110
- }
39
+ /** the search goes to the server once he stops typing this long */
40
+ const SEARCH_MS = 250
111
41
 
112
42
  const draftOf = (s: string | null): Draft | null => {
113
43
  try {
@@ -119,68 +49,19 @@ const draftOf = (s: string | null): Draft | null => {
119
49
  }
120
50
  }
121
51
 
122
- /** a loader for a polled list: it sends the tag of its last answer, and on « not modified » gives that answer again */
123
- function unchangedAware<T>(url: () => string): () => Promise<T> {
124
- let last: { tag: string; value: T } | null = null
125
- return async () => {
126
- const res = await reach(url(), { cache: 'no-store', headers: last ? { 'If-None-Match': last.tag } : {} })
127
- if (res.status === 304 && last) return last.value
128
- if (!res.ok) throw new Error(`${url()}: HTTP ${res.status} ${await res.text().catch(() => '')}`.trim())
129
- const value = (await res.json()) as T
130
- const tag = res.headers.get('ETag')
131
- last = tag ? { tag, value } : null
132
- return value
133
- }
134
- }
135
-
136
- async function postJson<T>(url: string, body: unknown): Promise<T> {
137
- const res = await reach(url, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify(body) })
138
- const text = await res.text()
139
- if (!res.ok) {
140
- let msg = text
141
- try {
142
- msg = (JSON.parse(text) as { error?: string }).error ?? text
143
- } catch {
144
- // a plain text answer says it already
145
- }
146
- throw new Error(msg || `HTTP ${res.status}`)
147
- }
148
- return JSON.parse(text) as T
149
- }
150
-
151
- /** a text to the clipboard: the clipboard api, else (a page over plain http, the phone through a public host) the
152
- * old copy command on a hidden field */
153
- async function copyText(text: string): Promise<boolean> {
154
- try {
155
- await navigator.clipboard.writeText(text)
156
- return true
157
- } catch {
158
- const el = document.createElement('textarea')
159
- el.value = text
160
- el.setAttribute('readonly', '')
161
- el.style.position = 'fixed'
162
- el.style.opacity = '0'
163
- document.body.appendChild(el)
164
- el.select()
165
- const ok = document.execCommand('copy')
166
- el.remove()
167
- return ok
168
- }
169
- }
170
-
171
52
  /** the pair's compare mode, the curtain's line and the onion's opacity, shared by every pair of the page */
172
53
  export class CompareSt {
173
54
  mode: CompareMode = 'side'
174
55
  split = 0.5
175
56
  opacity = 0.5
176
57
  constructor(private readonly key: string) {
177
- const m = store.get(key)
58
+ const m = kept.get(key)
178
59
  if (m && (COMPARE_MODES as readonly string[]).includes(m)) this.mode = m as CompareMode
179
60
  makeAutoObservable<this, 'key'>(this, { key: false })
180
61
  }
181
62
  setMode(m: CompareMode): void {
182
63
  this.mode = m
183
- store.put(this.key, m)
64
+ kept.put(this.key, m)
184
65
  }
185
66
  setSplit(v: number): void {
186
67
  this.split = Math.max(0, Math.min(1, v))
@@ -190,7 +71,7 @@ export class CompareSt {
190
71
  }
191
72
  }
192
73
 
193
- /** the phone's state: which pane shows, « circle » drawing on, the side of a pair */
74
+ /** the phone's state: which pane shows, « circle » drawing on, the side of a pair, the contents sheet */
194
75
  export class PhoneSt {
195
76
  on = false
196
77
  pane: PhonePane = 'list'
@@ -218,148 +99,116 @@ export class PhoneSt {
218
99
  const isShownStatus = (s: string): s is ShownStatus => Object.hasOwn(STATUS_LABEL, s)
219
100
 
220
101
  export class ReviewSt {
221
- list: Listing | null = null
102
+ page: ThreadPage | null = null
222
103
  listError: string | null = null
223
- /** the repo's review unit in words (its kinds, topics, dispatcher and its holder), read when the page starts */
104
+ /** the rows asked of the server: a page more on « more » or when the list's end scrolls into view */
105
+ shown = PAGE
106
+ /** the repo's review unit in words, read when the page starts */
224
107
  spec: RepoSpec | null = null
225
108
  /** the dispatcher's board in place of the cards */
226
109
  board = false
110
+ boardRows: BoardRow[] | null = null
227
111
  watchers: Watcher[] = []
228
- /** each clip view's own clock on the open card, by view index, made on first use */
229
- private readonly clips = new Map<number, ClipSt>()
230
- private clipsCard = ''
231
112
  selectedId: string | null = null
113
+ /** the card opened with none named (the list's first row then): it stays open until he picks another */
114
+ pinned: string | null = null
115
+ /** the open card as a thread: made when a card opens */
116
+ card: ThreadSt | null = null
117
+ /** what the search box holds; `q` is what the server was asked, once he stopped typing */
232
118
  query = ''
119
+ q = ''
233
120
  subject: string | null = null
234
121
  whose: Move | null = null
235
122
  status: ShownStatus | null = null
236
- drafts: Record<string, Draft> = {}
237
- /** the rectangle of the open card picked, its index: its note box opens beside it */
238
- rect: number | null = null
239
- /** the rectangle whose note box takes the focus once it shows: one just drawn, or picked on the image */
240
- noteFocus: number | null = null
241
- /** the subject rings over the image (M) */
242
- marksOn = true
243
- /** the open card's active view, its index: the one last drawn on or picked, whose clip the keys drive */
244
- view = 0
245
- zoom: Zoom = 'fit'
246
- viewZoom: Record<number, Zoom> = {}
247
- /** the gallery tile shown large across the column, `<view>/<tile>` */
248
- bigTile: string | null = null
249
- /** a draft card's past frame shown in place of its live one, an index of its history; null is now */
250
- frame: number | null = null
251
- /** a card of options shown full, every view stacked, by id: his switch, this visit */
252
- full: Record<string, boolean> = {}
253
- /** an option row he folded or unfolded, by view index; a row he never touched follows `rowOpen` */
254
- openRows: Record<number, boolean> = {}
255
- replies: Record<string, string> = {}
256
- private reading = new Set<string>()
257
123
  /** « hide handled »: only the active threads in the list */
258
124
  hideHandled = true
259
125
  /** « by lane »: the list grouped under one header per lane */
260
126
  byLane = false
261
- /** the threads whose older versions are unfolded, by head id */
262
- unfolded: Record<string, boolean> = {}
263
- busy = false
264
- error: string | null = null
127
+ /** the subject rings over the image (M) */
128
+ marksOn = true
129
+ zoom: Zoom = 'fit'
130
+ /** the contents strip beside the cells, when the column is wide enough; folded by hand */
131
+ railOn = true
132
+ /** the contents as a sheet over the cells: a narrow column or the phone */
133
+ sheet = false
134
+ /** the thread column's width, measured */
135
+ width = 0
265
136
  /** what the last copy put on the clipboard, in words, shown a moment */
266
137
  toast: string | null = null
267
- private toastTimer: ReturnType<typeof setTimeout> | null = null
268
- /** the card against its answer, his pick, kept with the prefs */
269
- place: CardPlace = 'auto'
270
- /** the page is narrower than STACK_PX */
271
- narrow = false
272
138
  readonly compare: CompareSt
273
139
  readonly phone = new PhoneSt()
140
+ /** the view a link names before its card is made */
141
+ pendingView = 0
142
+ private toastTimer: ReturnType<typeof setTimeout> | null = null
143
+ private searchTimer: ReturnType<typeof setTimeout> | null = null
274
144
  private timer: ReturnType<typeof setInterval> | null = null
275
- private readonly loadList: () => Promise<Listing>
145
+ private readonly loadPage: () => Promise<ThreadPage>
276
146
  private readonly loadWatchers: () => Promise<Watcher[]>
147
+ private readonly loadBoard: () => Promise<{ role: Role | null; rows: BoardRow[] }>
277
148
  private readonly prefix: string
278
149
 
279
- /** the page measured its width */
280
- fit(px: number): void {
281
- const on = px > 0 && px < STACK_PX
282
- if (this.narrow !== on) this.narrow = on
283
- }
284
- /** the card over its answer in one column: picked, or `auto` on a narrow page */
285
- get stacked(): boolean {
286
- return this.place === 'top' || (this.place === 'auto' && this.narrow)
287
- }
288
- setPlace(p: CardPlace): void {
289
- this.place = p
290
- }
291
- /** the open card as thin option rows: a choice, or views that each play alone, unless he asked them full */
292
- get rows(): boolean {
293
- const x = this.open
294
- return x !== null && asOptions(x.item) && this.full[x.item.id] !== true
295
- }
296
- setFull(on: boolean): void {
297
- const id = this.open?.item.id
298
- if (id) this.full = { ...this.full, [id]: on }
299
- }
300
- get choice(): boolean {
301
- const x = this.open
302
- return x !== null && isChoice(x.item)
303
- }
304
- /** the card's header (title, state, what, and in one column the verdicts) sits over its views: one column, the
305
- * phone's card pane, a choice's options */
306
- get headInViews(): boolean {
307
- return this.stacked || this.phone.on || this.choice
308
- }
309
- /** an option row shows its full view under it: from the start for an image, a pair or a clip, never for a sound
310
- * (its strip is its view), else as he folded it */
311
- rowOpen(i: number): boolean {
312
- const own = this.openRows[i]
313
- if (own !== undefined) return own
314
- const v = this.open?.item.views[i]
315
- return v !== undefined && (isGallery(v) || v.audio === undefined)
316
- }
317
- toggleRow(i: number): void {
318
- this.openRows = { ...this.openRows, [i]: !this.rowOpen(i) }
319
- }
320
-
321
150
  constructor(private readonly st: RepoSt) {
322
151
  this.prefix = `shipkit.review.${st.key}.`
323
- this.loadList = unchangedAware(() => st.url('/api/review'))
324
- this.loadWatchers = unchangedAware(() => st.url('/api/review/watchers'))
152
+ this.loadPage = etagLoader(() => st.url(`/api/review/threads?${this.listQuery}`))
153
+ this.loadWatchers = etagLoader(() => st.url('/api/review/watchers'))
154
+ this.loadBoard = etagLoader(() => st.url('/api/review/board'))
325
155
  this.compare = new CompareSt(`${this.prefix}compare`)
326
156
  try {
327
- const p = JSON.parse(store.get(`${this.prefix}prefs`) ?? '{}') as { hideHandled?: boolean; byLane?: boolean; zoom?: string; marks?: boolean; place?: string }
157
+ const p = JSON.parse(kept.get(`${this.prefix}prefs`) ?? '{}') as { hideHandled?: boolean; byLane?: boolean; zoom?: string; marks?: boolean; rail?: boolean }
328
158
  if (p.hideHandled === false) this.hideHandled = false
329
159
  if (p.byLane === true) this.byLane = true
330
160
  if (p.marks === false) this.marksOn = false
161
+ if (p.rail === false) this.railOn = false
331
162
  if ((ZOOMS as readonly string[]).includes(p.zoom ?? '')) this.zoom = p.zoom as Zoom
332
- if ((CARD_PLACES as readonly string[]).includes(p.place ?? '')) this.place = p.place as CardPlace
333
163
  } catch {
334
164
  // a broken pref is the default
335
165
  }
336
- makeAutoObservable<this, 'st' | 'clips' | 'clipsCard' | 'reading' | 'timer' | 'loadList' | 'loadWatchers' | 'prefix' | 'toastTimer'>(this, {
166
+ makeAutoObservable<this, 'st' | 'toastTimer' | 'searchTimer' | 'timer' | 'loadPage' | 'loadWatchers' | 'loadBoard' | 'prefix'>(this, {
337
167
  st: false,
338
- clips: false,
339
- clipsCard: false,
340
- reading: false,
168
+ toastTimer: false,
169
+ searchTimer: false,
341
170
  timer: false,
342
- loadList: false,
171
+ loadPage: false,
343
172
  loadWatchers: false,
173
+ loadBoard: false,
344
174
  prefix: false,
345
- toastTimer: false,
346
175
  compare: false,
347
176
  phone: false,
177
+ card: observableRef,
178
+ page: observableRef,
179
+ boardRows: observableRef,
348
180
  })
349
- // opening a card reads the agent's messages on its whole thread
350
181
  reaction(
351
- () => (this.openThread ? membersOf(this.openThread) : []).filter((x) => unreadBy(x, 'owner').length > 0).map((x) => x.item.id),
352
- (ids) => {
353
- for (const id of ids) void this.markRead(id)
354
- },
182
+ () => JSON.stringify({ hideHandled: this.hideHandled, byLane: this.byLane, zoom: this.zoom, marks: this.marksOn, rail: this.railOn }),
183
+ (s) => kept.put(`${this.prefix}prefs`, s),
355
184
  )
185
+ // the card the address names, else the list's first: a new one is a new thread state, the old one disposed
356
186
  reaction(
357
- () => JSON.stringify({ hideHandled: this.hideHandled, byLane: this.byLane, zoom: this.zoom, marks: this.marksOn, place: this.place }),
358
- (s) => store.put(`${this.prefix}prefs`, s),
187
+ () => this.openId,
188
+ (id) => this.openCard(id),
189
+ { fireImmediately: true },
359
190
  )
191
+ // a filter moved: the list asks its first page again
192
+ reaction(
193
+ () => this.listFilters,
194
+ () => {
195
+ this.shown = PAGE
196
+ if (this.timer !== null) void this.refresh()
197
+ },
198
+ )
199
+ }
200
+
201
+ /** an absolute hub path as this repo's hub answers it */
202
+ url(p: string): string {
203
+ return this.st.url(p)
360
204
  }
361
205
 
362
- /** the list and the watchers, read now and every 2 s while the page shows; the unit's words once a start */
206
+ /** the repo's one second clock: every « 3h ago » of the page reads it */
207
+ get now(): number {
208
+ return this.st.clock.now
209
+ }
210
+
211
+ /** the list, the watches and the open card, read now and every 2 s while the page shows; the unit's words once */
363
212
  start(): void {
364
213
  void this.refresh()
365
214
  void fetch(this.st.url('/api/review/spec'))
@@ -375,173 +224,119 @@ export class ReviewSt {
375
224
  }
376
225
 
377
226
  async refresh(): Promise<void> {
378
- try {
379
- const [list, watchers] = await Promise.all([this.loadList(), this.loadWatchers().catch(() => this.watchers)])
380
- runInAction(() => {
381
- if (list !== this.list) this.list = list
382
- if (watchers !== this.watchers) this.watchers = watchers
383
- this.listError = null
384
- })
385
- } catch (e) {
386
- runInAction(() => (this.listError = (e as Error).message))
387
- }
388
- }
389
-
390
- /** the card's folder, or one of its files, shown in the Finder of the machine the hub runs on */
391
- async reveal(id: string, file?: string): Promise<void> {
392
- try {
393
- await postJson(this.st.url(`/api/review/${id}/reveal`), file ? { file } : {})
394
- } catch (e) {
395
- runInAction(() => (this.error = (e as Error).message))
227
+ const card = this.card
228
+ await Promise.all([
229
+ this.loadPage().then(
230
+ (page) => runInAction(() => {
231
+ if (page !== this.page) this.page = page
232
+ this.listError = null
233
+ }),
234
+ (e: Error) => runInAction(() => (this.listError = e.message)),
235
+ ),
236
+ this.loadWatchers().then(
237
+ (w) => runInAction(() => w !== this.watchers && (this.watchers = w)),
238
+ () => undefined,
239
+ ),
240
+ this.board ? this.loadBoard().then((b) => runInAction(() => b.rows !== this.boardRows && (this.boardRows = b.rows)), () => undefined) : null,
241
+ card?.refresh(),
242
+ ])
243
+ }
244
+
245
+ /** a verdict or a reply went out: the card, the list, the tree's count and the project list's pill move at once */
246
+ async answered(): Promise<void> {
247
+ await this.refresh()
248
+ void this.st.cols.poll(true)
249
+ void this.st.home.projects.load()
250
+ if (this.st.home.page === 'inbox') void this.st.home.inbox.poll()
251
+ }
252
+
253
+ private openCard(id: string | null): void {
254
+ if (this.card?.id === id) return
255
+ // an id of the open thread (an old version's link) stays in it: the cell shows, nothing is rebuilt
256
+ if (id !== null && this.card?.data?.members.includes(id)) {
257
+ this.card.reveal(id)
258
+ return
396
259
  }
260
+ // the list's first row opened with no card named stays open: a poll that reorders the list never swaps it
261
+ if (this.selectedId === null && id !== null) this.pinned = id
262
+ this.card?.dispose()
263
+ this.card = id === null ? null : new ThreadSt(this, id, this.pendingView)
264
+ this.pendingView = 0
265
+ if (this.card && this.timer !== null) void this.card.refresh()
397
266
  }
398
267
 
399
- /** the open card as one paste a fresh agent session in any repo acts on: what it is, its repo, the command that shows
400
- * it whole, its link here and on the phone (C) */
401
- async copyCard(): Promise<void> {
402
- const x = this.open
403
- if (!x) return
404
- const id = x.item.id
405
- const w = this.spec?.where
406
- const here = typeof location === 'undefined' ? (w?.open ?? '') : `${location.origin}${location.pathname}${location.search}`
407
- const text = pasteBlock(x.item, STATUS_LABEL[this.statusOf(x)], {
408
- root: w?.root ?? '<the repo>',
409
- open: `${here}#page:review:${id}`,
410
- phone: w?.phone ? `${w.phone}#page:review:${id}` : null,
411
- })
412
- const ok = await copyText(text)
413
- runInAction(() => {
414
- this.toast = ok ? `copied for an agent: title, repo, sk review show, ${w?.phone ? 'links' : 'link'}` : 'the browser refused the copy'
415
- if (this.toastTimer !== null) clearTimeout(this.toastTimer)
416
- this.toastTimer = setTimeout(() => runInAction(() => (this.toast = null)), 2600)
417
- })
418
- }
419
-
420
- setBoard(on: boolean): void {
421
- this.board = on
422
- }
423
-
424
- /** a card's file; a draft card's carries its frame, so each new frame is a new url the browser loads again */
425
- fileUrl(id: string, name: string): string {
426
- const x = this.open?.item.id === id ? this.open : this.list?.items.find((y) => y.item.id === id)
427
- return `${this.st.url(`/api/review/${id}/${name}`)}${frameTag(x)}`
428
- }
429
-
430
- thumbUrl(x: ReviewItem, name: string): string {
431
- return /\.(png|jpe?g|webp)$/.test(name) ? `${this.st.url(`/api/review/${x.item.id}/thumb/${name}`)}${frameTag(x)}` : this.fileUrl(x.item.id, name)
432
- }
433
-
434
- threadImageUrl(id: string, name: string): string {
435
- return this.st.url(`/api/review/${id}/thread/${name}`)
436
- }
268
+ // ── the list ──
437
269
 
438
- get items(): ReviewItem[] {
439
- return this.list?.items ?? []
270
+ /** the filters the server is asked, in its keys */
271
+ get listFilters(): string {
272
+ const p = new URLSearchParams()
273
+ if (!this.hideHandled) p.set('handled', '1')
274
+ if (this.subject !== null) p.set('subject', this.subject)
275
+ if (this.whose !== null) p.set('whose', this.whose)
276
+ if (this.status !== null) p.set('status', this.status)
277
+ if (this.q) p.set('q', this.q)
278
+ return p.toString()
440
279
  }
441
280
 
442
- get broken(): Listing['broken'] {
443
- return this.list?.broken ?? []
281
+ get listQuery(): string {
282
+ const f = this.listFilters
283
+ return `${f ? `${f}&` : ''}limit=${this.shown}`
444
284
  }
445
285
 
446
- statusOf(x: ReviewItem): ShownStatus {
447
- return statusOf(x, this.items)
286
+ get rows(): ThreadRow[] {
287
+ return this.page?.rows ?? []
448
288
  }
449
289
 
450
- get followed(): Set<string> {
451
- return followedIds(this.items)
290
+ /** more rows sit on the server past the ones shown */
291
+ get more(): number {
292
+ return Math.max(0, (this.page?.total ?? 0) - this.rows.length)
452
293
  }
453
294
 
454
- reworkOf(x: ReviewItem): ReturnType<typeof reworkOf> {
455
- return reworkOf(x, this.followed.has(x.item.id), new Date())
456
- }
457
-
458
- /** the live watches that read his answer on any of these cards */
459
- listenersOf(cards: readonly ReviewItem[]): Watcher[] {
460
- return this.watchers.filter((w) =>
461
- cards.some((x) => (w.session === null || (x.item.origin.by === 'agent' && x.item.origin.session === w.session)) && (w.lane === null || laneOf(x) === w.lane)),
462
- )
463
- }
464
-
465
- get threads(): Thread[] {
466
- return orderedThreads(this.items)
295
+ showMore(): void {
296
+ if (this.more === 0 || this.page === null || this.page.limit < this.shown) return
297
+ this.shown += PAGE
298
+ void this.refresh()
467
299
  }
468
300
 
469
301
  /** what waits on the owner, the one count of every surface (collections/review.ts waitingCards) */
470
302
  get pendingCount(): number {
471
- return waitingOnOwner(this.items).length
303
+ return this.page?.counts.waiting ?? 0
472
304
  }
473
305
 
474
306
  get activeCount(): number {
475
- return this.threads.filter((t) => isActive(t)).length
307
+ return this.page?.counts.active ?? 0
476
308
  }
477
309
 
478
- /** the subject kinds this store holds, for the filter */
479
310
  get subjects(): string[] {
480
- return [...new Set(this.items.map((x) => x.item.subject.kind))].sort()
481
- }
482
-
483
- /** the list as the switch, the filters and the search show it: one thread per head */
484
- get visible(): Thread[] {
485
- const q = this.query.trim().toLowerCase()
486
- return this.threads.filter(
487
- (t) =>
488
- (!this.hideHandled || isActive(t)) &&
489
- (this.subject === null || t.head.item.subject.kind === this.subject) &&
490
- (this.whose === null || this.moveOf(t.head) === this.whose) &&
491
- (this.status === null || this.statusOf(t.head) === this.status) &&
492
- (q === '' || membersOf(t).some((x) => `${x.item.title} ${x.item.what ?? ''} ${x.item.id}`.toLowerCase().includes(q))),
493
- )
494
- }
495
-
496
- /** the visible threads under one header per lane; null: the cards with no lane */
497
- get laneGroups(): { lane: string | null; threads: Thread[] }[] {
498
- const groups = new Map<string | null, Thread[]>()
499
- for (const t of this.visible) {
500
- const lane = laneOf(t.head) ?? null
501
- groups.set(lane, [...(groups.get(lane) ?? []), t])
502
- }
503
- const all = [...groups].map(([lane, threads]) => ({ lane, threads }))
504
- return [...all.filter((g) => g.lane !== null), ...all.filter((g) => g.lane === null)]
505
- }
506
-
507
- get open(): ReviewItem | null {
508
- return this.items.find((x) => x.item.id === this.selectedId) ?? this.visible[0]?.head ?? this.threads[0]?.head ?? null
509
- }
510
-
511
- get openThread(): Thread | null {
512
- const id = this.open?.item.id
513
- return id === undefined ? null : threadOfItem(id, this.threads)
514
- }
515
-
516
- /** the reports and notes nested in the open card */
517
- get answered(): ReviewItem[] {
518
- const t = this.openThread
519
- const id = this.open?.item.id
520
- return t && t.versions.some((x) => x.item.id === id) ? t.answers : []
311
+ return this.page?.subjects ?? []
521
312
  }
522
313
 
523
- get answeredBy(): ReviewItem | null {
524
- const x = this.open
525
- return x && x.item.origin.by !== 'agent' ? answererOf(x.item.id, this.items) : null
314
+ get broken(): ThreadPage['broken'] {
315
+ return this.page?.broken ?? []
526
316
  }
527
317
 
528
- /** the older versions of the open card, the newest of them first */
529
- get history(): ReviewItem[] {
530
- const x = this.open
531
- return x ? chainOf(x, this.items).slice(1) : []
318
+ /** the rows under one header per lane; null: the rows with no lane */
319
+ get laneGroups(): { lane: string | null; rows: ThreadRow[] }[] {
320
+ const groups = new Map<string | null, ThreadRow[]>()
321
+ for (const r of this.rows) groups.set(r.lane ?? null, [...(groups.get(r.lane ?? null) ?? []), r])
322
+ const all = [...groups].map(([lane, rows]) => ({ lane, rows }))
323
+ return [...all.filter((g) => g.lane !== null), ...all.filter((g) => g.lane === null)]
532
324
  }
533
325
 
534
- get newer(): ReviewItem[] {
535
- const x = this.open
536
- return x ? childrenOf(x.item.id, this.items) : []
326
+ /** the card shown: the one the address names, else the list's first */
327
+ get openId(): string | null {
328
+ return this.selectedId ?? this.pinned ?? this.rows[0]?.head ?? null
537
329
  }
538
330
 
539
- showsVersions(t: Thread): boolean {
540
- return this.unfolded[t.head.item.id] === true || t.versions.slice(1).some((x) => x.item.id === this.selectedId)
331
+ /** the list's row of the open card: the one whose thread holds its id */
332
+ get openRow(): ThreadRow | null {
333
+ const id = this.card?.data?.head ?? this.openId
334
+ return id === null ? null : (this.rows.find((r) => r.head === id || r.ids.includes(id)) ?? null)
541
335
  }
542
336
 
543
- fold(headId: string): void {
544
- this.unfolded = { ...this.unfolded, [headId]: !this.unfolded[headId] }
337
+ /** the live watches that read his answer on any of these threads */
338
+ listenersOf(heads: readonly { lane?: string | undefined; session?: string | undefined }[]): Watcher[] {
339
+ return this.watchers.filter((w) => heads.some((h) => (w.session === null || h.session === w.session) && (w.lane === null || h.lane === w.lane)))
545
340
  }
546
341
 
547
342
  setHideHandled(on: boolean): void {
@@ -552,8 +347,16 @@ export class ReviewSt {
552
347
  this.byLane = on
553
348
  }
554
349
 
350
+ setBoard(on: boolean): void {
351
+ this.board = on
352
+ if (on) void this.refresh()
353
+ }
354
+
355
+ /** the search box: the server is asked once he stops typing */
555
356
  setQuery(q: string): void {
556
357
  this.query = q
358
+ if (this.searchTimer !== null) clearTimeout(this.searchTimer)
359
+ this.searchTimer = setTimeout(() => runInAction(() => (this.q = this.query.trim().toLowerCase())), q === '' ? 0 : SEARCH_MS)
557
360
  }
558
361
 
559
362
  setFilter(f: { subject?: string | null; whose?: Move | null; status?: ShownStatus | null }): void {
@@ -562,52 +365,14 @@ export class ReviewSt {
562
365
  if (f.status !== undefined) this.status = f.status
563
366
  }
564
367
 
565
- moveOf(x: ReviewItem): Move {
566
- return moveOf(stateOf(x, this.followed.has(x.item.id)).state)
567
- }
568
-
569
- /** what the form edits: the draft, else the sent feedback, else nothing yet */
570
- get draft(): Draft {
571
- const x = this.open
572
- if (!x) return { rects: [], comment: '' }
573
- const v = verdictOf(x)
574
- const sent = v?.reactions
575
- return (
576
- this.drafts[x.item.id] ?? {
577
- rects: v?.rects ?? [],
578
- comment: v?.comment ?? '',
579
- ...(sent && sent.length > 0 ? { reactions: sent } : {}),
580
- ...(v?.pick !== undefined ? { pick: v.pick } : {}),
581
- }
582
- )
583
- }
584
-
585
- get dirty(): boolean {
586
- const x = this.open
587
- return x !== null && this.drafts[x.item.id] !== undefined
588
- }
589
-
590
- private edit(f: (d: Draft) => Draft): void {
591
- const x = this.open
592
- if (!x) return
593
- const d = this.draft
594
- const { reactions, ...rest } = f({ ...d, rects: [...d.rects], reactions: [...(d.reactions ?? [])] })
595
- const next: Draft = reactions && reactions.length > 0 ? { ...rest, reactions } : rest
596
- this.drafts = { ...this.drafts, [x.item.id]: next }
597
- store.put(`${this.prefix}draft.${x.item.id}`, JSON.stringify(next))
598
- }
599
-
600
- /** opens a card from the page: its address follows */
601
- pick(id: string): void {
602
- this.st.showReview(id)
603
- if (this.phone.on) this.phone.show('card')
604
- }
368
+ // ── the address ──
605
369
 
606
370
  /** what the address carries beside the card: its view and the list's filters, `view=1&subject=place`, each only
607
371
  * off its default (`handled=1` shows the handled threads, `lanes=1` groups by lane) */
608
372
  get address(): string {
609
373
  const q = new URLSearchParams()
610
- if (this.view > 0) q.set('view', String(this.view))
374
+ const view = this.card?.view ?? this.pendingView
375
+ if (view > 0) q.set('view', String(view))
611
376
  if (this.subject !== null) q.set('subject', this.subject)
612
377
  if (this.whose !== null) q.set('whose', this.whose)
613
378
  if (this.status !== null) q.set('status', this.status)
@@ -620,362 +385,168 @@ export class ReviewSt {
620
385
  applyAddress(raw: string): void {
621
386
  const q = new URLSearchParams(raw)
622
387
  const view = Number(q.get('view'))
623
- if (Number.isInteger(view) && view > 0) this.view = view
388
+ if (Number.isInteger(view) && view > 0) {
389
+ if (this.card) this.card.setView(view)
390
+ else this.pendingView = view
391
+ }
624
392
  const subject = q.get('subject')
625
393
  if (subject) this.subject = subject
626
394
  const whose = q.get('whose')
627
- if (whose === 'owner' || whose === 'agents' || whose === 'none') this.whose = whose
395
+ if (whose !== null && Object.hasOwn(MOVE_LABEL, whose)) this.whose = whose as Move
628
396
  const status = q.get('status')
629
397
  if (status !== null && isShownStatus(status)) this.status = status
630
398
  if (q.get('handled') === '1') this.hideHandled = false
631
399
  if (q.get('lanes') === '1') this.byLane = true
632
400
  }
633
401
 
634
- /** the card the address names; its draft is read again from storage, the truth over every window */
402
+ /** the card the address names */
635
403
  select(id: string | null): void {
636
- if (id !== this.selectedId) {
637
- this.view = 0
638
- this.viewZoom = {}
639
- this.bigTile = null
640
- this.frame = null
641
- this.openRows = {}
642
- // a link to a card on the phone opens the card, never the list
643
- if (id !== null && this.phone.on) this.phone.show('card')
644
- }
404
+ // a link to a card on the phone opens the card, never the list
405
+ if (id !== null && id !== this.selectedId && this.phone.on) this.phone.show('card')
645
406
  this.selectedId = id
646
- if (id !== null) {
647
- const stored = draftOf(store.get(`${this.prefix}draft.${id}`))
648
- if (stored) this.drafts = { ...this.drafts, [id]: stored }
649
- else if (this.drafts[id]) {
650
- const { [id]: _, ...rest } = this.drafts
651
- this.drafts = rest
652
- }
653
- }
654
- this.rect = null
655
- this.noteFocus = null
656
- this.error = null
657
407
  }
658
408
 
659
- /** ↑↓ on the page: the next thread head the list shows */
409
+ /** opens a card from the page: its address follows */
410
+ pick(id: string): void {
411
+ this.st.showReview(id)
412
+ if (this.phone.on) this.phone.show('card')
413
+ }
414
+
415
+ /** ↑↓ on the page: the next row of the list */
660
416
  move(delta: 1 | -1): void {
661
- const list = this.visible
662
- const at = list.findIndex((t) => t.head.item.id === this.openThread?.head.item.id)
663
- const next = list[Math.max(0, Math.min(list.length - 1, at + delta))]
664
- if (next) this.pick(next.head.item.id)
417
+ const at = this.rows.findIndex((r) => r === this.openRow)
418
+ const next = this.rows[Math.max(0, Math.min(this.rows.length - 1, at + delta))]
419
+ if (next) this.pick(next.head)
665
420
  }
666
421
 
667
- /** N: the next pending thread head after the open one, wrapping */
422
+ /** N: the next card that waits on him after the open one, wrapping */
668
423
  nextPending(): void {
669
- const pend = this.threads.filter((t) => waits(t.head))
424
+ const pend = this.rows.filter((r) => r.waits)
670
425
  if (pend.length === 0) return
671
- const at = pend.findIndex((t) => t.head.item.id === this.open?.item.id)
426
+ const at = pend.findIndex((r) => r === this.openRow)
672
427
  const next = pend[(at + 1) % pend.length]
673
- if (next) this.pick(next.head.item.id)
428
+ if (next) this.pick(next.head)
674
429
  }
675
430
 
676
- /** a rectangle on a view, which becomes the active one; on a clip it keeps the time of the frame shown */
677
- addRect(r: { x: number; y: number; w: number; h: number }, side: Side | undefined, on: number = this.view): void {
678
- if (on !== this.view) this.setView(on)
679
- const view = this.view > 0 ? { view: this.view } : {}
680
- const t = this.clipKey ? { t: Math.round(this.clip.time * 1000) / 1000 } : {}
681
- this.edit((d) => ({ ...d, rects: [...d.rects, { ...r, comment: '', ...view, ...(side ? { side } : {}), ...t }] }))
682
- this.rect = this.draft.rects.length - 1
683
- this.noteFocus = this.rect
684
- }
431
+ // ── the thread column ──
685
432
 
686
- setView(i: number): void {
687
- this.view = i
688
- this.rect = null
433
+ /** the thread column measured its width */
434
+ fit(px: number): void {
435
+ if (this.width !== px) this.width = px
689
436
  }
690
437
 
691
- /** the playable view an option row or a clip shows: a clip, or a sound shown as a row */
692
- private playableAt(i: number): MediaView | null {
693
- const v = this.open?.item.views[i]
694
- if (!v || isGallery(v)) return null
695
- return v.clip || (v.audio && this.rows && !isPair(v.files)) ? v : null
438
+ /** the contents strip sits beside the cells */
439
+ get rail(): boolean {
440
+ return this.railOn && !this.phone.on && this.width >= RAIL_PX
696
441
  }
697
442
 
698
- get openView(): MediaView | null {
699
- const v = this.open?.item.views[this.view]
700
- return v && !isGallery(v) ? v : null
443
+ toggleRail(): void {
444
+ if (this.phone.on || this.width < RAIL_PX) this.sheet = !this.sheet
445
+ else this.railOn = !this.railOn
701
446
  }
702
447
 
703
- zoomOf(i: number): Zoom {
704
- return this.viewZoom[i] ?? this.zoom
448
+ closeSheet(): void {
449
+ this.sheet = false
705
450
  }
706
451
 
707
452
  setZoom(z: Zoom): void {
708
453
  this.zoom = z
709
- this.viewZoom = {}
710
- }
711
-
712
- setViewZoom(i: number, z: Zoom): void {
713
- this.viewZoom = { ...this.viewZoom, [i]: z }
714
454
  }
715
455
 
716
- setFrame(f: number | null): void {
717
- this.frame = f
718
- }
719
-
720
- toggleTile(view: number, tile: number): void {
721
- const k = `${view}/${tile}`
722
- this.bigTile = this.bigTile === k ? null : k
723
- }
724
-
725
- reactionOf(view: number, tile?: number): ReviewReaction | null {
726
- return (this.draft.reactions ?? []).find((r) => sameSpot(r, view, tile)) ?? null
727
- }
728
-
729
- /** a reaction's toggle: sets that status, or clears it when it is already the one */
730
- react(view: number, tile: number | undefined, status: ReviewStatus): void {
731
- const cur = this.reactionOf(view, tile)
732
- this.putReaction(view, tile, { ...cur, status: cur?.status === status ? undefined : status, comment: cur?.comment ?? '' })
733
- }
734
-
735
- setReactionComment(view: number, tile: number | undefined, comment: string): void {
736
- this.putReaction(view, tile, { ...this.reactionOf(view, tile), comment })
737
- }
738
-
739
- /** an option's stars; the same number again clears them */
740
- setStars(view: number, n: number): void {
741
- const cur = this.reactionOf(view)
742
- this.putReaction(view, undefined, { ...cur, comment: cur?.comment ?? '', stars: cur?.stars === n ? undefined : n })
743
- }
744
-
745
- removeReaction(view: number, tile: number | undefined): void {
746
- this.putReaction(view, tile, { comment: '' })
747
- }
748
-
749
- /** « pick »: that option is his answer, sent at once as an approval; his stars and words go with it */
750
- async choose(view: number): Promise<void> {
751
- if (!this.choice) return
752
- this.edit((d) => ({ ...d, pick: view }))
753
- await this.submit('approved')
754
- }
755
-
756
- /** the reactions that go to the agent with the verdict, in the card's order */
757
- get outgoingReactions(): ReviewReaction[] {
758
- return [...(this.draft.reactions ?? [])].sort((a, b) => a.view - b.view || (a.tile ?? -1) - (b.tile ?? -1))
759
- }
760
-
761
- private putReaction(view: number, tile: number | undefined, r: { status?: ReviewStatus | undefined; comment: string; stars?: number | undefined }): void {
762
- const next: ReviewReaction = { view, ...(tile !== undefined ? { tile } : {}), ...(r.status ? { status: r.status } : {}), comment: r.comment, ...(r.stars ? { stars: r.stars } : {}) }
763
- const empty = !r.status && r.comment === '' && !r.stars
764
- this.edit((d) => {
765
- const rest = (d.reactions ?? []).filter((q) => !sameSpot(q, view, tile))
766
- return { ...d, reactions: empty ? rest : [...rest, next] }
767
- })
456
+ toggleMarks(): void {
457
+ this.marksOn = !this.marksOn
768
458
  }
769
459
 
770
- /** the open view's clip identity (a clip, or a sound on a row), empty when it shows images */
771
- get clipKey(): string {
772
- const x = this.open
773
- return x && this.playableAt(this.view) ? `${x.item.id}#${this.view}` : ''
460
+ setView(i: number): void {
461
+ if (this.card) this.card.setView(i)
462
+ else this.pendingView = i
774
463
  }
775
464
 
776
- /** a row's ▶: that option plays with its sound, the one playing before it stops; again, it pauses */
777
- listen(i: number): void {
778
- this.setView(i)
779
- const c = this.clipOf(i)
780
- if (c.paused) c.listen()
781
- else c.pause()
782
- }
465
+ // ── his drafts, kept in the browser ──
783
466
 
784
- /** the clock of a clip view of the open card: every clip view plays and steps on its own */
785
- clipOf(view: number): ClipSt {
786
- const id = this.open?.item.id ?? ''
787
- if (id !== this.clipsCard) {
788
- this.clips.clear()
789
- this.clipsCard = id
790
- }
791
- let c = this.clips.get(view)
792
- if (!c) {
793
- c = new ClipSt()
794
- const views = this.open?.item.views ?? []
795
- const v = views[view]
796
- const media = v && !isGallery(v) ? v : undefined
797
- // one thing plays at a time: the first clip of a card loops on its own, the others and every option wait
798
- const first = views.findIndex((w) => !isGallery(w) && w.clip !== undefined)
799
- const still = this.rows || view !== first
800
- if (media?.audio) c.load(`${id}#${view}`, media.audio.duration, SOUND_FPS, true)
801
- else c.load(`${id}#${view}`, media?.clip?.duration ?? 0, media?.clip?.fps ?? 20, still)
802
- this.clips.set(view, c)
803
- }
804
- return c
467
+ storedDraft(head: string): Draft | null {
468
+ return draftOf(kept.get(`${this.prefix}draft.${head}`))
805
469
  }
806
470
 
807
- get clip(): ClipSt {
808
- return this.clipOf(this.view)
471
+ keepDraft(head: string, d: Draft | null): void {
472
+ kept.put(`${this.prefix}draft.${head}`, d === null ? null : JSON.stringify(d))
809
473
  }
810
474
 
811
- get conversation(): ReturnType<typeof conversationOf> {
812
- const t = this.openThread
813
- return t ? conversationOf(t) : []
814
- }
475
+ // ── files ──
815
476
 
816
- /** a thread holds an agent message he has not read: its card shows a dot */
817
- unread(t: Thread): boolean {
818
- return membersOf(t).some((x) => unreadBy(x, 'owner').length > 0)
477
+ /** a card's file at full size; a draft card's carries its frame, so each new frame is a new url */
478
+ fileUrl(id: string, name: string, wip?: { frame: number }): string {
479
+ return `${this.st.url(`/api/review/${id}/${name}`)}${wip ? `?f=${wip.frame}` : ''}`
819
480
  }
820
481
 
821
- get reply(): string {
822
- const id = this.open?.item.id
823
- return id ? (this.replies[id] ?? store.get(`${this.prefix}reply.${id}`) ?? '') : ''
482
+ /** an image at the size the card column draws it (1600 px webp); any other file is the file itself */
483
+ fitUrl(id: string, name: string, wip?: { frame: number }): string {
484
+ return /\.(png|jpe?g|webp)$/i.test(name) ? `${this.st.url(`/api/review/${id}/preview/fit/${name}`)}${wip ? `?f=${wip.frame}` : ''}` : this.fileUrl(id, name, wip)
824
485
  }
825
486
 
826
- setReply(text: string): void {
827
- const id = this.open?.item.id
828
- if (!id) return
829
- this.replies = { ...this.replies, [id]: text }
830
- store.put(`${this.prefix}reply.${id}`, text || null)
487
+ /** an image at the list's size (480 px webp) */
488
+ thumbUrl(id: string, name: string): string {
489
+ return /\.(png|jpe?g|webp)$/i.test(name) ? this.st.url(`/api/review/${id}/preview/thumb/${name}`) : this.fileUrl(id, name)
831
490
  }
832
491
 
833
- /** ⌘Enter or « reply »: his message goes to the open card */
834
- async sendReply(): Promise<void> {
835
- const x = this.open
836
- const text = this.reply.trim()
837
- if (!x || !text || this.busy) return
838
- const id = x.item.id
839
- this.busy = true
840
- this.error = null
841
- try {
842
- await postJson(this.st.url(`/api/review/${id}/reply`), { text })
843
- runInAction(() => {
844
- const { [id]: _, ...rest } = this.replies
845
- this.replies = rest
846
- store.put(`${this.prefix}reply.${id}`, null)
847
- })
848
- void this.refresh()
849
- } catch (e) {
850
- runInAction(() => (this.error = (e as Error).message))
851
- } finally {
852
- runInAction(() => (this.busy = false))
853
- }
492
+ threadImageUrl(id: string, name: string): string {
493
+ return this.st.url(`/api/review/${id}/thread/${name}`)
854
494
  }
855
495
 
856
- private async markRead(id: string): Promise<void> {
857
- if (this.reading.has(id)) return
858
- this.reading.add(id)
496
+ /** the card's folder, or one of its files, shown in the Finder of the machine the hub runs on */
497
+ async reveal(id: string, file?: string): Promise<void> {
859
498
  try {
860
- await postJson(this.st.url(`/api/review/${id}/read`), {})
861
- void this.refresh()
499
+ await postJson(this.st.url(`/api/review/${id}/reveal`), file ? { file } : {})
862
500
  } catch (e) {
863
- runInAction(() => (this.error = (e as Error).message))
864
- } finally {
865
- this.reading.delete(id)
501
+ runInAction(() => this.card && (this.card.error = (e as Error).message))
866
502
  }
867
503
  }
868
504
 
869
- toggleMarks(): void {
870
- this.marksOn = !this.marksOn
871
- }
872
-
873
- /** a rectangle picked: its view comes on screen, and on a clip its frame, paused; `focus` (a click on it on the
874
- * image) puts the cursor in its note box */
875
- pickRect(i: number | null, focus = false): void {
876
- this.rect = i
877
- this.noteFocus = focus ? i : null
878
- if (i === null) return
879
- const r = this.draft.rects[i]
880
- this.view = r?.view ?? 0
881
- if (r?.t === undefined || !this.clipKey) return
882
- this.clip.seek(r.t)
883
- }
884
-
885
- /** the note box took the focus it was asked */
886
- noteFocused(): void {
887
- this.noteFocus = null
888
- }
889
-
890
- setRectComment(i: number, comment: string): void {
891
- this.edit((d) => ({ ...d, rects: d.rects.map((r, j) => (j === i ? { ...r, comment } : r)) }))
892
- }
893
-
894
- removeRect(i: number): void {
895
- this.edit((d) => ({ ...d, rects: d.rects.filter((_, j) => j !== i) }))
896
- this.rect = null
897
- this.noteFocus = null
898
- }
899
-
900
- setComment(comment: string): void {
901
- this.edit((d) => ({ ...d, comment }))
505
+ /** the open card as one paste a fresh agent session in any repo acts on: what it is, its repo, the command that shows
506
+ * it whole, its link here and on the phone (C) */
507
+ async copyCard(): Promise<void> {
508
+ const v = this.card?.data
509
+ const item = this.card?.headItem
510
+ if (!v || !item) return
511
+ const w = this.spec?.where
512
+ const here = typeof location === 'undefined' ? (w?.open ?? '') : `${location.origin}${location.pathname}${location.search}`
513
+ const text = pasteBlock(item, STATUS_LABEL[v.status], {
514
+ root: w?.root ?? '<the repo>',
515
+ open: `${here}#page:review:${v.head}`,
516
+ phone: w?.phone ? `${w.phone}#page:review:${v.head}` : null,
517
+ })
518
+ await this.copied(text, `copied for an agent: title, repo, sk review show, ${w?.phone ? 'links' : 'link'}`)
902
519
  }
903
520
 
904
- /** back to what was sent */
905
- dropDraft(): void {
906
- const x = this.open
907
- if (!x) return
908
- const { [x.item.id]: _, ...rest } = this.drafts
909
- this.drafts = rest
910
- store.put(`${this.prefix}draft.${x.item.id}`, null)
911
- this.rect = null
521
+ /** one cell's id, for an agent to name it */
522
+ async copyId(id: string): Promise<void> {
523
+ await this.copied(id, `copied ${id}`)
912
524
  }
913
525
 
914
- /** V, F, R, A: the draft goes to the card's thread as the owner's verdict, through the server */
915
- async submit(status: ReviewStatus): Promise<void> {
916
- const x = this.open
917
- if (!x || this.busy) return
918
- if (x.item.origin.by !== 'agent') {
919
- this.error = 'this item was raised, not shown by an agent: a word on it goes in a reply'
920
- return
921
- }
922
- if (x.item.wip) {
923
- this.error = 'a draft card: the verdict comes once its agent makes it ready; a word goes in a reply'
924
- return
925
- }
926
- const id = x.item.id
927
- const d = this.draft
928
- this.busy = true
929
- this.error = null
930
- try {
931
- const pick = isChoice(x.item) && isApproved(status) && d.pick !== undefined ? { pick: d.pick } : {}
932
- const m = await postJson<Message>(this.st.url(`/api/review/${id}/feedback`), { status, comment: d.comment, rects: d.rects, reactions: d.reactions ?? [], ...pick })
933
- runInAction(() => {
934
- // the verdict shows at once: the list of every card comes back after it
935
- const r = this.list
936
- if (r) this.list = { ...r, items: r.items.map((y) => (y.item.id === id ? { ...y, thread: [...y.thread, m] } : y)) }
937
- const { [id]: _, ...rest } = this.drafts
938
- this.drafts = rest
939
- store.put(`${this.prefix}draft.${id}`, null)
940
- })
941
- void this.refresh()
942
- // the tree's count of what waits on the owner moves at once, and so does the project list's pill
943
- void this.st.cols.poll(true)
944
- void this.st.home.projects.load()
945
- } catch (e) {
946
- runInAction(() => (this.error = (e as Error).message))
947
- } finally {
948
- runInAction(() => (this.busy = false))
949
- }
526
+ private async copied(text: string, said: string): Promise<void> {
527
+ const ok = await copyText(text)
528
+ runInAction(() => {
529
+ this.toast = ok ? said : 'the browser refused the copy'
530
+ if (this.toastTimer !== null) clearTimeout(this.toastTimer)
531
+ this.toastTimer = setTimeout(() => runInAction(() => (this.toast = null)), 2600)
532
+ })
950
533
  }
951
534
 
952
535
  /** the page's keys, as the atelier takes its own: true when it used the key. V approves, F ok with a fix, R rejects,
953
- * A archives, N the next waiting card, C copies the card for an agent, M the rings, Delete the picked rectangle; on a clip Space plays, ← → a frame
954
- * (a sound: two seconds); on option rows 1 to 9 play that row, ⇧1 to ⇧5 score the row playing, P picks it. A digit is
955
- * read from its physical key (`code`), so ⇧ and an AZERTY keyboard read the same */
536
+ * A archives, N the next waiting card, C copies the card for an agent, M the rings, ↑ ↓ the list; the card takes
537
+ * the rest (ThreadSt.key). A digit is read from its physical key (`code`), so ⇧ and an AZERTY keyboard read the same */
956
538
  key(e: Pick<KeyboardEvent, 'key' | 'shiftKey'> & { code?: string }): boolean {
539
+ const card = this.card
540
+ if (card?.key(e)) return true
957
541
  const k = e.key.toLowerCase()
958
- const digit = Number(/^Digit([1-9])$/.exec(e.code ?? '')?.[1] ?? (/^[1-9]$/.test(e.key) ? e.key : 0))
959
- const sound = this.openView?.audio !== undefined
960
- if (this.rows && digit > 0 && !e.shiftKey) {
961
- if (digit <= (this.open?.item.views.length ?? 0)) this.listen(digit - 1)
962
- } else if (this.choice && this.rows && digit > 0 && e.shiftKey) {
963
- if (digit <= STARS) this.setStars(this.view, digit)
964
- } else if (this.choice && k === 'p') void this.choose(this.view)
965
- else if (this.clipKey && e.key === ' ') {
966
- if (this.clip.paused && this.rows) this.clip.listen()
967
- else this.clip.toggle()
968
- } else if (this.clipKey && sound && (e.key === 'ArrowLeft' || e.key === 'ArrowRight')) this.clip.jump(this.clip.time + (e.key === 'ArrowRight' ? SOUND_JUMP : -SOUND_JUMP))
969
- else if (this.clipKey && (e.key === 'ArrowLeft' || e.key === 'ArrowRight')) this.clip.step(e.key === 'ArrowRight' ? 1 : -1)
970
- else if (e.key === 'ArrowUp' || e.key === 'ArrowDown') this.move(e.key === 'ArrowDown' ? 1 : -1)
971
- else if (k === 'v') void this.submit('approved')
972
- else if (k === 'f') void this.submit('approved-with-fix')
973
- else if (k === 'r') void this.submit('rejected')
974
- else if (k === 'a') void this.submit('archived')
542
+ if (e.key === 'ArrowUp' || e.key === 'ArrowDown') this.move(e.key === 'ArrowDown' ? 1 : -1)
543
+ else if (k === 'v') void card?.submit('approved')
544
+ else if (k === 'f') void card?.submit('approved-with-fix')
545
+ else if (k === 'r') void card?.submit('rejected')
546
+ else if (k === 'a') void card?.submit('archived')
975
547
  else if (k === 'n') this.nextPending()
976
548
  else if (k === 'c') void this.copyCard()
977
549
  else if (k === 'm') this.toggleMarks()
978
- else if ((e.key === 'Delete' || e.key === 'Backspace') && this.rect !== null) this.removeRect(this.rect)
979
550
  else return false
980
551
  return true
981
552
  }