From ca717d9486d75e14c3abd2f4706e3653d973c933 Mon Sep 17 00:00:00 2001 From: Miguel Palhas Date: Mon, 9 Nov 2026 19:02:03 +0000 Subject: [PATCH] fix(web): keep open panels across download polls The 15s download poll rebuilt the series, movie and library views, closing any subtitle panel or tray the user had open. Download chips now refill in place instead. Co-Authored-By: Claude Opus 5.5 (1M context) --- web/src/main.ts | 115 +++++++++++++++++++--------------------------- web/src/style.css | 5 ++ 2 files changed, 53 insertions(+), 67 deletions(-) diff --git a/web/src/main.ts b/web/src/main.ts index 2cd3930..8f81df0 100644 --- a/web/src/main.ts +++ b/web/src/main.ts @@ -376,7 +376,6 @@ function main() { // assigned once the queues view exists; the poll keeps the badge honest let refreshQueuesBadge: (() => void) | null = null; // assigned once the library and series views exist (§9.8) - let repaintDownloads: (() => void) | null = null; async function probe() { if (inFlight) { @@ -385,7 +384,7 @@ function main() { inFlight = true; render(await probeHealth()); latestDownloads = await fetchDownloads(); - repaintDownloads?.(); + repaintDownloadSlots(); inFlight = false; refreshQueuesBadge?.(); } @@ -427,11 +426,6 @@ function main() { }; movieDetail.setRemoved(openAfterRemoval); seriesDetail.setRemoved(openAfterRemoval); - repaintDownloads = () => { - library.repaintDownloads(); - seriesDetail.repaintDownloads(); - movieDetail.repaintDownloads(); - }; refreshQueuesBadge = () => { void queues.refreshBadge(); }; @@ -1050,20 +1044,48 @@ function downloadChip( targetKind: string, targetId: number, say?: (text: string | null) => void, -): HTMLSpanElement | null { - const download = findDownload(latestDownloads, targetKind, targetId); - if (download === null) { - return null; +): HTMLSpanElement { + const slot = document.createElement("span"); + slot.className = "dl-slot"; + slot.dataset.dlKind = targetKind; + slot.dataset.dlId = String(targetId); + if (say) { + downloadSays.set(slot, say); + } + fillDownloadSlot(slot); + return slot; +} + +const downloadSays = new WeakMap void>(); + +function fillDownloadSlot(slot: HTMLElement) { + const download = findDownload(latestDownloads, slot.dataset.dlKind ?? "", Number(slot.dataset.dlId)); + if (download === null) { + slot.replaceChildren(); + return; + } + const say = downloadSays.get(slot); + slot.replaceChildren( + chip(downloadChipLabel(download), (span) => { + span.classList.add("dl-chip"); + span.dataset.dlPhase = download.phase; + const detail = downloadChipDetail(download); + span.setAttribute("aria-label", `download ${detail}`); + if (say) { + explainable(span, `download ${detail}`, say); + } + }), + ); +} + +/** + * Refills every download chip in place from the latest poll. Rebuilding the + * pages instead would close whatever panel or tray the user had open. + */ +function repaintDownloadSlots() { + for (const slot of document.querySelectorAll(".dl-slot")) { + fillDownloadSlot(slot); } - return chip(downloadChipLabel(download), (span) => { - span.classList.add("dl-chip"); - span.dataset.dlPhase = download.phase; - const detail = downloadChipDetail(download); - span.setAttribute("aria-label", `download ${detail}`); - if (say) { - explainable(span, `download ${detail}`, say); - } - }); } /** The ramp read off N/M itself: green when full, amber while a gap remains. */ @@ -2071,10 +2093,7 @@ function libraryRow( if (waiver !== null) { parts.meta.children[0]?.after(waiver); } - const download = downloadChip("movie", movie.id, parts.say); - if (download !== null) { - parts.meta.append(download); - } + parts.meta.append(downloadChip("movie", movie.id, parts.say)); return parts.item; } @@ -2313,8 +2332,6 @@ interface MovieView { * surface underneath repaints instead of listing something that is gone. */ setRemoved: (handler: (parent: Route) => void) => void; - /** §9.8: repaint only while the page is open (issue #267). */ - repaintDownloads: () => void; } /** One bucket: a head with its count and a list. */ @@ -2676,16 +2693,7 @@ function movieMain(views: HideableView[]): MovieView { chipsEl.append(chip(NO_TARGETED_SEARCH)); } // §9.8: the hero is the row that owns the item, same as the library row - const download = downloadChip("movie", movie.id, heroSay); - if (download !== null) { - chipsEl.append(download); - } - } - - function repaintDownloads() { - if (!view.hidden) { - paintIdentity(); - } + chipsEl.append(downloadChip("movie", movie.id, heroSay)); } function paintRootOptions() { @@ -3213,7 +3221,6 @@ function movieMain(views: HideableView[]): MovieView { setRemoved: (handler: (parent: Route) => void) => { removed = handler; }, - repaintDownloads, }; } @@ -3707,9 +3714,6 @@ function releaseRow( interface LibraryView { hide: () => void; open: () => void; - /** §9.8: repaints rows in place from the latest poll — only while the - * view is actually visible, so a hidden library never rebuilds for it. */ - repaintDownloads: () => void; } interface LibraryGroup { @@ -3991,13 +3995,7 @@ function libraryMain( sequence += 1; } - function repaintDownloads() { - if (!view.hidden) { - render(); - } - } - - return { hide, open, repaintDownloads }; + return { hide, open }; } /** @@ -4137,10 +4135,7 @@ function movieCard( ): HTMLLIElement { const chips: HTMLSpanElement[] = []; chips.push(mediaStateChip(movie.state, movie.wanted)); - const download = downloadChip("movie", movie.id); - if (download !== null) { - chips.push(download); - } + chips.push(downloadChip("movie", movie.id)); const waiver = waiverChip(movie.waiver); if (waiver !== null) { chips.push(waiver); @@ -4586,9 +4581,6 @@ interface SeriesView { ) => Promise; /** Where to land once the title is gone — same contract as a movie. */ setRemoved: (handler: (parent: Route) => void) => void; - /** §9.8: repaints seasons and episodes in place from the latest poll — - * only while the view is actually visible. */ - repaintDownloads: () => void; } const PAD_TWO = (value: number): string => String(value).padStart(2, "0"); @@ -4969,10 +4961,7 @@ function seriesMain(tvDeck: TvReleasesView, views: HideableView[]): SeriesView { ); } // §9.8: a season row aggregates its own pack grab, last on its line - const download = downloadChip("season", season.id, parts.say); - if (download !== null) { - parts.meta.append(download); - } + parts.meta.append(downloadChip("season", season.id, parts.say)); const episodes = document.createElement("ul"); episodes.className = "episodes"; @@ -5140,10 +5129,7 @@ function seriesMain(tvDeck: TvReleasesView, views: HideableView[]): SeriesView { parts.meta.append(pri(chip(formatAirDate(episode.air_date)))); // §9.8: nothing here if the episode is part of a season pack grab — that // download is `target_kind: "season"` and shows on the season row instead - const download = downloadChip("episode", episode.id, parts.say); - if (download !== null) { - parts.meta.append(download); - } + parts.meta.append(downloadChip("episode", episode.id, parts.say)); return parts.item; } @@ -5412,11 +5398,6 @@ function seriesMain(tvDeck: TvReleasesView, views: HideableView[]): SeriesView { setRemoved: (handler: (parent: Route) => void) => { removed = handler; }, - repaintDownloads: () => { - if (!view.hidden) { - renderSeasons(); - } - }, }; } diff --git a/web/src/style.css b/web/src/style.css index 0e482c6..a0fb1a4 100644 --- a/web/src/style.css +++ b/web/src/style.css @@ -737,6 +737,11 @@ button.chip { border-color: var(--line-strong); } +/* §9.8: the slot is refilled in place by the poll and takes no box itself */ +.dl-slot { + display: contents; +} + /* §9.8: live download state, fixed width so 9% → 10% never moves a neighbour */ .dl-chip { min-width: 7ch;