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.
- package/CHANGELOG.md +23 -0
- package/package.json +1 -1
- package/src/cli/cmd_Media.ts +164 -0
- package/src/cli/cmd_Review.ts +2 -1
- package/src/cli/family-pages.ts +1 -0
- package/src/cli/registry.ts +2 -0
- package/src/collections/pings.ts +6 -4
- package/src/core/app-icon.ts +17 -4
- package/src/core/scratch-objects.ts +56 -0
- package/src/core/trace-audit.ts +13 -1
- package/src/home/home-paths.ts +4 -0
- package/src/home/home-routes.ts +36 -2
- package/src/home/hubs.ts +5 -0
- package/src/home/inbox-shape.ts +182 -0
- package/src/home/inbox.ts +48 -0
- package/src/home/run-daemon.ts +12 -2
- package/src/home/serve-web.ts +155 -16
- package/src/ledger/git-scan.ts +73 -25
- package/src/ledger/repo-view.ts +2 -22
- package/src/media-kinds.ts +7 -0
- package/src/media-store/content.ts +51 -0
- package/src/media-store/daemon.ts +91 -0
- package/src/media-store/db.ts +74 -0
- package/src/media-store/fact.ts +9 -0
- package/src/media-store/kind.ts +44 -0
- package/src/media-store/purge.ts +139 -0
- package/src/media-store/remote.ts +93 -0
- package/src/media-store/space.ts +124 -0
- package/src/media-store/sync.ts +101 -0
- package/src/media-store/upload.ts +98 -0
- package/src/repo-config.ts +4 -0
- package/src/review/anim.ts +6 -5
- package/src/review/cells.ts +552 -0
- package/src/review/format.ts +1 -1
- package/src/review/media-kind.ts +84 -0
- package/src/review/media-read.ts +48 -0
- package/src/review/model.ts +43 -5
- package/src/review/previews.ts +153 -0
- package/src/review/routes.ts +105 -47
- package/src/review/store.ts +106 -45
- package/src/review/trailer-desk.ts +79 -46
- package/src/review/trailer-media.ts +163 -0
- package/src/review/trailer-routes.ts +5 -2
- package/src/serve/hub-app/home-st.ts +39 -9
- package/src/serve/hub-app/home.html +2 -1
- package/src/serve/hub-app/hub-app.tsx +7 -23
- package/src/serve/hub-app/icons.tsx +2 -0
- package/src/serve/hub-app/inbox-st.ts +144 -0
- package/src/serve/hub-app/inbox-view.tsx +205 -0
- package/src/serve/hub-app/inbox.css +73 -0
- package/src/serve/hub-app/item-view.tsx +19 -0
- package/src/serve/hub-app/keys.ts +4 -3
- package/src/serve/hub-app/palette-st.ts +2 -1
- package/src/serve/hub-app/project-list.tsx +1 -0
- package/src/serve/hub-app/projects-svc.ts +1 -1
- package/src/serve/hub-app/repo-st.ts +1 -1
- package/src/serve/hub-app/review/kind-view.tsx +21 -22
- package/src/serve/hub-app/review/kit.tsx +11 -12
- package/src/serve/hub-app/review/review-board.tsx +15 -13
- package/src/serve/hub-app/review/review-cells.tsx +241 -0
- package/src/serve/hub-app/review/review-kit.ts +79 -0
- package/src/serve/hub-app/review/review-list.tsx +87 -122
- package/src/serve/hub-app/review/review-page.tsx +22 -79
- package/src/serve/hub-app/review/review-st.ts +269 -698
- package/src/serve/hub-app/review/review-thread.tsx +302 -0
- package/src/serve/hub-app/review/review-views.tsx +322 -253
- package/src/serve/hub-app/review/thread-st.ts +770 -0
- package/src/serve/hub-app/review.css +235 -91
- package/src/serve/hub-runtime.ts +9 -4
- package/src/serve/serve-hub.ts +4 -1
- package/src/serve/warm-cell.ts +6 -1
- package/src/trailer/footage.ts +6 -2
- package/src/trailer/passage.ts +4 -2
- package/src/trailer/prune.ts +6 -10
- 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
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
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 {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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:
|
|
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
|
-
/**
|
|
75
|
-
|
|
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
|
-
/**
|
|
85
|
-
const
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
102
|
+
page: ThreadPage | null = null
|
|
222
103
|
listError: string | null = null
|
|
223
|
-
/** the
|
|
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
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
|
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.
|
|
324
|
-
this.loadWatchers =
|
|
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(
|
|
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' | '
|
|
166
|
+
makeAutoObservable<this, 'st' | 'toastTimer' | 'searchTimer' | 'timer' | 'loadPage' | 'loadWatchers' | 'loadBoard' | 'prefix'>(this, {
|
|
337
167
|
st: false,
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
reading: false,
|
|
168
|
+
toastTimer: false,
|
|
169
|
+
searchTimer: false,
|
|
341
170
|
timer: false,
|
|
342
|
-
|
|
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.
|
|
352
|
-
(
|
|
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
|
-
() =>
|
|
358
|
-
(
|
|
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
|
|
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
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
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
|
-
|
|
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
|
-
|
|
439
|
-
|
|
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
|
|
443
|
-
|
|
281
|
+
get listQuery(): string {
|
|
282
|
+
const f = this.listFilters
|
|
283
|
+
return `${f ? `${f}&` : ''}limit=${this.shown}`
|
|
444
284
|
}
|
|
445
285
|
|
|
446
|
-
|
|
447
|
-
return
|
|
286
|
+
get rows(): ThreadRow[] {
|
|
287
|
+
return this.page?.rows ?? []
|
|
448
288
|
}
|
|
449
289
|
|
|
450
|
-
|
|
451
|
-
|
|
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
|
-
|
|
455
|
-
|
|
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
|
|
303
|
+
return this.page?.counts.waiting ?? 0
|
|
472
304
|
}
|
|
473
305
|
|
|
474
306
|
get activeCount(): number {
|
|
475
|
-
return this.
|
|
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
|
|
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
|
|
524
|
-
|
|
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
|
|
529
|
-
get
|
|
530
|
-
const
|
|
531
|
-
|
|
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
|
-
|
|
535
|
-
|
|
536
|
-
return
|
|
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
|
-
|
|
540
|
-
|
|
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
|
-
|
|
544
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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)
|
|
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
|
|
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
|
|
402
|
+
/** the card the address names */
|
|
635
403
|
select(id: string | null): void {
|
|
636
|
-
|
|
637
|
-
|
|
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
|
-
/**
|
|
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
|
|
662
|
-
const
|
|
663
|
-
|
|
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
|
|
422
|
+
/** N: the next card that waits on him after the open one, wrapping */
|
|
668
423
|
nextPending(): void {
|
|
669
|
-
const pend = this.
|
|
424
|
+
const pend = this.rows.filter((r) => r.waits)
|
|
670
425
|
if (pend.length === 0) return
|
|
671
|
-
const at = pend.findIndex((
|
|
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
|
|
428
|
+
if (next) this.pick(next.head)
|
|
674
429
|
}
|
|
675
430
|
|
|
676
|
-
|
|
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
|
-
|
|
687
|
-
|
|
688
|
-
this.
|
|
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
|
|
692
|
-
|
|
693
|
-
|
|
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
|
-
|
|
699
|
-
|
|
700
|
-
|
|
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
|
-
|
|
704
|
-
|
|
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
|
-
|
|
717
|
-
this.
|
|
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
|
-
|
|
771
|
-
|
|
772
|
-
|
|
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
|
-
|
|
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
|
-
|
|
785
|
-
|
|
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
|
-
|
|
808
|
-
|
|
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
|
-
|
|
812
|
-
const t = this.openThread
|
|
813
|
-
return t ? conversationOf(t) : []
|
|
814
|
-
}
|
|
475
|
+
// ── files ──
|
|
815
476
|
|
|
816
|
-
/** a
|
|
817
|
-
|
|
818
|
-
return
|
|
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
|
-
|
|
822
|
-
|
|
823
|
-
return
|
|
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
|
-
|
|
827
|
-
|
|
828
|
-
|
|
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
|
-
|
|
834
|
-
|
|
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
|
-
|
|
857
|
-
|
|
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}/
|
|
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
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
this.
|
|
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
|
-
/**
|
|
905
|
-
|
|
906
|
-
|
|
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
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
this.
|
|
920
|
-
|
|
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,
|
|
954
|
-
*
|
|
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
|
-
|
|
959
|
-
|
|
960
|
-
if (
|
|
961
|
-
|
|
962
|
-
|
|
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
|
}
|