Track repair collection cycles and reconcile request availability
This commit is contained in:
@@ -68,6 +68,7 @@ type Snapshot = {
|
||||
actions: RequestAction[]
|
||||
artwork?: { poster_url?: string; backdrop_url?: string }
|
||||
presentation?: {
|
||||
repairCycle?: string | null
|
||||
status?: { label?: string; meaning?: string }
|
||||
download?: {
|
||||
visible?: boolean
|
||||
@@ -121,6 +122,8 @@ type ActionHistory = {
|
||||
}
|
||||
|
||||
type LiveDownloadProgress = {
|
||||
repairCycle?: string | null
|
||||
visible?: boolean
|
||||
request_id: string
|
||||
state: string
|
||||
summary: string
|
||||
@@ -205,15 +208,20 @@ const formatDuration = (duration?: number | null) => {
|
||||
|
||||
const mergeLiveDownload = (current: Snapshot, live: LiveDownloadProgress): Snapshot => {
|
||||
if (String(current.request_id) !== String(live.request_id)) return current
|
||||
if ((current.presentation?.repairCycle ?? null) !== (live.repairCycle ?? null)) return current
|
||||
if (['COMPLETED', 'AVAILABLE'].includes(current.state)) return current
|
||||
const downloadStage = current.presentation?.pipeline?.find((stage) => stage.id === 'download')
|
||||
if (downloadStage?.state === 'complete' && downloadStage.visible === false) return current
|
||||
const visible = live.visible ?? live.state !== 'not_started'
|
||||
const stageState = live.state === 'completed'
|
||||
? 'complete'
|
||||
: ['missing', 'error'].includes(live.state)
|
||||
? 'attention'
|
||||
: 'active'
|
||||
: live.state === 'not_started' ? 'waiting' : 'active'
|
||||
const presentation = current.presentation ?? {}
|
||||
const pipeline = (presentation.pipeline ?? fallbackPipeline(current)).map((stage) =>
|
||||
stage.id === 'download'
|
||||
? { ...stage, state: stageState, summary: live.summary, visible: true, torrents: live.torrents }
|
||||
? { ...stage, state: stageState, stateLabel: undefined, summary: live.summary, visible, torrents: live.torrents }
|
||||
: stage
|
||||
)
|
||||
return {
|
||||
@@ -222,7 +230,7 @@ const mergeLiveDownload = (current: Snapshot, live: LiveDownloadProgress): Snaps
|
||||
...presentation,
|
||||
download: {
|
||||
...(presentation.download ?? {}),
|
||||
visible: true,
|
||||
visible,
|
||||
state: live.state,
|
||||
summary: live.summary,
|
||||
torrents: live.torrents,
|
||||
|
||||
Reference in New Issue
Block a user