refactor(frontend): satisfy noUncheckedIndexedAccess (S3b)
Enable noUncheckedIndexedAccess and fix all 98 call sites it surfaced across 18 files. Every fix is behaviour-preserving — the flag flagged reads TypeScript couldn't prove in-bounds, all of which were already guarded by a length/index check, a findIndex result, or a non-empty invariant: - read-once so a ternary's narrowing sticks (Feed overrides, linkify mention); - non-null assertion AFTER an existing guard (PlayerModal/VideoEditor queue+cut-list indexing, modules step, useUndoable stacks) with a comment stating the invariant; - nullish fallback where undefined is a real possibility (GlassTuner slider ?? def, ConfigPanel active group ?? [], descriptionLinks id ?? null); - optional chaining where the entry genuinely can be absent (PlexBrowse IO entry); - a non-empty tuple type for the RELATIVE_UNITS constant (encodes "always has [0]"). The single highest-leverage fix: PlayerModal's `active` became `queue?.[index] ?? video` (always Video), clearing 34 of the 45 errors in that file at once. Verified: tsc/eslint/prettier clean, 56 vitest + 34 pytest + 17/17 e2e green (the e2e suite exercises the feed/player/channel components touched here).
This commit is contained in:
@@ -124,7 +124,7 @@ export default function PlayerModal({
|
||||
// where a just-watched item could drop out and snap playback to queue[0]).
|
||||
let index = queue ? queue.findIndex((v) => v.id === playingId) : 0;
|
||||
if (index < 0) index = 0;
|
||||
const active = queue && queue[index] ? queue[index] : video;
|
||||
const active = queue?.[index] ?? video; // the queue item at index, else the opened video (never undefined)
|
||||
const hasQueue = !!queue && queue.length > 1;
|
||||
// startAt only applies to the item we opened with; advanced items resume their own pos.
|
||||
const resumeAt =
|
||||
@@ -242,11 +242,11 @@ export default function PlayerModal({
|
||||
navRef.current = { queue, index };
|
||||
const goPrev = () => {
|
||||
const { queue: q, index: i } = navRef.current;
|
||||
if (q && i > 0) setPlayingId(q[i - 1].id);
|
||||
if (q && i > 0) setPlayingId(q[i - 1]!.id);
|
||||
};
|
||||
const goNext = () => {
|
||||
const { queue: q, index: i } = navRef.current;
|
||||
if (q && i < q.length - 1) setPlayingId(q[i + 1].id);
|
||||
if (q && i < q.length - 1) setPlayingId(q[i + 1]!.id);
|
||||
};
|
||||
// Relative seek within the current video (plain Arrow keys), matching YouTube's ±5s.
|
||||
const nudgeSeek = (delta: number) => {
|
||||
@@ -277,12 +277,12 @@ export default function PlayerModal({
|
||||
);
|
||||
};
|
||||
const cycleAuto = () => {
|
||||
const next = AUTO_MODES[(AUTO_MODES.indexOf(autoMode) + 1) % AUTO_MODES.length];
|
||||
const next = AUTO_MODES[(AUTO_MODES.indexOf(autoMode) + 1) % AUTO_MODES.length]!;
|
||||
setAutoMode(next);
|
||||
persistPref({ playerAutoAdvance: next });
|
||||
};
|
||||
const cycleLoop = () => {
|
||||
const next = LOOP_MODES[(LOOP_MODES.indexOf(loopMode) + 1) % LOOP_MODES.length];
|
||||
const next = LOOP_MODES[(LOOP_MODES.indexOf(loopMode) + 1) % LOOP_MODES.length]!;
|
||||
setLoopMode(next);
|
||||
persistPref({ playerLoop: next });
|
||||
};
|
||||
@@ -303,21 +303,21 @@ export default function PlayerModal({
|
||||
if (!q || q.length === 0) return;
|
||||
const wrap = l === "all";
|
||||
if (a === "next") {
|
||||
if (i < q.length - 1) setPlayingId(q[i + 1].id);
|
||||
if (i < q.length - 1) setPlayingId(q[i + 1]!.id);
|
||||
else if (wrap) {
|
||||
if (q.length === 1) replayCurrent();
|
||||
else setPlayingId(q[0].id);
|
||||
else setPlayingId(q[0]!.id);
|
||||
}
|
||||
} else if (a === "prev") {
|
||||
if (i > 0) setPlayingId(q[i - 1].id);
|
||||
if (i > 0) setPlayingId(q[i - 1]!.id);
|
||||
else if (wrap) {
|
||||
if (q.length === 1) replayCurrent();
|
||||
else setPlayingId(q[q.length - 1].id);
|
||||
else setPlayingId(q[q.length - 1]!.id);
|
||||
}
|
||||
} else if (a === "random" && q.length > 1) {
|
||||
let r = i;
|
||||
while (r === i) r = Math.floor(Math.random() * q.length);
|
||||
setPlayingId(q[r].id);
|
||||
setPlayingId(q[r]!.id);
|
||||
} else if (a === "random" && wrap) {
|
||||
replayCurrent();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user