rvlib-shipkit 2.10.0 → 2.12.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 (73) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/package.json +1 -1
  3. package/src/cli/cmd_Media.ts +253 -0
  4. package/src/cli/cmd_Review.ts +4 -0
  5. package/src/cli/cmd_Trailer.ts +4 -0
  6. package/src/cli/family-pages.ts +1 -0
  7. package/src/cli/registry.ts +2 -0
  8. package/src/collections/pings.ts +6 -4
  9. package/src/core/app-icon.ts +17 -4
  10. package/src/core/scratch-objects.ts +56 -0
  11. package/src/core/trace-audit.ts +13 -1
  12. package/src/home/home-paths.ts +4 -0
  13. package/src/home/home-routes.ts +36 -2
  14. package/src/home/hubs.ts +5 -0
  15. package/src/home/inbox-shape.ts +188 -0
  16. package/src/home/inbox.ts +104 -0
  17. package/src/home/run-daemon.ts +12 -2
  18. package/src/home/serve-web.ts +161 -16
  19. package/src/ledger/git-scan.ts +73 -25
  20. package/src/ledger/repo-view.ts +2 -22
  21. package/src/media-kinds.ts +14 -0
  22. package/src/media-store/content.ts +61 -0
  23. package/src/media-store/daemon.ts +91 -0
  24. package/src/media-store/db.ts +74 -0
  25. package/src/media-store/fact.ts +9 -0
  26. package/src/media-store/hand.ts +58 -0
  27. package/src/media-store/kind.ts +44 -0
  28. package/src/media-store/purge.ts +139 -0
  29. package/src/media-store/put.ts +120 -0
  30. package/src/media-store/remote.ts +93 -0
  31. package/src/media-store/space.ts +167 -0
  32. package/src/media-store/sync.ts +101 -0
  33. package/src/media-store/upload.ts +98 -0
  34. package/src/repo-config.ts +4 -0
  35. package/src/review/anim.ts +6 -5
  36. package/src/review/cells.ts +5 -1
  37. package/src/review/media-kind.ts +84 -0
  38. package/src/review/media-read.ts +48 -0
  39. package/src/review/model.ts +22 -1
  40. package/src/review/previews.ts +41 -12
  41. package/src/review/routes.ts +32 -8
  42. package/src/review/store.ts +102 -40
  43. package/src/review/trailer-desk.ts +79 -46
  44. package/src/review/trailer-media.ts +181 -0
  45. package/src/review/trailer-routes.ts +5 -2
  46. package/src/review/trailer-shots.ts +89 -0
  47. package/src/serve/hub-app/cols-svc.ts +12 -1
  48. package/src/serve/hub-app/home-st.ts +39 -9
  49. package/src/serve/hub-app/home.html +2 -1
  50. package/src/serve/hub-app/hub-app.tsx +7 -23
  51. package/src/serve/hub-app/icons.tsx +2 -0
  52. package/src/serve/hub-app/inbox-st.ts +144 -0
  53. package/src/serve/hub-app/inbox-view.tsx +205 -0
  54. package/src/serve/hub-app/inbox.css +73 -0
  55. package/src/serve/hub-app/item-view.tsx +19 -0
  56. package/src/serve/hub-app/keys.ts +4 -3
  57. package/src/serve/hub-app/palette-st.ts +2 -1
  58. package/src/serve/hub-app/project-list.tsx +1 -0
  59. package/src/serve/hub-app/projects-svc.ts +1 -1
  60. package/src/serve/hub-app/repo-st.ts +1 -1
  61. package/src/serve/hub-app/review/review-st.ts +15 -3
  62. package/src/serve/hub-app/review/review-thread.tsx +5 -4
  63. package/src/serve/hub-app/review.css +1 -1
  64. package/src/serve/hub-app/test-view.tsx +9 -2
  65. package/src/serve/hub-app/tests-svc.ts +16 -1
  66. package/src/serve/hub-runtime.ts +9 -4
  67. package/src/serve/resources-wire.ts +48 -0
  68. package/src/serve/serve-hub.ts +11 -7
  69. package/src/serve/warm-cell.ts +6 -1
  70. package/src/trailer/footage.ts +6 -2
  71. package/src/trailer/passage.ts +8 -3
  72. package/src/trailer/prune.ts +6 -10
  73. package/src/trailer/shelf.ts +16 -0
