fix(web): settle toggles, retries and stale routes
ci / web (pull_request) Successful in 23s
ci / rust (pull_request) Successful in 1m23s
ci / image (pull_request) Skipped

Toggles and failed deletes re-enable, an override grab ends a running
sweep watch, the pack retry ignores a second click, a deep-link fetch
yields to a later navigation, and the search tab focuses the box.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Miguel Palhas
2026-11-11 00:43:21 +00:00
co-authored by Claude Opus 5.5
parent 1167828208
commit 769a59e15c
5 changed files with 47 additions and 18 deletions
+29 -9
View File
@@ -11,6 +11,7 @@ import {
useRef,
useState,
} from "react";
import { flushSync } from "react-dom";
import { LAYER, LiveContext, type Nav, NavContext, type TvDeckRequest, useEscape } from "./context";
import { type Download, fetchDownloads } from "./downloads";
import { type Probe, probeHealth } from "./health";
@@ -185,6 +186,7 @@ export function App() {
const inputRef = useRef<HTMLInputElement>(null);
const wordmark = useRef<HTMLAnchorElement>(null);
const debounce = useRef<number | undefined>(undefined);
const routeTicket = useRef(0);
// where back and Esc land, and which control gets focus back
const overlayParent = useRef<Route>(LIBRARY);
const overlayOrigin = useRef<HTMLElement | null>(null);
@@ -205,6 +207,10 @@ export function App() {
const applyRoute = useCallback(
async (next: Route) => {
window.clearTimeout(debounce.current);
// a later route, or a click, outranks a deep-link fetch still out
routeTicket.current += 1;
const ticket = routeTicket.current;
const stale = () => ticket !== routeTicket.current;
if (isBase(next)) {
// §9.7: "/" is the library — clear any stale query so the rail input
// matches the route on a cold load or back-navigation
@@ -223,7 +229,11 @@ export function App() {
overlayOrigin.current = wordmark.current;
setInput("");
if (next.kind === "movie" || next.kind === "releases") {
if ((await fetchMovie(next.movieId)) === null) {
const found = await fetchMovie(next.movieId);
if (stale()) {
return;
}
if (found === null) {
home();
return;
}
@@ -236,7 +246,11 @@ export function App() {
return;
}
if (next.kind === "series") {
if ((await fetchSeries(next.seriesId)) === null) {
const found = await fetchSeries(next.seriesId);
if (stale()) {
return;
}
if (found === null) {
home();
return;
}
@@ -253,6 +267,9 @@ export function App() {
let tv: TvDeckRequest;
if (next.kind === "seasonReleases") {
const title = (await fetchSeries(next.seriesId))?.title ?? "";
if (stale()) {
return;
}
if (title === "") {
home();
return;
@@ -267,6 +284,9 @@ export function App() {
} else {
const episode = await fetchEpisode(next.episodeId);
const title = episode === null ? "" : ((await fetchSeries(episode.series_id))?.title ?? "");
if (stale()) {
return;
}
if (episode === null || title === "") {
home();
return;
@@ -308,6 +328,7 @@ export function App() {
const nav = useMemo<Nav>(() => {
const openOverlay = (overlay: Overlay, path: Route, origin: HTMLElement | null) => {
routeTicket.current += 1;
overlayParent.current = layersRef.current.base;
overlayOrigin.current = origin;
navigate(path);
@@ -357,7 +378,10 @@ export function App() {
/* ---- the rail's search box ---- */
const focusInput = () => {
/** Opens the rail's search box and puts the caret in it. Below 40rem the box
* only exists once the rail is searching, so that paints first. */
const openSearch = () => {
flushSync(() => setSearching(true));
inputRef.current?.focus();
inputRef.current?.select();
};
@@ -412,8 +436,7 @@ export function App() {
const go = (target: Destination) => {
if (target === "search") {
setSearching(true);
focusInput();
openSearch();
return;
}
setSearching(false);
@@ -558,10 +581,7 @@ export function App() {
type="button"
className="control control-icon rail-search-open"
aria-label="search"
onClick={() => {
setSearching(true);
focusInput();
}}
onClick={openSearch}
>
<Icon name="search" />
</button>
+2
View File
@@ -224,7 +224,9 @@ export function MovieView({ movieId, toReleases }: { movieId: number; toReleases
const reloadReleases = async () => {
sequence.current += 1;
const ticket = sequence.current;
// a sweep being watched ends here; the verdicts below are the newer answer
window.clearTimeout(pollTimer.current);
setSweeping(false);
const outcome = await movieReleases(movieId);
if (!current(ticket)) {
return;
+1 -1
View File
@@ -324,7 +324,7 @@ export function QueuesView({ hidden }: { hidden: boolean }) {
roots={roots}
open={nav.openMovie}
settled={(text) => {
setSettledIds(new Set([...settledIds, movie.id]));
setSettledIds((settled) => new Set(settled).add(movie.id));
setStatus(text);
}}
/>
+3 -7
View File
@@ -105,11 +105,7 @@ function WritingToggle({
data-focus-id={focusId}
onClick={() => {
setBusy(true);
void write().then((ok) => {
if (!ok) {
setBusy(false);
}
});
void write().then(() => setBusy(false));
}}
/>
);
@@ -152,7 +148,7 @@ function SeasonRow({
if (outcome.kind === "error") {
tree.fail(`remove failed — ${outcome.detail}`);
tree.reload();
return undefined;
return false;
}
// the delete disappears with the files; the tracked toggle survives
tree.reload(`track-${season.number}`);
@@ -319,7 +315,7 @@ function EpisodeRow({
if (outcome.kind === "error") {
tree.fail(`remove failed — ${outcome.detail}`);
tree.reload();
return undefined;
return false;
}
// once missing, the row's want control is what remains to focus
tree.reload(`want-${episode.id}`);
+12 -1
View File
@@ -27,7 +27,12 @@ export function TvDeckView({ request }: { request: TvDeckRequest }) {
const [status, setStatusState] = useState<Status | null>(null);
const [deck, setDeck] = useState<DeckState>({ kind: "skeleton" });
const [failure, setFailure] = useState<ImportFailure | null>(null);
const [sweeping, setSweeping] = useState(false);
const [sweeping, setSweepingState] = useState(false);
const sweepingRef = useRef(false);
const setSweeping = (on: boolean) => {
sweepingRef.current = on;
setSweepingState(on);
};
const back = useRef<HTMLButtonElement>(null);
// guards a stale fetch from painting over a newer view
const sequence = useRef(0);
@@ -102,6 +107,7 @@ export function TvDeckView({ request }: { request: TvDeckRequest }) {
}
const painted = outcome.releases.length > 0;
if (painted) {
setSweeping(false);
paint(outcome.releases);
}
// One read of the season's state, shared by the notice and the empty
@@ -287,6 +293,11 @@ export function TvDeckView({ request }: { request: TvDeckRequest }) {
* window and does try a pack (#181).
*/
async function startSweep(known?: SeasonPackState | null) {
// the status line's retry stays clickable until the watch replaces it
if (sweepingRef.current) {
return;
}
sweepingRef.current = true;
setSweeping(true);
// The stamp the watch below waits to move. An episode stamps its own
// row; reading it before the search is queued is what keeps the finished