2026-06-29 00:24:49 +02:00
|
|
|
import { useEffect, useRef, useState } from "react";
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
import { useTranslation } from "react-i18next";
|
2026-06-12 17:39:08 +02:00
|
|
|
import { createPortal } from "react-dom";
|
2026-06-14 18:40:12 +02:00
|
|
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
2026-07-05 00:20:50 +02:00
|
|
|
import { AlertTriangle, ArrowLeft, Check, CheckCheck, ChevronLeft, ChevronRight, ExternalLink, Repeat, Repeat1, Shuffle, SkipBack, SkipForward, Volume2, VolumeX, X } from "lucide-react";
|
2026-06-12 18:01:43 +02:00
|
|
|
import Avatar from "./Avatar";
|
2026-06-15 14:45:18 +02:00
|
|
|
import AddToPlaylist from "./AddToPlaylist";
|
feat(downloads): M5 — Download Center frontend
- api.ts: download types + methods (profiles, enqueue, list/manage, file url, share,
usage, index, admin storage/quota)
- format.ts: formatBytes / formatSpeed
- i18n: en/hu/de downloads.json (trilingual)
- Downloads nav module (Download icon, active-count badge, hidden for demo) placed after
Messages; urlState page + App render + Header title
- DownloadButton: self-contained per-card/player affordance (demo-hidden, reflects the
per-user download index: downloaded / in-queue), opens the preset dialog
- DownloadDialog: preset picker + optional display name -> enqueue + 'View' toast
- ProfileEditor: manage built-in + custom formats (full spec form incl. SponsorBlock)
- DownloadCenter: Queue / Library / Shared / (admin) System tabs, live progress via
useLiveQuery, usage bar, pause/resume/cancel/delete, save-to-device, rename, share,
admin storage dashboard + per-user quota editor
- wired DownloadButton into VideoCard + PlayerModal
- lib/nav.ts: decoupled navigator so the download toast can jump to the page
tsc + vite build clean. Verified in a headless authed browser: page + tabs render, Library
shows a real download with usage bar + actions, no console errors.
2026-07-03 01:52:58 +02:00
|
|
|
import DownloadButton from "./DownloadButton";
|
2026-06-12 17:39:01 +02:00
|
|
|
import { api, type Video } from "../lib/api";
|
2026-06-19 03:22:10 +02:00
|
|
|
import { channelYouTubeUrl, formatDuration, formatViews, relativeTime } from "../lib/format";
|
2026-06-29 00:24:49 +02:00
|
|
|
import { renderDescription } from "../lib/descriptionLinks";
|
2026-06-26 01:37:43 +02:00
|
|
|
import { useBackToClose } from "../lib/history";
|
2026-06-12 17:38:45 +02:00
|
|
|
|
|
|
|
|
// Experiment (branch experiment/inline-player): play the video in-app via the
|
|
|
|
|
// YouTube IFrame Player API (not a bare embed) so we can read playback position
|
2026-06-12 17:39:01 +02:00
|
|
|
// and resume where the user left off. The modal closes via the in-card Close
|
|
|
|
|
// button, the backdrop, or ESC (ESC only while focus is on our page, not inside
|
|
|
|
|
// the cross-origin player iframe — a browser security boundary we can't cross).
|
|
|
|
|
|
|
|
|
|
// How close to the end (seconds) counts as "finished" → auto-mark watched.
|
|
|
|
|
const FINISH_MARGIN = 10;
|
2026-06-12 17:38:45 +02:00
|
|
|
|
2026-07-05 00:20:50 +02:00
|
|
|
// Persistent playback settings (stored in users.preferences). Auto-advance = what plays when a
|
|
|
|
|
// video ends; loop = whether it repeats the current video ("one"), wraps the list at its ends
|
|
|
|
|
// ("all"), or neither ("off"). Both apply to any queued player (feed or playlist).
|
|
|
|
|
type AutoMode = "off" | "next" | "prev" | "random";
|
|
|
|
|
type LoopMode = "off" | "one" | "all";
|
|
|
|
|
const AUTO_MODES: AutoMode[] = ["off", "next", "prev", "random"];
|
|
|
|
|
const LOOP_MODES: LoopMode[] = ["off", "one", "all"];
|
|
|
|
|
|
2026-06-12 17:38:45 +02:00
|
|
|
// --- IFrame Player API loader (singleton) ---
|
|
|
|
|
let apiPromise: Promise<any> | null = null;
|
|
|
|
|
function loadYouTubeApi(): Promise<any> {
|
|
|
|
|
if (apiPromise) return apiPromise;
|
|
|
|
|
apiPromise = new Promise((resolve) => {
|
|
|
|
|
const w = window as any;
|
|
|
|
|
if (w.YT && w.YT.Player) return resolve(w.YT);
|
|
|
|
|
const prev = w.onYouTubeIframeAPIReady;
|
|
|
|
|
w.onYouTubeIframeAPIReady = () => {
|
|
|
|
|
if (typeof prev === "function") prev();
|
|
|
|
|
resolve(w.YT);
|
|
|
|
|
};
|
|
|
|
|
const tag = document.createElement("script");
|
|
|
|
|
tag.src = "https://www.youtube.com/iframe_api";
|
|
|
|
|
document.head.appendChild(tag);
|
|
|
|
|
});
|
|
|
|
|
return apiPromise;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function PlayerModal({
|
|
|
|
|
video,
|
2026-06-14 18:40:12 +02:00
|
|
|
startAt,
|
2026-07-05 00:20:50 +02:00
|
|
|
queue,
|
2026-06-15 16:11:37 +02:00
|
|
|
startIndex,
|
2026-06-12 17:38:45 +02:00
|
|
|
onClose,
|
2026-06-12 17:39:01 +02:00
|
|
|
onState,
|
2026-06-30 03:12:44 +02:00
|
|
|
onOpenChannel,
|
2026-06-12 17:38:45 +02:00
|
|
|
}: {
|
|
|
|
|
video: Video;
|
2026-06-14 18:40:12 +02:00
|
|
|
// Where to start the opened video: a number of seconds (0 = Restart), or null/undefined
|
|
|
|
|
// to resume from the server-saved position carried on the video.
|
|
|
|
|
startAt?: number | null;
|
2026-06-15 16:11:37 +02:00
|
|
|
// Optional playback queue (e.g. a playlist). When present, the player advances through
|
|
|
|
|
// it (auto-advance on end + prev/next), recreating per item to reuse the single-video
|
|
|
|
|
// resume / auto-watch / progress logic.
|
|
|
|
|
queue?: Video[];
|
|
|
|
|
startIndex?: number;
|
2026-06-12 17:38:45 +02:00
|
|
|
onClose: () => void;
|
2026-06-12 17:39:01 +02:00
|
|
|
onState: (id: string, status: string) => void;
|
2026-06-30 03:12:44 +02:00
|
|
|
// Open the active video's channel page in-app (closes the player first). The small external
|
|
|
|
|
// icon next to the name keeps the open-on-YouTube behaviour.
|
|
|
|
|
onOpenChannel?: (channelId: string, channelName?: string) => void;
|
2026-06-12 17:38:45 +02:00
|
|
|
}) {
|
2026-06-16 03:09:28 +02:00
|
|
|
const { t, i18n } = useTranslation();
|
2026-06-14 18:40:12 +02:00
|
|
|
const qc = useQueryClient();
|
2026-06-26 01:37:43 +02:00
|
|
|
// Browser/mouse Back closes the player instead of leaving the page.
|
|
|
|
|
useBackToClose(onClose);
|
2026-06-16 03:09:28 +02:00
|
|
|
// Precise upload date shown inline after the relative time (e.g. "9 yr ago · 12 Jan 2017").
|
|
|
|
|
const fullDate = (d: string | null | undefined) =>
|
|
|
|
|
d
|
|
|
|
|
? new Date(d).toLocaleDateString(i18n.language, {
|
|
|
|
|
year: "numeric",
|
|
|
|
|
month: "short",
|
|
|
|
|
day: "numeric",
|
|
|
|
|
})
|
|
|
|
|
: "";
|
2026-06-15 16:27:28 +02:00
|
|
|
// Track the playing item by id (not a frozen index) so it survives the queue changing
|
|
|
|
|
// under us — e.g. an item removed in another tab. The index is derived from the *live*
|
|
|
|
|
// queue, so the N / M counter and prev/next neighbours stay correct without disrupting
|
|
|
|
|
// playback of the current video.
|
|
|
|
|
const [playingId, setPlayingId] = useState<string>(
|
2026-07-04 22:25:37 +02:00
|
|
|
// A caller with an explicit index (playlist) starts there; otherwise locate the opened
|
|
|
|
|
// `video` in the queue (the feed passes its whole list + the clicked video, no index).
|
|
|
|
|
startIndex != null ? queue?.[startIndex]?.id ?? video.id : video.id
|
2026-06-15 16:27:28 +02:00
|
|
|
);
|
|
|
|
|
let index = queue ? queue.findIndex((v) => v.id === playingId) : 0;
|
|
|
|
|
if (index < 0) index = 0;
|
2026-06-15 16:11:37 +02:00
|
|
|
const active = queue && queue[index] ? queue[index] : video;
|
|
|
|
|
const hasQueue = !!queue && queue.length > 1;
|
|
|
|
|
// startAt only applies to the item we opened with; advanced items resume their own pos.
|
|
|
|
|
const resumeAt =
|
|
|
|
|
startAt != null && active.id === video.id ? startAt : active.position_seconds || 0;
|
2026-06-12 17:38:45 +02:00
|
|
|
const mountRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
|
const playerRef = useRef<any>(null);
|
2026-06-12 17:39:01 +02:00
|
|
|
const autoMarkedRef = useRef(false);
|
2026-06-29 23:37:18 +02:00
|
|
|
// Keyboard/wheel controls. We keep focus on the modal card (not the cross-origin player
|
|
|
|
|
// iframe) so F / Space / Esc keep working until the user clicks into YouTube's native
|
|
|
|
|
// controls; the interaction overlay below also stops the iframe stealing focus on a video
|
|
|
|
|
// click. `stageRef` is the element we fullscreen (so the volume overlay stays visible).
|
|
|
|
|
const cardRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
|
const stageRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
|
const overlayRef = useRef<HTMLDivElement | null>(null);
|
|
|
|
|
const volTimerRef = useRef<number | undefined>(undefined);
|
|
|
|
|
// Volume level to flash in the on-player overlay (null = hidden). Auto-fades after a moment.
|
|
|
|
|
const [volumeUi, setVolumeUi] = useState<number | null>(null);
|
|
|
|
|
|
|
|
|
|
const focusModal = () => cardRef.current?.focus();
|
|
|
|
|
const togglePlay = () => {
|
|
|
|
|
const p = playerRef.current;
|
|
|
|
|
if (!p || typeof p.getPlayerState !== "function") return;
|
|
|
|
|
if (p.getPlayerState() === 1) p.pauseVideo?.(); // 1 === playing
|
|
|
|
|
else p.playVideo?.();
|
|
|
|
|
};
|
|
|
|
|
const toggleFullscreen = () => {
|
|
|
|
|
const el = stageRef.current;
|
|
|
|
|
if (!el) return;
|
|
|
|
|
if (document.fullscreenElement) document.exitFullscreen?.();
|
|
|
|
|
else el.requestFullscreen?.();
|
|
|
|
|
};
|
|
|
|
|
const flashVolume = (level: number) => {
|
|
|
|
|
setVolumeUi(level);
|
|
|
|
|
window.clearTimeout(volTimerRef.current);
|
|
|
|
|
volTimerRef.current = window.setTimeout(() => setVolumeUi(null), 1200);
|
|
|
|
|
};
|
|
|
|
|
const nudgeVolume = (delta: number) => {
|
|
|
|
|
const p = playerRef.current;
|
|
|
|
|
if (!p || typeof p.getVolume !== "function") return;
|
|
|
|
|
const cur = p.isMuted?.() ? 0 : p.getVolume?.() ?? 50;
|
|
|
|
|
const next = Math.max(0, Math.min(100, Math.round(cur + delta)));
|
|
|
|
|
if (next > 0) p.unMute?.();
|
|
|
|
|
p.setVolume?.(next);
|
|
|
|
|
if (next === 0) p.mute?.();
|
|
|
|
|
flashVolume(next);
|
|
|
|
|
};
|
2026-06-12 17:39:01 +02:00
|
|
|
|
2026-06-12 17:39:20 +02:00
|
|
|
// The player can navigate to other videos (YouTube links in a description). The
|
2026-06-15 16:11:37 +02:00
|
|
|
// currently-playing id may differ from the active item.
|
|
|
|
|
const [currentVideoId, setCurrentVideoId] = useState(active.id);
|
|
|
|
|
const currentIdRef = useRef(active.id);
|
|
|
|
|
const navigated = currentVideoId !== active.id;
|
2026-06-12 17:39:20 +02:00
|
|
|
// Title/author of a navigated-to video, read from the player (free, no API call).
|
|
|
|
|
const [liveData, setLiveData] = useState<{ title?: string; author?: string } | null>(null);
|
2026-06-16 10:45:57 +02:00
|
|
|
// IFrame Player API error code, when the current video can't play in the embed (e.g. an
|
|
|
|
|
// auto-generated Topic "Art Track" with embedding disabled → 101/150, or removed/private →
|
|
|
|
|
// 100). We overlay a friendly message + "Open on YouTube" instead of YouTube's bare error.
|
|
|
|
|
const [playerError, setPlayerError] = useState<number | null>(null);
|
2026-06-12 17:39:20 +02:00
|
|
|
|
|
|
|
|
const loadVideo = (id: string, start: number | null) => {
|
|
|
|
|
const p = playerRef.current;
|
|
|
|
|
if (!p || typeof p.loadVideoById !== "function") return;
|
2026-06-15 16:11:37 +02:00
|
|
|
// Explicit start wins; otherwise resume the active item, start others at 0.
|
|
|
|
|
const startSeconds = start != null ? start : id === active.id ? resumeAt : 0;
|
2026-06-16 10:45:57 +02:00
|
|
|
setPlayerError(null);
|
2026-06-12 17:39:20 +02:00
|
|
|
p.loadVideoById({ videoId: id, startSeconds: startSeconds || 0 });
|
|
|
|
|
currentIdRef.current = id;
|
|
|
|
|
setCurrentVideoId(id);
|
|
|
|
|
setLiveData(null);
|
|
|
|
|
};
|
|
|
|
|
|
2026-06-12 17:39:01 +02:00
|
|
|
// Local mirror of watch status so the toggle reacts instantly; changes are
|
|
|
|
|
// propagated to the feed (and server) via onState.
|
2026-06-15 16:11:37 +02:00
|
|
|
const [status, setStatus] = useState(active.status);
|
2026-06-12 17:39:01 +02:00
|
|
|
const watched = status === "watched";
|
|
|
|
|
const setWatched = (on: boolean) => {
|
|
|
|
|
const next = on ? "watched" : "new";
|
|
|
|
|
setStatus(next);
|
2026-06-15 16:11:37 +02:00
|
|
|
onState(active.id, next);
|
2026-06-12 17:39:01 +02:00
|
|
|
};
|
|
|
|
|
|
2026-06-15 16:11:37 +02:00
|
|
|
// On queue advance (active changes), sync local state to the new item.
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setStatus(active.status);
|
|
|
|
|
setCurrentVideoId(active.id);
|
|
|
|
|
currentIdRef.current = active.id;
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
}, [active.id]);
|
|
|
|
|
|
2026-06-12 17:39:20 +02:00
|
|
|
const seekTo = (seconds: number) => {
|
|
|
|
|
const p = playerRef.current;
|
|
|
|
|
if (p && typeof p.seekTo === "function") {
|
|
|
|
|
p.seekTo(seconds, true);
|
|
|
|
|
p.playVideo?.();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-04 22:25:37 +02:00
|
|
|
// Prev/next stepping through the queue (the feed's order, or a playlist). Read the live
|
|
|
|
|
// queue+index from a ref so the window keydown handler (bound once) always steps from the
|
|
|
|
|
// current position, not a stale closure.
|
|
|
|
|
const navRef = useRef({ queue, index });
|
|
|
|
|
navRef.current = { queue, index };
|
|
|
|
|
const goPrev = () => {
|
|
|
|
|
const { queue: q, index: i } = navRef.current;
|
|
|
|
|
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);
|
|
|
|
|
};
|
|
|
|
|
// Relative seek within the current video (plain Arrow keys), matching YouTube's ±5s.
|
|
|
|
|
const nudgeSeek = (delta: number) => {
|
|
|
|
|
const p = playerRef.current;
|
|
|
|
|
if (!p || typeof p.getCurrentTime !== "function") return;
|
|
|
|
|
p.seekTo(Math.max(0, (p.getCurrentTime() || 0) + delta), true);
|
|
|
|
|
};
|
|
|
|
|
|
2026-07-05 00:20:50 +02:00
|
|
|
// Auto-advance + loop are persistent per-user settings. Read the current values from the cached
|
|
|
|
|
// `me`, mirror them in local state for instant UI, and write both to the server + cache on change
|
|
|
|
|
// so they apply to every player and survive reloads. A ref feeds the (once-bound) end handler.
|
|
|
|
|
const savedPrefs = (qc.getQueryData<{ preferences?: Record<string, unknown> }>(["me"])
|
|
|
|
|
?.preferences ?? {}) as { playerAutoAdvance?: AutoMode; playerLoop?: LoopMode };
|
|
|
|
|
const [autoMode, setAutoMode] = useState<AutoMode>(savedPrefs.playerAutoAdvance ?? "off");
|
|
|
|
|
const [loopMode, setLoopMode] = useState<LoopMode>(savedPrefs.playerLoop ?? "off");
|
|
|
|
|
const modeRef = useRef({ autoMode, loopMode });
|
|
|
|
|
modeRef.current = { autoMode, loopMode };
|
|
|
|
|
const persistPref = (patch: Record<string, string>) => {
|
|
|
|
|
api.savePrefs(patch).catch(() => {});
|
|
|
|
|
qc.setQueryData<{ preferences?: Record<string, unknown> } | undefined>(["me"], (m) =>
|
|
|
|
|
m ? { ...m, preferences: { ...(m.preferences || {}), ...patch } } : m
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
const cycleAuto = () => {
|
|
|
|
|
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];
|
|
|
|
|
setLoopMode(next);
|
|
|
|
|
persistPref({ playerLoop: next });
|
|
|
|
|
};
|
|
|
|
|
const replayCurrent = () => {
|
|
|
|
|
const p = playerRef.current;
|
|
|
|
|
if (p && typeof p.seekTo === "function") {
|
|
|
|
|
p.seekTo(0, true);
|
|
|
|
|
p.playVideo?.();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
// Run when the current video ends, per the saved settings. Loop "one" repeats it; otherwise
|
|
|
|
|
// advance in the chosen direction, wrapping at the ends only when loop is "all" (a single-item
|
|
|
|
|
// list repeats). Uses the live queue + settings via refs so it's correct from the bound handler.
|
|
|
|
|
const advanceOnEnd = () => {
|
|
|
|
|
const { autoMode: a, loopMode: l } = modeRef.current;
|
|
|
|
|
if (l === "one") return replayCurrent();
|
|
|
|
|
const { queue: q, index: i } = navRef.current;
|
|
|
|
|
if (!q || q.length === 0) return;
|
|
|
|
|
const wrap = l === "all";
|
|
|
|
|
if (a === "next") {
|
|
|
|
|
if (i < q.length - 1) setPlayingId(q[i + 1].id);
|
|
|
|
|
else if (wrap) {
|
|
|
|
|
if (q.length === 1) replayCurrent();
|
|
|
|
|
else setPlayingId(q[0].id);
|
|
|
|
|
}
|
|
|
|
|
} else if (a === "prev") {
|
|
|
|
|
if (i > 0) setPlayingId(q[i - 1].id);
|
|
|
|
|
else if (wrap) {
|
|
|
|
|
if (q.length === 1) replayCurrent();
|
|
|
|
|
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);
|
|
|
|
|
} else if (a === "random" && wrap) {
|
|
|
|
|
replayCurrent();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-06-12 17:39:08 +02:00
|
|
|
// Lazy description (fetched only when the title is hovered). The popover is
|
|
|
|
|
// portaled to <body> with fixed positioning so the modal card's overflow-y-auto
|
|
|
|
|
// can't clip it. A small close grace lets the mouse travel title → popover.
|
2026-06-12 17:39:01 +02:00
|
|
|
const [showDesc, setShowDesc] = useState(false);
|
2026-06-12 17:39:08 +02:00
|
|
|
// `bottom` anchors the popover just above the title so it grows upward (over the
|
|
|
|
|
// player) instead of downward off-screen / behind the OS taskbar.
|
|
|
|
|
const [descRect, setDescRect] = useState<{ left: number; bottom: number; width: number } | null>(
|
|
|
|
|
null
|
|
|
|
|
);
|
2026-06-12 17:39:20 +02:00
|
|
|
const titleRef = useRef<HTMLSpanElement | null>(null);
|
2026-06-12 17:39:08 +02:00
|
|
|
const closeTimer = useRef<number | undefined>(undefined);
|
2026-07-04 22:25:37 +02:00
|
|
|
const openTimer = useRef<number | undefined>(undefined);
|
|
|
|
|
const openDescNow = () => {
|
2026-06-12 17:39:08 +02:00
|
|
|
window.clearTimeout(closeTimer.current);
|
2026-07-04 22:25:37 +02:00
|
|
|
window.clearTimeout(openTimer.current);
|
2026-06-12 17:39:08 +02:00
|
|
|
const el = titleRef.current;
|
|
|
|
|
if (el) {
|
|
|
|
|
const r = el.getBoundingClientRect();
|
2026-06-12 17:39:20 +02:00
|
|
|
const width = Math.min(560, window.innerWidth - 32);
|
|
|
|
|
const left = Math.max(16, Math.min(r.left, window.innerWidth - width - 16));
|
|
|
|
|
setDescRect({ left, bottom: window.innerHeight - r.top + 8, width });
|
2026-06-12 17:39:08 +02:00
|
|
|
}
|
|
|
|
|
setShowDesc(true);
|
|
|
|
|
};
|
2026-07-04 22:25:37 +02:00
|
|
|
// Hover-intent: only pop the description if the pointer lingers on the title (~400ms), so a
|
|
|
|
|
// quick pass over it doesn't flash the popover.
|
|
|
|
|
const scheduleOpenDesc = () => {
|
|
|
|
|
window.clearTimeout(closeTimer.current);
|
|
|
|
|
window.clearTimeout(openTimer.current);
|
|
|
|
|
openTimer.current = window.setTimeout(openDescNow, 400);
|
|
|
|
|
};
|
2026-06-12 17:39:08 +02:00
|
|
|
const scheduleCloseDesc = () => {
|
2026-07-04 22:25:37 +02:00
|
|
|
window.clearTimeout(openTimer.current);
|
2026-06-12 17:39:08 +02:00
|
|
|
closeTimer.current = window.setTimeout(() => setShowDesc(false), 150);
|
|
|
|
|
};
|
2026-06-12 17:39:01 +02:00
|
|
|
const detail = useQuery({
|
2026-06-12 17:39:20 +02:00
|
|
|
queryKey: ["video-detail", currentVideoId],
|
|
|
|
|
queryFn: () => api.videoDetail(currentVideoId),
|
|
|
|
|
// On hover (for the description) and eagerly when navigated, so we can link the
|
|
|
|
|
// linked video's channel. Both share the one cached result.
|
|
|
|
|
enabled: showDesc || navigated,
|
2026-06-12 17:39:01 +02:00
|
|
|
staleTime: 5 * 60_000,
|
|
|
|
|
});
|
2026-06-12 17:38:45 +02:00
|
|
|
|
2026-06-29 23:37:18 +02:00
|
|
|
// Keyboard shortcuts (Esc close / F fullscreen / Space play-pause) + background scroll lock.
|
|
|
|
|
// These fire only while focus is on our page, not inside the cross-origin player iframe — so
|
|
|
|
|
// we focus the modal card on open and again on player-ready (autoplay can grab focus).
|
2026-06-12 17:38:45 +02:00
|
|
|
useEffect(() => {
|
|
|
|
|
const onKey = (e: KeyboardEvent) => {
|
2026-06-29 23:37:18 +02:00
|
|
|
if (e.key === "Escape") {
|
|
|
|
|
// In fullscreen, let the browser's Esc exit fullscreen only — don't also close the modal.
|
|
|
|
|
if (document.fullscreenElement) return;
|
|
|
|
|
onClose();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const el = document.activeElement as HTMLElement | null;
|
|
|
|
|
const tag = (el?.tagName || "").toLowerCase();
|
|
|
|
|
const typing = tag === "input" || tag === "textarea" || tag === "select" || !!el?.isContentEditable;
|
|
|
|
|
if (e.key === "f" || e.key === "F") {
|
|
|
|
|
if (typing) return;
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
toggleFullscreen();
|
|
|
|
|
} else if (e.key === " " || e.code === "Space") {
|
|
|
|
|
// Let Space activate a focused button/link; otherwise toggle playback (and stop the
|
|
|
|
|
// page from scrolling).
|
|
|
|
|
if (typing || tag === "button" || tag === "a") return;
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
togglePlay();
|
2026-07-04 22:25:37 +02:00
|
|
|
} else if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
|
|
|
|
|
// Plain arrows seek within the video (YouTube-style ±5s); Shift+arrow steps to the
|
|
|
|
|
// previous/next video in the queue (the feed's order or a playlist).
|
|
|
|
|
if (typing) return;
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
const forward = e.key === "ArrowRight";
|
|
|
|
|
if (e.shiftKey) {
|
|
|
|
|
if (forward) goNext();
|
|
|
|
|
else goPrev();
|
|
|
|
|
} else {
|
|
|
|
|
nudgeSeek(forward ? 5 : -5);
|
|
|
|
|
}
|
2026-06-29 23:37:18 +02:00
|
|
|
}
|
2026-06-12 17:38:45 +02:00
|
|
|
};
|
|
|
|
|
window.addEventListener("keydown", onKey);
|
2026-06-29 23:37:18 +02:00
|
|
|
focusModal();
|
2026-06-12 17:38:45 +02:00
|
|
|
const prevOverflow = document.body.style.overflow;
|
|
|
|
|
document.body.style.overflow = "hidden";
|
|
|
|
|
return () => {
|
|
|
|
|
window.removeEventListener("keydown", onKey);
|
|
|
|
|
document.body.style.overflow = prevOverflow;
|
2026-06-12 17:39:08 +02:00
|
|
|
window.clearTimeout(closeTimer.current);
|
2026-07-04 22:25:37 +02:00
|
|
|
window.clearTimeout(openTimer.current);
|
2026-06-29 23:37:18 +02:00
|
|
|
window.clearTimeout(volTimerRef.current);
|
2026-06-12 17:38:45 +02:00
|
|
|
};
|
|
|
|
|
}, [onClose]);
|
|
|
|
|
|
2026-06-29 23:37:18 +02:00
|
|
|
// Mouse-wheel volume. A cross-origin iframe swallows wheel events, so we catch them on the
|
|
|
|
|
// interaction overlay above it (non-passive so preventDefault stops the modal scrolling).
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const el = overlayRef.current;
|
|
|
|
|
if (!el) return;
|
|
|
|
|
const onWheel = (e: WheelEvent) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
focusModal(); // re-grab focus if it had slipped into the native controls
|
|
|
|
|
nudgeVolume(e.deltaY < 0 ? 5 : -5);
|
|
|
|
|
};
|
|
|
|
|
el.addEventListener("wheel", onWheel, { passive: false });
|
|
|
|
|
return () => el.removeEventListener("wheel", onWheel);
|
|
|
|
|
// Re-attach if the overlay remounts (it's hidden while the embed shows an error).
|
|
|
|
|
}, [playerError]);
|
|
|
|
|
|
2026-06-12 17:39:01 +02:00
|
|
|
// Create the player, resume from the saved position, persist progress, and
|
|
|
|
|
// auto-mark watched once playback reaches the end.
|
2026-06-12 17:38:45 +02:00
|
|
|
useEffect(() => {
|
|
|
|
|
let cancelled = false;
|
2026-06-15 16:11:37 +02:00
|
|
|
const id = active.id;
|
|
|
|
|
autoMarkedRef.current = false;
|
2026-06-16 10:45:57 +02:00
|
|
|
setPlayerError(null);
|
2026-06-12 17:39:01 +02:00
|
|
|
|
2026-06-15 16:11:37 +02:00
|
|
|
// Auto-watch only applies to the active item — not to other videos the player
|
|
|
|
|
// navigated to via description links.
|
2026-06-17 13:38:47 +02:00
|
|
|
const maybeAutoWatch = (current: number, duration: number): boolean => {
|
|
|
|
|
if (autoMarkedRef.current || duration <= 0 || currentIdRef.current !== id) return false;
|
2026-06-12 17:39:01 +02:00
|
|
|
if (current > duration - FINISH_MARGIN) {
|
|
|
|
|
autoMarkedRef.current = true;
|
|
|
|
|
setWatched(true);
|
2026-06-17 13:38:47 +02:00
|
|
|
return true;
|
2026-06-12 17:39:01 +02:00
|
|
|
}
|
2026-06-17 13:38:47 +02:00
|
|
|
return false;
|
2026-06-12 17:39:01 +02:00
|
|
|
};
|
2026-06-14 18:40:12 +02:00
|
|
|
const persist = (): Promise<unknown> | void => {
|
2026-06-12 17:38:45 +02:00
|
|
|
const p = playerRef.current;
|
|
|
|
|
if (!p || typeof p.getCurrentTime !== "function") return;
|
|
|
|
|
try {
|
2026-06-12 17:39:01 +02:00
|
|
|
const cur = p.getCurrentTime();
|
|
|
|
|
const dur = typeof p.getDuration === "function" ? p.getDuration() : 0;
|
2026-06-17 13:38:47 +02:00
|
|
|
// If we just auto-marked watched, skip the near-end progress checkpoint: it would
|
|
|
|
|
// only clear the resume position, and firing both at once needlessly races the
|
|
|
|
|
// watched write against the progress row it deletes.
|
|
|
|
|
if (maybeAutoWatch(cur, dur)) return;
|
2026-06-14 18:40:12 +02:00
|
|
|
// Only checkpoint the feed video we opened with — a navigated-to video may not
|
|
|
|
|
// be in this user's library, so the server would 404 on it.
|
|
|
|
|
if (currentIdRef.current === id) {
|
|
|
|
|
return api.saveProgress(id, cur, dur).catch(() => {});
|
|
|
|
|
}
|
2026-06-12 17:38:45 +02:00
|
|
|
} catch {
|
|
|
|
|
/* player may be tearing down */
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
loadYouTubeApi().then((YT) => {
|
|
|
|
|
if (cancelled || !mountRef.current) return;
|
|
|
|
|
playerRef.current = new YT.Player(mountRef.current, {
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
videoId: id,
|
|
|
|
|
playerVars: {
|
|
|
|
|
autoplay: 1,
|
2026-06-14 18:40:12 +02:00
|
|
|
start: resumeAt || undefined,
|
2026-06-12 17:38:45 +02:00
|
|
|
rel: 0, // limit "related" to the same channel (full removal is no longer possible)
|
|
|
|
|
enablejsapi: 1,
|
|
|
|
|
origin: window.location.origin,
|
|
|
|
|
playsinline: 1,
|
|
|
|
|
},
|
2026-06-12 17:39:01 +02:00
|
|
|
events: {
|
2026-06-29 23:37:18 +02:00
|
|
|
// Keep keyboard focus on the modal, not the iframe, so shortcuts work right away.
|
|
|
|
|
onReady: () => focusModal(),
|
2026-06-12 17:39:01 +02:00
|
|
|
onStateChange: (e: any) => {
|
2026-06-12 17:39:20 +02:00
|
|
|
// 1 === playing → sync the navigated-to video's title/author for display.
|
|
|
|
|
if (e?.data === 1) {
|
|
|
|
|
const p = playerRef.current;
|
|
|
|
|
const d = p && typeof p.getVideoData === "function" ? p.getVideoData() : null;
|
|
|
|
|
if (d) setLiveData({ title: d.title, author: d.author });
|
|
|
|
|
}
|
2026-06-15 16:11:37 +02:00
|
|
|
// 0 === ended → mark watched, then advance to the next queue item if any.
|
|
|
|
|
if (e?.data === 0 && currentIdRef.current === id) {
|
|
|
|
|
if (!autoMarkedRef.current) {
|
|
|
|
|
autoMarkedRef.current = true;
|
|
|
|
|
setWatched(true);
|
|
|
|
|
}
|
2026-07-05 00:20:50 +02:00
|
|
|
advanceOnEnd();
|
2026-06-12 17:39:01 +02:00
|
|
|
}
|
|
|
|
|
},
|
2026-06-16 10:45:57 +02:00
|
|
|
// The embed couldn't play this video (embedding disabled, removed, private…).
|
|
|
|
|
// Surface our own message + an "Open on YouTube" escape hatch.
|
|
|
|
|
onError: (e: any) => setPlayerError(typeof e?.data === "number" ? e.data : -1),
|
2026-06-12 17:39:01 +02:00
|
|
|
},
|
2026-06-12 17:38:45 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2026-06-12 17:39:01 +02:00
|
|
|
// Periodic checkpoint so progress (and auto-watch) survive a crash/refresh.
|
2026-06-12 17:38:45 +02:00
|
|
|
const timer = window.setInterval(persist, 5000);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
cancelled = true;
|
|
|
|
|
window.clearInterval(timer);
|
2026-06-15 16:11:37 +02:00
|
|
|
// Final flush, then refresh the feed + playlists so resume bars reflect this session.
|
|
|
|
|
Promise.resolve(persist()).finally(() => {
|
|
|
|
|
qc.invalidateQueries({ queryKey: ["feed"] });
|
|
|
|
|
qc.invalidateQueries({ queryKey: ["playlist"] });
|
|
|
|
|
});
|
2026-06-12 17:38:45 +02:00
|
|
|
const p = playerRef.current;
|
|
|
|
|
if (p && typeof p.destroy === "function") {
|
|
|
|
|
try {
|
|
|
|
|
p.destroy();
|
|
|
|
|
} catch {
|
|
|
|
|
/* ignore */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
playerRef.current = null;
|
|
|
|
|
};
|
2026-06-12 17:39:01 +02:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2026-06-15 16:11:37 +02:00
|
|
|
}, [active.id]);
|
2026-06-12 17:38:45 +02:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
className="fixed inset-0 z-50 flex items-center justify-center p-4 sm:p-6 bg-black/80 backdrop-blur-sm"
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
role="dialog"
|
|
|
|
|
aria-modal="true"
|
|
|
|
|
>
|
2026-07-04 23:42:13 +02:00
|
|
|
{/* The card, flanked by full-height glassy strips that step through the feed's order (or a
|
|
|
|
|
playlist). Each strip sits just outside the card, spans its full height, and fades out at
|
|
|
|
|
the ends. stopPropagation so a click steps instead of closing. Hidden on narrow screens
|
|
|
|
|
where there's no room beside the card. */}
|
|
|
|
|
<div className="relative flex w-full max-w-4xl max-h-full">
|
|
|
|
|
{hasQueue && (
|
2026-07-04 22:25:37 +02:00
|
|
|
<button
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
goPrev();
|
|
|
|
|
}}
|
|
|
|
|
disabled={index === 0}
|
|
|
|
|
aria-label={t("player.previous")}
|
2026-07-04 23:20:02 +02:00
|
|
|
title={`${t("player.previous")} · Shift+←`}
|
2026-07-04 23:42:13 +02:00
|
|
|
className="absolute right-full top-0 bottom-0 mr-2 hidden w-12 place-items-center rounded-2xl bg-white/5 text-white/40 backdrop-blur-sm transition hover:bg-white/15 hover:text-white disabled:pointer-events-none disabled:opacity-0 sm:grid"
|
2026-07-04 22:25:37 +02:00
|
|
|
>
|
2026-07-04 23:42:13 +02:00
|
|
|
<ChevronLeft className="h-8 w-8" />
|
2026-07-04 22:25:37 +02:00
|
|
|
</button>
|
2026-07-04 23:42:13 +02:00
|
|
|
)}
|
2026-06-12 17:38:45 +02:00
|
|
|
<div
|
2026-06-29 23:37:18 +02:00
|
|
|
ref={cardRef}
|
|
|
|
|
tabIndex={-1}
|
2026-07-04 23:42:13 +02:00
|
|
|
className="glass-card relative flex-1 min-w-0 max-h-full overflow-y-auto rounded-2xl shadow-2xl outline-none"
|
2026-06-12 17:38:45 +02:00
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
|
>
|
2026-06-29 23:37:18 +02:00
|
|
|
<div
|
|
|
|
|
ref={stageRef}
|
|
|
|
|
className="player-stage relative aspect-video w-full bg-black rounded-t-2xl overflow-hidden"
|
|
|
|
|
>
|
2026-06-16 11:58:57 +02:00
|
|
|
{/* Hide the iframe entirely on error so YouTube's own error screen can't bleed
|
|
|
|
|
through our overlay. */}
|
|
|
|
|
<div ref={mountRef} className={`w-full h-full ${playerError != null ? "invisible" : ""}`} />
|
2026-07-04 22:25:37 +02:00
|
|
|
{/* Interaction layer over the CENTRE of the video: catches the scroll wheel (volume)
|
|
|
|
|
and click (play/pause), and stops the iframe stealing keyboard focus. It deliberately
|
|
|
|
|
leaves the top AND bottom edges uncovered so YouTube's native controls — the top-right
|
|
|
|
|
cluster (volume / CC / settings) and the bottom bar (seek / More videos / fullscreen)
|
|
|
|
|
— stay clickable. Hidden on error so the "Open on YouTube" CTA is clickable. */}
|
2026-06-29 23:37:18 +02:00
|
|
|
{playerError == null && (
|
|
|
|
|
<div
|
|
|
|
|
ref={overlayRef}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
focusModal();
|
|
|
|
|
togglePlay();
|
|
|
|
|
}}
|
|
|
|
|
title={t("player.shortcutsHint")}
|
|
|
|
|
aria-label={t("player.shortcutsHint")}
|
2026-07-04 22:25:37 +02:00
|
|
|
className="absolute inset-x-0 top-[12%] bottom-[22%] z-10 cursor-pointer"
|
2026-06-29 23:37:18 +02:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
{/* Volume level flash (auto-fades). pointer-events-none so it never blocks the video. */}
|
|
|
|
|
{volumeUi != null && (
|
|
|
|
|
<div className="pointer-events-none absolute top-3 left-1/2 -translate-x-1/2 z-20 flex items-center gap-2 rounded-full bg-black/70 px-3 py-1.5 text-xs text-white shadow-lg">
|
|
|
|
|
{volumeUi === 0 ? <VolumeX className="h-4 w-4" /> : <Volume2 className="h-4 w-4" />}
|
|
|
|
|
<div className="h-1.5 w-28 overflow-hidden rounded-full bg-white/25">
|
|
|
|
|
<div className="h-full rounded-full bg-white transition-all" style={{ width: `${volumeUi}%` }} />
|
|
|
|
|
</div>
|
|
|
|
|
<span className="w-7 text-right tabular-nums">{volumeUi}</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-06-16 10:45:57 +02:00
|
|
|
{playerError != null && (
|
2026-06-16 11:58:57 +02:00
|
|
|
<div className="absolute inset-0 grid place-items-center bg-bg p-6 text-center">
|
2026-06-16 10:45:57 +02:00
|
|
|
<div className="max-w-sm">
|
|
|
|
|
<AlertTriangle className="w-8 h-8 text-amber-500 mx-auto mb-3" />
|
|
|
|
|
<h3 className="text-base font-semibold">{t("player.unavailableTitle")}</h3>
|
|
|
|
|
<p className="text-sm text-muted mt-1.5 mb-4">
|
|
|
|
|
{playerError === 101 || playerError === 150
|
|
|
|
|
? t("player.embedDisabledBody")
|
|
|
|
|
: t("player.unavailableBody")}
|
|
|
|
|
</p>
|
|
|
|
|
<a
|
|
|
|
|
href={`https://www.youtube.com/watch?v=${currentVideoId}`}
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
className="inline-flex items-center justify-center gap-2 px-4 py-2 rounded-xl font-semibold bg-accent text-accent-fg hover:opacity-90 transition"
|
|
|
|
|
>
|
|
|
|
|
<ExternalLink className="w-4 h-4" />
|
|
|
|
|
{t("player.openOnYoutube")}
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-06-12 17:38:45 +02:00
|
|
|
</div>
|
|
|
|
|
|
2026-06-15 16:11:37 +02:00
|
|
|
{hasQueue && (
|
2026-07-05 00:20:50 +02:00
|
|
|
<div className="flex flex-wrap items-center justify-center gap-x-4 gap-y-1.5 px-4 py-2 border-b border-border text-sm">
|
2026-06-15 16:11:37 +02:00
|
|
|
<button
|
2026-06-15 16:27:28 +02:00
|
|
|
onClick={() => index > 0 && setPlayingId(queue![index - 1].id)}
|
2026-06-15 16:11:37 +02:00
|
|
|
disabled={index === 0}
|
2026-07-04 23:20:02 +02:00
|
|
|
title={`${t("player.previous")} · Shift+←`}
|
2026-06-15 16:11:37 +02:00
|
|
|
className="inline-flex items-center gap-1.5 text-muted enabled:hover:text-fg disabled:opacity-40 transition"
|
|
|
|
|
>
|
|
|
|
|
<SkipBack className="w-4 h-4" /> {t("player.previous")}
|
|
|
|
|
</button>
|
|
|
|
|
<span className="text-muted tabular-nums">
|
|
|
|
|
{index + 1} / {queue!.length}
|
|
|
|
|
</span>
|
|
|
|
|
<button
|
2026-06-15 16:27:28 +02:00
|
|
|
onClick={() => index < queue!.length - 1 && setPlayingId(queue![index + 1].id)}
|
2026-06-15 16:11:37 +02:00
|
|
|
disabled={index === queue!.length - 1}
|
2026-07-04 23:20:02 +02:00
|
|
|
title={`${t("player.next")} · Shift+→`}
|
2026-06-15 16:11:37 +02:00
|
|
|
className="inline-flex items-center gap-1.5 text-muted enabled:hover:text-fg disabled:opacity-40 transition"
|
|
|
|
|
>
|
|
|
|
|
{t("player.next")} <SkipForward className="w-4 h-4" />
|
|
|
|
|
</button>
|
2026-07-05 00:20:50 +02:00
|
|
|
<span className="w-px h-4 bg-border" />
|
|
|
|
|
{/* Persistent playback settings — cycle on click, saved to your account. */}
|
|
|
|
|
<button
|
|
|
|
|
onClick={cycleAuto}
|
|
|
|
|
title={t("player.autoAdvance.hint")}
|
|
|
|
|
className={`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 transition ${
|
|
|
|
|
autoMode !== "off" ? "bg-accent/15 text-accent" : "text-muted hover:bg-surface hover:text-fg"
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
{autoMode === "prev" ? (
|
|
|
|
|
<SkipBack className="h-3.5 w-3.5" />
|
|
|
|
|
) : autoMode === "random" ? (
|
|
|
|
|
<Shuffle className="h-3.5 w-3.5" />
|
|
|
|
|
) : (
|
|
|
|
|
<SkipForward className="h-3.5 w-3.5" />
|
|
|
|
|
)}
|
|
|
|
|
{t("player.autoAdvance.label")}: {t(`player.autoAdvance.${autoMode}`)}
|
|
|
|
|
</button>
|
|
|
|
|
<button
|
|
|
|
|
onClick={cycleLoop}
|
|
|
|
|
title={t("player.loop.hint")}
|
|
|
|
|
className={`inline-flex items-center gap-1.5 rounded-lg px-2.5 py-1 transition ${
|
|
|
|
|
loopMode !== "off" ? "bg-accent/15 text-accent" : "text-muted hover:bg-surface hover:text-fg"
|
|
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
{loopMode === "one" ? <Repeat1 className="h-3.5 w-3.5" /> : <Repeat className="h-3.5 w-3.5" />}
|
|
|
|
|
{t("player.loop.label")}: {t(`player.loop.${loopMode}`)}
|
|
|
|
|
</button>
|
2026-06-15 16:11:37 +02:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-06-12 17:38:45 +02:00
|
|
|
<div className="p-4 sm:p-5">
|
2026-06-12 17:39:01 +02:00
|
|
|
{/* Title row — title (with hover description) on the left, Close on the right. */}
|
|
|
|
|
<div className="flex items-start gap-3">
|
2026-06-12 17:39:20 +02:00
|
|
|
<h2 className="min-w-0 flex-1 text-lg font-semibold leading-snug">
|
|
|
|
|
{/* Hover target is the text itself (inline), not the whole row. */}
|
|
|
|
|
<span
|
|
|
|
|
ref={titleRef}
|
|
|
|
|
className="cursor-default"
|
2026-07-04 22:25:37 +02:00
|
|
|
onMouseEnter={scheduleOpenDesc}
|
2026-06-12 17:39:20 +02:00
|
|
|
onMouseLeave={scheduleCloseDesc}
|
|
|
|
|
>
|
2026-06-15 16:11:37 +02:00
|
|
|
{navigated ? liveData?.title ?? t("player.loading") : active.title}
|
2026-06-12 17:39:20 +02:00
|
|
|
</span>
|
|
|
|
|
</h2>
|
|
|
|
|
{navigated && (
|
|
|
|
|
<button
|
2026-06-15 16:11:37 +02:00
|
|
|
onClick={() => loadVideo(active.id, null)}
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
title={t("player.backToOriginal")}
|
2026-06-12 17:39:20 +02:00
|
|
|
className="shrink-0 inline-flex items-center gap-1.5 text-sm px-3 py-1.5 rounded-lg text-muted hover:text-fg hover:bg-surface transition"
|
|
|
|
|
>
|
|
|
|
|
<ArrowLeft className="w-4 h-4" />
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
{t("player.back")}
|
2026-06-12 17:39:20 +02:00
|
|
|
</button>
|
|
|
|
|
)}
|
2026-06-12 17:39:08 +02:00
|
|
|
{showDesc &&
|
|
|
|
|
descRect &&
|
|
|
|
|
createPortal(
|
|
|
|
|
<div
|
|
|
|
|
className="fixed z-[60] bg-surface border border-border rounded-xl shadow-2xl p-4"
|
|
|
|
|
style={{
|
|
|
|
|
left: descRect.left,
|
|
|
|
|
bottom: descRect.bottom,
|
|
|
|
|
width: descRect.width,
|
|
|
|
|
}}
|
2026-07-04 22:25:37 +02:00
|
|
|
onMouseEnter={openDescNow}
|
2026-06-12 17:39:08 +02:00
|
|
|
onMouseLeave={scheduleCloseDesc}
|
|
|
|
|
>
|
2026-06-12 17:39:01 +02:00
|
|
|
<div className="text-xs uppercase tracking-wide text-muted mb-2">
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
{t("player.description")}
|
2026-06-12 17:39:01 +02:00
|
|
|
</div>
|
|
|
|
|
{detail.isLoading ? (
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
<div className="text-sm text-muted">{t("player.loading")}</div>
|
2026-06-12 17:39:01 +02:00
|
|
|
) : detail.data?.description ? (
|
2026-06-12 17:39:20 +02:00
|
|
|
<div className="text-sm whitespace-pre-wrap break-words max-h-64 overflow-y-auto leading-relaxed">
|
|
|
|
|
{renderDescription(detail.data.description, {
|
|
|
|
|
currentId: currentVideoId,
|
|
|
|
|
onSeek: seekTo,
|
|
|
|
|
onLoadVideo: loadVideo,
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
t,
|
2026-06-12 17:39:20 +02:00
|
|
|
})}
|
2026-06-12 17:39:01 +02:00
|
|
|
</div>
|
|
|
|
|
) : (
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
<div className="text-sm text-muted">{t("player.noDescription")}</div>
|
2026-06-12 17:39:01 +02:00
|
|
|
)}
|
2026-06-12 17:39:08 +02:00
|
|
|
</div>,
|
|
|
|
|
document.body
|
2026-06-12 17:39:01 +02:00
|
|
|
)}
|
|
|
|
|
<button
|
|
|
|
|
onClick={onClose}
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
title={t("player.closeEsc")}
|
2026-06-12 17:39:01 +02:00
|
|
|
className="shrink-0 inline-flex items-center gap-1.5 text-sm px-3 py-1.5 rounded-lg text-muted hover:text-fg hover:bg-surface transition"
|
|
|
|
|
>
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
{t("player.close")}
|
2026-06-12 17:39:01 +02:00
|
|
|
<X className="w-4 h-4" />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2026-06-12 17:38:45 +02:00
|
|
|
|
2026-06-12 17:39:20 +02:00
|
|
|
{/* Channel + meta on one line, with the watched toggle pushed to the right.
|
|
|
|
|
When navigated to a linked video we only have its author (from the player),
|
|
|
|
|
so we show that as plain text and hide feed-video-specific bits. */}
|
2026-06-12 17:38:45 +02:00
|
|
|
<div className="flex items-center gap-3 mt-3">
|
2026-06-12 18:01:43 +02:00
|
|
|
{!navigated && (
|
|
|
|
|
<Avatar
|
2026-06-15 16:11:37 +02:00
|
|
|
src={active.channel_thumbnail}
|
|
|
|
|
fallback={active.channel_title ?? ""}
|
2026-06-12 17:39:01 +02:00
|
|
|
className="w-9 h-9 rounded-full shrink-0"
|
2026-06-12 17:38:45 +02:00
|
|
|
/>
|
|
|
|
|
)}
|
2026-06-12 17:39:20 +02:00
|
|
|
{navigated ? (
|
|
|
|
|
detail.data?.channel_id ? (
|
|
|
|
|
<a
|
2026-06-19 03:22:10 +02:00
|
|
|
href={channelYouTubeUrl(detail.data.channel_id)}
|
2026-06-12 17:39:20 +02:00
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
className="font-medium hover:text-accent shrink-0"
|
|
|
|
|
>
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
{liveData?.author ?? detail.data.channel_title ?? t("player.channel")}
|
2026-06-12 17:39:20 +02:00
|
|
|
</a>
|
|
|
|
|
) : (
|
|
|
|
|
<span className="font-medium shrink-0">{liveData?.author ?? ""}</span>
|
|
|
|
|
)
|
|
|
|
|
) : (
|
2026-06-30 03:12:44 +02:00
|
|
|
<div className="flex items-center gap-1.5 shrink-0 min-w-0">
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => {
|
2026-06-30 04:14:14 +02:00
|
|
|
if (!onOpenChannel) return onClose();
|
|
|
|
|
const cid = active.channel_id;
|
|
|
|
|
const cname = active.channel_title ?? undefined;
|
|
|
|
|
// Closing the player pops its own history entry (useBackToClose → history.back()).
|
|
|
|
|
// Open the channel only AFTER that pop's popstate — pushing the channel entry
|
|
|
|
|
// before it would let the back remove it again (the bug: clicking the name only
|
|
|
|
|
// closed the player). One-shot listener fires after App's popstate handler.
|
|
|
|
|
const open = () => {
|
|
|
|
|
window.removeEventListener("popstate", open);
|
|
|
|
|
onOpenChannel(cid, cname);
|
|
|
|
|
};
|
|
|
|
|
window.addEventListener("popstate", open);
|
2026-06-30 03:12:44 +02:00
|
|
|
onClose();
|
|
|
|
|
}}
|
|
|
|
|
className="font-medium hover:text-accent truncate text-left"
|
|
|
|
|
>
|
|
|
|
|
{active.channel_title}
|
|
|
|
|
</button>
|
|
|
|
|
<a
|
|
|
|
|
href={active.channel_url}
|
|
|
|
|
target="_blank"
|
|
|
|
|
rel="noreferrer"
|
|
|
|
|
title={t("channels.row.openOnYouTube")}
|
|
|
|
|
aria-label={t("channels.row.openOnYouTube")}
|
|
|
|
|
className="text-muted hover:text-accent shrink-0"
|
|
|
|
|
>
|
|
|
|
|
<ExternalLink className="w-3.5 h-3.5" />
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
2026-06-12 17:39:20 +02:00
|
|
|
)}
|
|
|
|
|
{!navigated ? (
|
|
|
|
|
<div className="flex flex-wrap items-center gap-x-2 gap-y-0.5 text-sm text-muted min-w-0">
|
2026-06-15 16:11:37 +02:00
|
|
|
{active.view_count != null && (
|
|
|
|
|
<span>· {t("player.views", { count: active.view_count, formattedCount: formatViews(active.view_count) })}</span>
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
)}
|
2026-06-16 03:09:28 +02:00
|
|
|
<span>
|
|
|
|
|
· {relativeTime(active.published_at)}
|
|
|
|
|
{active.published_at && ` · ${fullDate(active.published_at)}`}
|
|
|
|
|
</span>
|
2026-06-15 16:11:37 +02:00
|
|
|
{active.duration_seconds != null && (
|
|
|
|
|
<span>· {formatDuration(active.duration_seconds)}</span>
|
2026-06-12 17:39:20 +02:00
|
|
|
)}
|
2026-06-15 16:11:37 +02:00
|
|
|
{active.live_status === "was_live" && (
|
2026-06-12 17:39:20 +02:00
|
|
|
<span className="bg-accent text-accent-fg text-[10px] font-semibold uppercase tracking-wide px-1.5 py-0.5 rounded">
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
{t("player.stream")}
|
2026-06-12 17:39:20 +02:00
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
// Linked video's stats come from the (already-fetched) video detail.
|
|
|
|
|
<div className="flex flex-wrap items-center gap-x-2 gap-y-0.5 text-sm text-muted min-w-0">
|
|
|
|
|
{detail.data?.view_count != null && (
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
<span>· {t("player.views", { count: detail.data.view_count, formattedCount: formatViews(detail.data.view_count) })}</span>
|
2026-06-12 17:39:20 +02:00
|
|
|
)}
|
2026-06-16 03:09:28 +02:00
|
|
|
{detail.data?.published_at && (
|
|
|
|
|
<span>
|
|
|
|
|
· {relativeTime(detail.data.published_at)} · {fullDate(detail.data.published_at)}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2026-06-12 17:39:20 +02:00
|
|
|
{detail.data?.duration_seconds != null && (
|
|
|
|
|
<span>· {formatDuration(detail.data.duration_seconds)}</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-06-12 17:38:45 +02:00
|
|
|
|
2026-06-15 14:45:18 +02:00
|
|
|
{!navigated && (
|
|
|
|
|
<AddToPlaylist
|
2026-06-15 16:11:37 +02:00
|
|
|
videoId={active.id}
|
2026-06-15 14:45:18 +02:00
|
|
|
className="ml-auto shrink-0 inline-flex items-center justify-center w-9 h-9 rounded-lg text-muted hover:text-fg hover:bg-surface border border-border transition"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
feat(downloads): M5 — Download Center frontend
- api.ts: download types + methods (profiles, enqueue, list/manage, file url, share,
usage, index, admin storage/quota)
- format.ts: formatBytes / formatSpeed
- i18n: en/hu/de downloads.json (trilingual)
- Downloads nav module (Download icon, active-count badge, hidden for demo) placed after
Messages; urlState page + App render + Header title
- DownloadButton: self-contained per-card/player affordance (demo-hidden, reflects the
per-user download index: downloaded / in-queue), opens the preset dialog
- DownloadDialog: preset picker + optional display name -> enqueue + 'View' toast
- ProfileEditor: manage built-in + custom formats (full spec form incl. SponsorBlock)
- DownloadCenter: Queue / Library / Shared / (admin) System tabs, live progress via
useLiveQuery, usage bar, pause/resume/cancel/delete, save-to-device, rename, share,
admin storage dashboard + per-user quota editor
- wired DownloadButton into VideoCard + PlayerModal
- lib/nav.ts: decoupled navigator so the download toast can jump to the page
tsc + vite build clean. Verified in a headless authed browser: page + tabs render, Library
shows a real download with usage bar + actions, no console errors.
2026-07-03 01:52:58 +02:00
|
|
|
{!navigated && (
|
|
|
|
|
<DownloadButton
|
|
|
|
|
videoId={active.id}
|
|
|
|
|
title={active.title}
|
|
|
|
|
className="shrink-0 inline-flex items-center justify-center w-9 h-9 rounded-lg text-muted hover:text-fg hover:bg-surface border border-border transition"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2026-06-12 17:39:20 +02:00
|
|
|
{!navigated && (
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => setWatched(!watched)}
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
title={watched ? t("player.watchedUnmark") : t("player.markWatched")}
|
2026-06-12 17:39:20 +02:00
|
|
|
className={
|
2026-06-15 14:45:18 +02:00
|
|
|
"shrink-0 inline-flex items-center gap-1.5 text-sm px-3 py-1.5 rounded-lg transition " +
|
2026-06-12 17:39:20 +02:00
|
|
|
(watched
|
|
|
|
|
? "bg-accent text-accent-fg shadow-sm hover:opacity-90"
|
|
|
|
|
: "text-muted hover:text-fg hover:bg-surface border border-border")
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
{watched ? <CheckCheck className="w-4 h-4" /> : <Check className="w-4 h-4" />}
|
feat(i18n): translate remaining components (HU/EN/DE)
Feed, VideoCard, Sidebar, PlayerModal, Channels, Stats, SettingsPanel,
OnboardingWizard, NotificationCenter, Toaster, ErrorBoundary and the relativeTime
helper are now fully translated in Hungarian, English and German, each with its own
locale area file (auto-loaded). Key parity verified across all three languages.
2026-06-15 00:47:04 +02:00
|
|
|
{watched ? t("player.watched") : t("player.markWatched")}
|
2026-06-12 17:39:20 +02:00
|
|
|
</button>
|
|
|
|
|
)}
|
2026-06-12 17:38:45 +02:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-07-04 23:42:13 +02:00
|
|
|
{hasQueue && (
|
|
|
|
|
<button
|
|
|
|
|
onClick={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
goNext();
|
|
|
|
|
}}
|
|
|
|
|
disabled={index >= queue!.length - 1}
|
|
|
|
|
aria-label={t("player.next")}
|
|
|
|
|
title={`${t("player.next")} · Shift+→`}
|
|
|
|
|
className="absolute left-full top-0 bottom-0 ml-2 hidden w-12 place-items-center rounded-2xl bg-white/5 text-white/40 backdrop-blur-sm transition hover:bg-white/15 hover:text-white disabled:pointer-events-none disabled:opacity-0 sm:grid"
|
|
|
|
|
>
|
|
|
|
|
<ChevronRight className="h-8 w-8" />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2026-06-12 17:38:45 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|