@@ -0,0 +1,89 @@
1
+ // the shots folders of the trailer kind (wiki build/trailer.md, Renders in the media store): each build's shelf
2
+ // `out/<cut>-shots/` and each kept version's `versions/<v>/shots/`. Their facts sit in the folder's own `.media.json`,
3
+ // which a build's new shelf drops with the old files. The shelf of each trailer's newest build stays on the disk
4
+ import { existsSync, readdirSync, renameSync, statSync, writeFileSync } from 'node:fs'
5
+ import { join, relative } from 'node:path'
6
+ import { factOf, mediaKey } from '../media-store/content.ts'
7
+ import type { MediaRow } from '../media-store/kind.ts'
8
+ import { fetchBack } from '../media-store/remote.ts'
9
+ import { SHOT_FACTS, shotFacts } from '../trailer/shelf.ts'
10
+ import { TRAILER_KIND, trailerIds } from './trailer-desk.ts'
11
+
12
+ const SHELF_RE = /^(.+)-shots$/
13
+
14
+ export interface ShotFolder {
15
+ /** the folder, relative to the repo: the item of its rows */
16
+ item: string
17
+ trailer: string
18
+ /** the cut it shelves, or the version it keeps */
19
+ cut: string
20
+ version: boolean
21
+ /** when it was made: a build makes its shelf anew, a keep its version's; its facts file moves no clock */
22
+ born: number
23
+ }
24
+
25
+ /** every shots folder of the repo's trailers */
26
+ export function shotFolders(root: string): ShotFolder[] {
27
+ const out: ShotFolder[] = []
28
+ for (const id of trailerIds(root)) {
29
+ const dir = join(root, 'trailer', id)
30
+ const add = (path: string, cut: string, version: boolean): void => {
31
+ const s = statSync(path, { throwIfNoEntry: false })
32
+ if (s?.isDirectory()) out.push({ item: relative(root, path), trailer: id, cut, version, born: s.birthtimeMs })
33
+ }
34
+ for (const f of existsSync(join(dir, 'out')) ? readdirSync(join(dir, 'out')) : []) {
35
+ const m = SHELF_RE.exec(f)
36
+ if (m) add(join(dir, 'out', f), m[1]!, false)
37
+ }
38
+ for (const v of existsSync(join(dir, 'versions')) ? readdirSync(join(dir, 'versions')) : []) if (/^v\d+$/.test(v)) add(join(dir, 'versions', v, 'shots'), v, true)
39
+ }
40
+ return out
41
+ }
42
+
43
+ /** a folder's rows: its facts filled while `take()` allows, written back when they moved */
44
+ export async function shotRows(root: string, f: ShotFolder, take: () => boolean): Promise<MediaRow[]> {
45
+ const folder = join(root, f.item)
46
+ const facts = shotFacts(folder)
47
+ let moved = false
48
+ const rows: MediaRow[] = []
49
+ const names = new Set([...Object.keys(facts), ...readdirSync(folder).filter((n) => !n.startsWith('.'))])
50
+ for (const name of [...names].sort()) {
51
+ const size = statSync(join(folder, name), { throwIfNoEntry: false })?.size
52
+ let fact = facts[name]
53
+ if (size !== undefined && fact?.size !== size) {
54
+ if (!take()) continue
55
+ fact = facts[name] = await factOf(join(folder, name))
56
+ moved = true
57
+ }
58
+ if (fact) rows.push({ item: f.item, name, fact, local: size !== undefined })
59
+ }
60
+ if (moved) {
61
+ const file = join(folder, SHOT_FACTS)
62
+ writeFileSync(`${file}.${process.pid}.tmp`, JSON.stringify(facts))
63
+ renameSync(`${file}.${process.pid}.tmp`, file)
64
+ }
65
+ return rows
66
+ }
67
+
68
+ /** the shelf the purge keeps: per trailer, the one its newest build wrote */
69
+ export function newestShelves(folders: readonly ShotFolder[]): Set<string> {
70
+ const best = new Map<string, ShotFolder>()
71
+ for (const f of folders) if (!f.version && (best.get(f.trailer)?.born ?? -1) < f.born) best.set(f.trailer, f)
72
+ return new Set([...best.values()].map((f) => f.item))
73
+ }
74
+
75
+ /** every file of a shots folder on the disk, the ones the purge let go fetched back first; the names that came back
76
+ * missing are returned, never dropped in silence */
77
+ export async function shotsBack(root: string, folder: string): Promise<string[]> {
78
+ const facts = shotFacts(folder)
79
+ const item = relative(root, folder)
80
+ const lost: string[] = []
81
+ await Promise.all(
82
+ Object.entries(facts).map(async ([name, f]) => {
83
+ const path = join(folder, name)
84
+ if (!(await fetchBack(path, mediaKey(TRAILER_KIND, f, name), f, { store: root, item, name }))) lost.push(name)
85
+ }),
86
+ )
87
+ return lost.sort()
88
+ }
89
+
@@ -53,6 +53,8 @@ export class ColsSvc {
53
53
  private last: Answer | null = null
54
54
  private keptCat: string | null | undefined = undefined
55
55
  private restoring: Promise<void> | null = null
56
+ /** the ETag of the last answer taken */
57
+ private tag: string | null = null
56
58
  actErr = ''
57
59
  remarkDraft = ''
58
60
  proofDraft = ''
@@ -64,7 +66,7 @@ export class ColsSvc {
64
66
  private timer: ReturnType<typeof setInterval> | null = null
65
67
 
66
68
  constructor(private st: RepoSt) {
67
- makeAutoObservable<this, 'st' | 'timer' | 'keptAt' | 'restoring' | 'readKept' | 'last' | 'keptCat'>(this, { st: false, timer: false, keptAt: false, restoring: false, readKept: false, last: false, keptCat: false })
69
+ makeAutoObservable<this, 'st' | 'timer' | 'keptAt' | 'restoring' | 'readKept' | 'last' | 'keptCat' | 'tag'>(this, { st: false, timer: false, keptAt: false, restoring: false, readKept: false, last: false, keptCat: false, tag: false })
68
70
  }
69
71
 
70
72
  /** one check's row of the plan, null when no plan covers it */
@@ -135,7 +137,16 @@ export class ColsSvc {
135
137
  try {
136
138
  const r = await reach(this.st.url(fresh ? '/api/resources.json?fresh=1' : '/api/resources.json'))
137
139
  if (!r.ok) throw new Error(await r.text())
140
+ // the browser revalidates the tag and hands back what it holds:
141
+ // the same tag is the same answer, so nothing is parsed or swapped
142
+ const tag = r.headers.get('ETag')
143
+ if (tag != null && tag === this.tag && this.loaded) {
144
+ await r.body?.cancel()
145
+ runInAction(() => { this.fetchErr = null })
146
+ return
147
+ }
138
148
  const j = (await r.json()) as Answer
149
+ this.tag = tag
139
150
  runInAction(() => {
140
151
  this.colMeta = j.collections
141
152
  this.fetched = j.resources
@@ -20,6 +20,7 @@ import { PaletteSt } from './palette-st.ts'
20
20
  import { PlannedSt } from './planned-st.ts'
21
21
  import { ActivitySt } from './activity-st.ts'
22
22
  import { InsightsSt } from './insights-st.ts'
23
+ import { InboxSt } from './inbox-st.ts'
23
24
  import { ProjectsSvc } from './projects-svc.ts'
24
25
  import { parseFilter, RepoSt } from './repo-st.ts'
25
26
  import { openSection, repoSections, sectionOfRepo } from './repo-sections.ts'
@@ -27,11 +28,11 @@ import { openSection, repoSections, sectionOfRepo } from './repo-sections.ts'
27
28
  /** the longest one repo's read ahead holds the next one back */
28
29
  export const PREFETCH_WAIT_MS = 10_000
29
30
 
30
- /** what the page shows: the machine overview, the plan, the activity, the insights, the archived repos, or one repo */
31
- export type Page = 'overview' | 'planned' | 'activity' | 'insights' | 'archived' | 'repo'
31
+ /** what the page shows: the machine overview, the inbox, the plan, the activity, the insights, the archived repos, or one repo */
32
+ export type Page = 'overview' | 'inbox' | 'planned' | 'activity' | 'insights' | 'archived' | 'repo'
32
33
 
33
34
  /** the address of each page of the home that is no repo's */
34
- export const PLACE_PATH = { overview: '/', planned: '/planned', activity: '/activity', insights: '/insights', archived: '/archived' } as const
35
+ export const PLACE_PATH = { overview: '/', inbox: '/inbox', planned: '/planned', activity: '/activity', insights: '/insights', archived: '/archived' } as const
35
36
 
36
37
  /** where a repo's hub answers on the home */
37
38
  export const repoBase = (name: string): string => `/r/${encodeURIComponent(name)}`
@@ -49,6 +50,7 @@ export const checkAddress = (repo: string, check: string): string =>
49
50
  export function routeOf(pathname: string): { page: Page; repo: string | null } {
50
51
  const m = /^\/r\/([^/]+)/.exec(pathname)
51
52
  if (m != null) return { page: 'repo', repo: decodeURIComponent(m[1]!) }
53
+ if (/^\/inbox\/?$/.test(pathname)) return { page: 'inbox', repo: null }
52
54
  if (/^\/planned\/?$/.test(pathname)) return { page: 'planned', repo: null }
53
55
  if (/^\/activity\/?$/.test(pathname)) return { page: 'activity', repo: null }
54
56
  if (/^\/insights\/?$/.test(pathname)) return { page: 'insights', repo: null }
@@ -78,6 +80,8 @@ export class HomeSt {
78
80
  /** what every repo committed and holds, polled while it is the page */
79
81
  activity: ActivitySt
80
82
  insights: InsightsSt
83
+ /** everything that waits on the owner in every repo, polled while it is the page */
84
+ inbox: InboxSt
81
85
  /** the one picker, cmd+j */
82
86
  palette: PaletteSt
83
87
  /** the widths of the project list and a repo's sidebar */
@@ -106,12 +110,13 @@ export class HomeSt {
106
110
  this.planned = new PlannedSt(this)
107
111
  this.activity = new ActivitySt(this)
108
112
  this.insights = new InsightsSt(this)
113
+ this.inbox = new InboxSt(this)
109
114
  this.palette = new PaletteSt(this)
110
115
  this.layout = new LayoutSt()
111
116
  this.dock = new DockSt(this)
112
117
  this.machine = o.home ? new MachineSt(this, o) : null
113
118
  this.page = o.home ? 'overview' : 'repo'
114
- makeAutoObservable<this, 'disposers' | 'onUrl' | 'prefetching' | 'base'>(this, { base: false, machine: false, projects: false, planned: false, activity: false, insights: false, palette: false, layout: false, theme: false, dock: false, repos: observableShallow, disposers: false, onUrl: false, prefetching: false })
119
+ makeAutoObservable<this, 'disposers' | 'onUrl' | 'prefetching' | 'base'>(this, { base: false, machine: false, projects: false, planned: false, activity: false, insights: false, inbox: false, palette: false, layout: false, theme: false, dock: false, repos: observableShallow, disposers: false, onUrl: false, prefetching: false })
115
120
  const m = this.machine
116
121
  if (m != null) {
117
122
  this.projects.onSelect = (name) => this.select(name)
@@ -147,6 +152,7 @@ export class HomeSt {
147
152
 
148
153
  get title(): string {
149
154
  if (this.page === 'overview') return 'home'
155
+ if (this.page === 'inbox') return this.inbox.count > 0 ? `inbox · ${this.inbox.count}` : 'inbox'
150
156
  if (this.page === 'planned') return 'planned'
151
157
  if (this.page === 'activity') return 'activity'
152
158
  if (this.page === 'insights') return 'insights'
@@ -193,6 +199,7 @@ export class HomeSt {
193
199
  this.machine?.stop()
194
200
  this.planned.stop()
195
201
  this.activity.stop()
202
+ this.inbox.stop()
196
203
  this.dock.dispose()
197
204
  for (const r of this.repos.values()) r.dispose()
198
205
  }
@@ -216,7 +223,12 @@ export class HomeSt {
216
223
  /** a check: its own page in its repo, in place. The selection is written
217
224
  * before the repo is shown, so the one history entry already names it */
218
225
  openCheck(repo: string, check: string): void {
219
- this.repo(repo).cols.select('checks', `check:${check}`)
226
+ this.openItem(repo, 'checks', `check:${check}`)
227
+ }
228
+
229
+ /** one row of a repo: its own page in its repo, in place, as one history entry */
230
+ openItem(repo: string, col: string, id: string): void {
231
+ this.repo(repo).cols.select(col, id)
220
232
  this.show('repo', repo, 'push')
221
233
  }
222
234
 
@@ -232,9 +244,20 @@ export class HomeSt {
232
244
  const u = new URL(path, 'http://home.invalid')
233
245
  const r = routeOf(u.pathname)
234
246
  if (r.page === 'planned') this.planned.query = u.searchParams.get('q') ?? ''
247
+ if (r.page === 'inbox') this.inbox.fromSearch(u.search)
235
248
  this.show(r.page, r.repo, 'push')
236
249
  }
237
250
 
251
+ /** the inbox on one item, or on its list: an item is a history entry of its own, so back returns to the list */
252
+ openInbox(item: { repo: string; id: string } | null): void {
253
+ const was = this.inbox.open
254
+ if (item != null) this.repo(item.repo)
255
+ this.inbox.open = item
256
+ const same = was?.repo === item?.repo && was?.id === item?.id
257
+ if (this.page === 'inbox' && same) return
258
+ this.show('inbox', null, item != null && this.page === 'inbox' ? 'push' : this.page === 'inbox' ? 'replace' : 'push')
259
+ }
260
+
238
261
  /** the url decides the page: the first load, back, forward and a hand
239
262
  * edited address all land here */
240
263
  fromUrl(): void {
@@ -246,6 +269,9 @@ export class HomeSt {
246
269
  // an address from before repo pages had their own path (`/#<repo>`)
247
270
  const legacy = r.page === 'overview' ? currentHash() : ''
248
271
  if (legacy !== '') return this.show('repo', legacy, 'replace')
272
+ // on a phone the home opens on the inbox
273
+ if (r.page === 'overview' && this.inbox.phone && location.search === '') return this.show('inbox', null, 'replace')
274
+ if (r.page === 'inbox') this.inbox.fromSearch(location.search)
249
275
  if (r.page === 'planned') this.planned.query = new URLSearchParams(location.search).get('q') ?? ''
250
276
  if (r.page === 'repo') this.repo(r.repo!).filter = parseFilter(location.search)
251
277
  this.show(r.page, r.repo, 'none')
@@ -259,7 +285,7 @@ export class HomeSt {
259
285
  const prevPage = this.page
260
286
  const next = page === 'repo' && repo != null ? this.repo(repo) : null
261
287
  // the page already shown is never a second history entry
262
- if (how === 'push' && page === this.page && next === prev && page !== 'planned') how = 'none'
288
+ if (how === 'push' && page === this.page && next === prev && page !== 'planned' && page !== 'inbox') how = 'none'
263
289
  if (prev != null && prev !== next) prev.pause()
264
290
  next?.markSeen()
265
291
  this.page = page
@@ -269,13 +295,17 @@ export class HomeSt {
269
295
  this.projects.away = next == null
270
296
  this.projects.place = page === 'repo' || page === 'archived' ? null : page
271
297
  if (how !== 'none') {
272
- const to = next != null ? `${repoPage(next.key)}${next.search}${next.hash}` : page === 'planned' ? this.planned.address : page === 'activity' || page === 'insights' || page === 'archived' ? PLACE_PATH[page] : '/'
273
- if (how === 'push') history.pushState(null, '', to)
274
- else history.replaceState(null, '', to)
298
+ const to = next != null ? `${repoPage(next.key)}${next.search}${next.hash}` : page === 'planned' ? this.planned.address : page === 'inbox' ? `${PLACE_PATH.inbox}${this.inbox.search}` : page === 'activity' || page === 'insights' || page === 'archived' ? PLACE_PATH[page] : '/'
299
+ // an inbox item marks its entry, so its back button goes back rather than forward to the list
300
+ const state = page === 'inbox' && this.inbox.open != null ? { inbox: 'item' } : null
301
+ if (how === 'push') history.pushState(state, '', to)
302
+ else history.replaceState(state, '', to)
275
303
  }
276
304
  if (page === 'planned') this.planned.start()
277
305
  else this.planned.stop()
278
306
  if (page === 'insights' && prevPage !== 'insights') this.insights.start()
307
+ if (page === 'inbox') this.inbox.start()
308
+ else this.inbox.stop()
279
309
  if (page === 'activity') this.activity.start()
280
310
  else this.activity.stop()
281
311
  if (next != null && next !== prev && this.machine?.data != null) void this.machine.hub(next.key, 'ensure')
@@ -2,7 +2,7 @@
2
2
  <html lang="en">
3
3
  <head>
4
4
  <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
6
6
  <title>home</title>
7
7
  <link rel="stylesheet" href="./hub.css" />
8
8
  <link rel="stylesheet" href="./project-list.css" />
@@ -15,6 +15,7 @@
15
15
  <link rel="stylesheet" href="./dock.css" />
16
16
  <link rel="stylesheet" href="./controls.css" />
17
17
  <link rel="stylesheet" href="./review.css" />
18
+ <link rel="stylesheet" href="./inbox.css" />
18
19
  </head>
19
20
  <body data-home>
20
21
  <div id="root"></div>
@@ -11,18 +11,16 @@ import { reaction, runInAction } from 'mobx'
11
11
  import { observer } from 'mobx-react-lite'
12
12
  import { StrictMode, useEffect, useLayoutEffect, useRef } from 'react'
13
13
  import { createRoot } from 'react-dom/client'
14
- import { ColCard, StatusCard } from './col-card.tsx'
14
+ import { StatusCard } from './col-card.tsx'
15
15
  import { AskTable, CheckTable, ItemTable, SecretTable } from './col-tables-view.tsx'
16
- import { WIKIS, WikisView } from './wikis-view.tsx'
17
- import { ComfyOverlay, ComfyView } from './comfy-view.tsx'
16
+ import { ComfyOverlay } from './comfy-view.tsx'
17
+ import { ItemView } from './item-view.tsx'
18
+ import { InboxView } from './inbox-view.tsx'
18
19
  import type { Filter, RepoSt } from './repo-st.ts'
19
20
  import { HomeSt, PLACE_PATH } from './home-st.ts'
20
21
  import { hashFor } from './hash-route.ts'
21
- import { TimelineView } from './timeline-view.tsx'
22
22
  import { HeaderBar, notUp } from './header-bar.tsx'
23
23
  import { FOLLOW_KEY } from './timeline-chart.tsx'
24
- import { CheckCard } from './check-view.tsx'
25
- import { TestCard } from './test-view.tsx'
26
24
  import { TestsPage } from './tests-view.tsx'
27
25
  import { AssetStage, CatGrid, InfoChips, MediaTopbar, ToolsBar, VariantsBar } from './media-view.tsx'
28
26
  import { Sidebar } from './sidebar.tsx'
@@ -81,22 +79,7 @@ const AssetRemarks = observer(({ app }: { app: RepoSt }) => {
81
79
  const Main = observer(({ app }: { app: RepoSt }) => {
82
80
  const m = app.media
83
81
  const errs = m.errors.length > 0 ? <div className="errs">{m.errors.join('\n')}</div> : null
84
- if (app.sel?.t === 'item') return (
85
- <main>
86
- {errs}
87
- {app.sel.col === WIKIS
88
- ? <WikisView app={app} id={app.sel.id} />
89
- : app.sel.col === 'comfy'
90
- ? <ComfyView app={app} id={app.sel.id} />
91
- : app.sel.col === 'checks'
92
- ? <div className="stagewrap"><CheckCard app={app} id={app.sel.id} /></div>
93
- : app.sel.col === 'tests'
94
- ? <div className="stagewrap"><TestCard app={app} id={app.sel.id} /></div>
95
- : app.sel.col === 'runs'
96
- ? <div className="stagewrap"><TimelineView app={app} /></div>
97
- : <div className="stagewrap"><ColCard app={app} col={app.sel.col} id={app.sel.id} /></div>}
98
- </main>
99
- )
82
+ if (app.sel?.t === 'item') return <main>{errs}<ItemView app={app} col={app.sel.col} id={app.sel.id} /></main>
100
83
  if (app.sel?.t === 'col') return (
101
84
  <main>
102
85
  {errs}
@@ -218,7 +201,7 @@ function onKey(e: KeyboardEvent): void {
218
201
  if (pk.t === 'picker') home.palette.toggle()
219
202
  else if (pk.t === 'dock') home.dock.cycle()
220
203
  else if (pk.t === 'rail') home.layout.toggleRail()
221
- else if (pk.t === 'home' || pk.t === 'planned' || pk.t === 'activity' || pk.t === 'insights') {
204
+ else if (pk.t === 'home' || pk.t === 'inbox' || pk.t === 'planned' || pk.t === 'activity' || pk.t === 'insights') {
222
205
  home.palette.close()
223
206
  if (home.machine != null) home.navigate(PLACE_PATH[pk.t === 'home' ? 'overview' : pk.t])
224
207
  } else if (pk.t === 'step') {
@@ -361,6 +344,7 @@ const App = observer(() => {
361
344
  <Panel id="page" minSize={320} className="appcol" style={PANEL}>
362
345
  {home.machine == null ? null : <HomeStrip app={home} />}
363
346
  {home.page === 'overview' ? <Overview app={home} /> : null}
347
+ {home.page === 'inbox' ? <InboxView app={home} /> : null}
364
348
  {home.page === 'planned' ? <PlannedView app={home} /> : null}
365
349
  {home.page === 'activity' ? <ActivityView app={home} /> : null}
366
350
  {home.page === 'insights' ? <InsightsView app={home} /> : null}
@@ -14,6 +14,8 @@ export const ICON = {
14
14
  archived: 'M2.5 4h15v3.5h-15zM4 7.5V16h12V7.5M8 10.5h4',
15
15
  insights: 'M3 16.5h14M5 16.5V11M9 16.5V5M13 16.5V8.5M17 16.5V12',
16
16
  home: 'M3 9.5 10 3.5l7 6M5 8v8.5h10V8M8.5 16.5v-4.5h3v4.5',
17
+ // a tray: what waits on the owner, every repo
18
+ inbox: 'M3 11.5 5.5 4h9l2.5 7.5V16H3zM3 11.5h4.5l1 2h3l1-2H17',
17
19
  planned: 'M5.5 3h9M5.5 17h9M6.5 3c0 4 7 4 7 7s-7 3-7 7M13.5 3c0 4-7 4-7 7s7 3 7 7',
18
20
  browser: 'M10 2.5a7.5 7.5 0 1 0 0 15a7.5 7.5 0 1 0 0-15M2.5 10h15M10 2.5c-3 3-3 12 0 15M10 2.5c3 3 3 12 0 15',
19
21
  window: 'M2.5 4h15v12h-15zM2.5 7.5h15M5 5.75h.01M7 5.75h.01',
@@ -0,0 +1,144 @@
1
+ // the inbox page as state (wiki build/shipkit/home.md, The inbox), a node of the root (home-st.ts): the main list in
2
+ // pages of `GET /api/inbox`, the folded yellow list read once it unfolds, and the item open in place. Polled every few
3
+ // seconds while the page shows and the tab is visible, 304 when nothing moved. An item opens in its repo's own state
4
+ // (RepoSt): a card in that repo's review thread, an ask or a need in its item view, the same components as its hub
5
+ //
6
+ // the one constraint a reader breaks first: the address and the open item move together, through HomeSt.show; `open`
7
+ // only says which item the address names
8
+ import { makeAutoObservable, observableRef, runInAction } from 'mobx'
9
+ import { INBOX_PAGE, openOf, type InboxAnswer, type InboxRow } from '../../home/inbox-shape.ts'
10
+ import { etagLoader } from './review/review-kit.ts'
11
+ import { ownTrouble } from './reach.ts'
12
+ import { ClockSvc } from './clock-svc.ts'
13
+ import type { HomeSt } from './home-st.ts'
14
+
15
+ const POLL_MS = 4000
16
+
17
+ /** below this width the inbox is the phone's: one pane at a time, the list or the item */
18
+ export const INBOX_PHONE_PX = 768
19
+
20
+ export class InboxSt {
21
+ page: InboxAnswer | null = null
22
+ yellowPage: InboxAnswer | null = null
23
+ error = ''
24
+ /** the rows asked of the main list: a page more on « more » */
25
+ shown = INBOX_PAGE
26
+ /** the folded list unfolded: read while it is */
27
+ yellowOpen = false
28
+ /** the item the address names */
29
+ open: { repo: string; id: string } | null = null
30
+ /** on a phone the list or the item, one at a time */
31
+ phone = false
32
+ /** every row's age reads it, ticking while the page shows */
33
+ readonly clock = new ClockSvc()
34
+ private timer: ReturnType<typeof setInterval> | null = null
35
+ private readonly loadMain: () => Promise<InboxAnswer>
36
+ private readonly loadYellow: () => Promise<InboxAnswer>
37
+ private readonly onVisible = (): void => {
38
+ if (document.visibilityState === 'visible' && this.timer != null) void this.poll()
39
+ }
40
+
41
+ constructor(private readonly home: HomeSt) {
42
+ this.loadMain = etagLoader(() => `/api/inbox?limit=${this.shown}`)
43
+ this.loadYellow = etagLoader(() => '/api/inbox?list=yellow&limit=500')
44
+ makeAutoObservable<this, 'home' | 'timer' | 'loadMain' | 'loadYellow' | 'onVisible'>(this, { home: false, timer: false, loadMain: false, loadYellow: false, onVisible: false, clock: false, page: observableRef, yellowPage: observableRef })
45
+ if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
46
+ const mq = window.matchMedia(`(max-width: ${INBOX_PHONE_PX - 1}px)`)
47
+ this.phone = mq.matches
48
+ mq.addEventListener('change', (e) => runInAction(() => (this.phone = e.matches)))
49
+ }
50
+ }
51
+
52
+ get rows(): InboxRow[] {
53
+ return this.page?.rows ?? []
54
+ }
55
+
56
+ get yellowRows(): InboxRow[] {
57
+ return this.yellowPage?.rows ?? []
58
+ }
59
+
60
+ get count(): number {
61
+ return this.page?.counts.main ?? 0
62
+ }
63
+
64
+ get yellowCount(): number {
65
+ return this.page?.counts.yellow ?? 0
66
+ }
67
+
68
+ get more(): number {
69
+ return Math.max(0, (this.page?.total ?? 0) - this.rows.length)
70
+ }
71
+
72
+ /** the row of the open item, from either list; null while the lists have not answered or once it left them */
73
+ get openRow(): InboxRow | null {
74
+ const o = this.open
75
+ if (o == null) return null
76
+ const key = `${o.repo}/${o.id}`
77
+ return this.rows.find((r) => r.key === key) ?? this.yellowRows.find((r) => r.key === key) ?? null
78
+ }
79
+
80
+ /** the address's part after /inbox */
81
+ get search(): string {
82
+ return this.open == null ? '' : `?open=${encodeURIComponent(`${this.open.repo}/${this.open.id}`)}`
83
+ }
84
+
85
+ /** the address read back: the item it names, or the list */
86
+ fromSearch(search: string): void {
87
+ const o = openOf(search)
88
+ // the repo's state is made here, never while a view draws
89
+ if (o != null) this.home.repo(o.repo)
90
+ if (o?.repo !== this.open?.repo || o?.id !== this.open?.id) this.open = o
91
+ }
92
+
93
+ start(): void {
94
+ if (this.timer != null) return
95
+ this.clock.start(10_000)
96
+ void this.poll()
97
+ this.timer = setInterval(() => {
98
+ if (document.visibilityState === 'visible') void this.poll()
99
+ }, POLL_MS)
100
+ document.addEventListener('visibilitychange', this.onVisible)
101
+ }
102
+
103
+ stop(): void {
104
+ if (this.timer != null) clearInterval(this.timer)
105
+ this.timer = null
106
+ this.clock.stop()
107
+ document.removeEventListener('visibilitychange', this.onVisible)
108
+ }
109
+
110
+ async poll(): Promise<void> {
111
+ await Promise.all([
112
+ this.loadMain().then(
113
+ (p) => runInAction(() => {
114
+ if (p !== this.page) this.page = p
115
+ this.error = ''
116
+ }),
117
+ (e: Error) => runInAction(() => (this.error = ownTrouble(e, this.home.machine, (m) => `the inbox cannot be read: ${m}`))),
118
+ ),
119
+ this.yellowOpen ? this.loadYellow().then((p) => runInAction(() => p !== this.yellowPage && (this.yellowPage = p)), () => undefined) : null,
120
+ ])
121
+ }
122
+
123
+ showMore(): void {
124
+ if (this.more === 0) return
125
+ this.shown += INBOX_PAGE
126
+ void this.poll()
127
+ }
128
+
129
+ toggleYellow(): void {
130
+ this.yellowOpen = !this.yellowOpen
131
+ if (this.yellowOpen) void this.poll()
132
+ }
133
+
134
+ /** a row tapped: the item in place, as a history entry */
135
+ pick(row: Pick<InboxRow, 'repo' | 'id'>): void {
136
+ this.home.openInbox({ repo: row.repo, id: row.id })
137
+ }
138
+
139
+ /** back to the list: the entry the item pushed, else the list's own address */
140
+ back(): void {
141
+ if (history.state?.inbox === 'item') history.back()
142
+ else this.home.openInbox(null)
143
+ }
144
+ }