refactor: group episode state
This commit is contained in:
@@ -19,16 +19,16 @@ export const isAutoplayEnabled = (): boolean =>
|
||||
* Updates video overlay text (shown briefly on episode change).
|
||||
*/
|
||||
export const updateOverlay = (episode: string, title: string): void => {
|
||||
if (!state.videoOverlay) return;
|
||||
const p = state.videoOverlay.querySelector("p");
|
||||
if (!state.elements.videoOverlay) return;
|
||||
const p = state.elements.videoOverlay.querySelector("p");
|
||||
if (!p) return;
|
||||
p.textContent = title ? `Episode ${episode}, ${title}` : `Episode ${episode}`;
|
||||
};
|
||||
|
||||
// helper: get all episode elements from grid and list
|
||||
const getEpisodeEls = () => {
|
||||
const grid = state.episodeGrid;
|
||||
const list = state.episodeList;
|
||||
const grid = state.elements.episodeGrid;
|
||||
const list = state.elements.episodeList;
|
||||
return {
|
||||
gridEls: grid ? Array.from(grid.querySelectorAll("[data-episode-id]")) : [],
|
||||
listEls: list ? Array.from(list.querySelectorAll("[data-episode-id]")) : [],
|
||||
@@ -47,8 +47,8 @@ export const updateEpisodeHighlight = (num: number): void => {
|
||||
);
|
||||
|
||||
// apply new highlight
|
||||
const gridEl = state.episodeGrid?.querySelector(`[data-episode-id="${num}"]`);
|
||||
const listEl = state.episodeList?.querySelector(`[data-episode-id="${num}"]`);
|
||||
const gridEl = state.elements.episodeGrid?.querySelector(`[data-episode-id="${num}"]`);
|
||||
const listEl = state.elements.episodeList?.querySelector(`[data-episode-id="${num}"]`);
|
||||
gridEl?.classList.add("ring-2", "ring-accent");
|
||||
listEl?.classList.add("ring-2", "ring-accent");
|
||||
// scroll into view
|
||||
@@ -75,7 +75,7 @@ export const switchEpisodeRange = (idx: number): void => {
|
||||
label.textContent = `${String(start).padStart(2, "0")}-${String(end).padStart(2, "0")}`;
|
||||
|
||||
// show/hide episodes in range
|
||||
state.episodeGrid?.querySelectorAll("[data-episode-id]").forEach((el) => {
|
||||
state.elements.episodeGrid?.querySelectorAll("[data-episode-id]").forEach((el) => {
|
||||
const n = Number.parseInt((el as HTMLElement).dataset.episodeId ?? "0", 10);
|
||||
el.classList.toggle("hidden", n < start || n > end);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user