feat: make watch page a single-video swipe feed

This commit is contained in:
Zhou Weidong committed 2026-11-10 16:25:50 +08:00
1 parent b2e4374ddc
commit 02ccf0ddc4
2 files changed
+10 -11

No files matched your search

+1
View File
@@ -1,4 +1,5 @@
/* Author: fruit.com.cn */
.single-video-page{position:fixed;inset:64px 0 0;background:#050505;z-index:2}.single-video-toolbar{position:absolute;top:0;left:0;right:0;height:58px;z-index:3;display:flex;align-items:center;gap:14px;padding:0 24px;background:linear-gradient(#000b,transparent);pointer-events:none}.single-video-toolbar button{pointer-events:auto;border:0;background:#0008;color:#fff;border-radius:50%;width:34px;height:34px;font-size:20px}.single-video-toolbar img{width:72px;height:34px;object-fit:contain}.single-video-toolbar span{color:#ddd;font-size:12px}.single-video-feed{height:100%;overflow-y:auto;scroll-snap-type:y mandatory;overscroll-behavior-y:contain}.single-video-feed>div{height:100%;scroll-snap-align:start}.single-video-slide{position:relative;height:100%;max-width:900px;margin:0 auto;background:#111}.single-video-stage,.single-video-stage .video-player,.single-video-placeholder{width:100%;height:100%;object-fit:contain;background:#050505}.single-video-placeholder{position:relative;display:grid;place-items:center}.single-video-placeholder img{width:100%;height:100%;object-fit:cover;opacity:.38}.single-video-placeholder span{position:absolute;background:#000b;border-radius:10px;padding:12px 16px;color:#fff}.single-video-info{position:absolute;left:28px;right:28px;bottom:28px;text-shadow:0 2px 14px #000}.single-video-info span{color:#ff786f;font-size:11px;letter-spacing:.12em}.single-video-info h1{margin:7px 0;font:700 28px Outfit}.single-video-info p{margin:0;color:#ddd}@media(max-width:760px){.single-video-page{inset:58px 0 0}.single-video-toolbar{padding:0 14px}.single-video-feed>div,.single-video-slide{height:100dvh}.single-video-info{left:20px;right:20px;bottom:34px}.single-video-info h1{font-size:23px}}
.youtube-watch-layout{display:grid;grid-template-columns:minmax(0,1fr) 330px;gap:28px;max-width:1320px;margin:0 auto}.watch-main{min-width:0}.watch-channel-bar{display:flex;align-items:center;gap:12px;margin-bottom:16px}.watch-channel-bar img{width:72px;height:34px;object-fit:contain}.watch-channel-bar div{display:grid;gap:3px}.watch-channel-bar small{color:#999}.watch-channel-bar button{margin-left:auto;border:0;border-radius:20px;padding:10px 16px;background:#fff;color:#111;font-weight:600}.episode-feed{display:grid;gap:20px;scroll-snap-type:y mandatory}.episode-slide{position:relative;min-height:min(72vh,700px);scroll-snap-align:start;overflow:hidden;border-radius:16px;background:#111}.episode-slide-player{height:100%;min-height:min(72vh,700px)}.episode-slide-player .video-player,.episode-slide-placeholder{width:100%;height:100%;min-height:min(72vh,700px);object-fit:contain;background:#050505}.episode-slide-placeholder{position:relative;display:grid;place-items:center}.episode-slide-placeholder img{width:100%;height:100%;object-fit:cover;opacity:.42}.episode-slide-placeholder span{position:absolute;color:#fff;padding:12px 16px;border-radius:10px;background:#000b}.episode-slide-caption{position:absolute;left:24px;right:24px;bottom:20px;text-shadow:0 2px 15px #000}.episode-slide-caption span{color:#ff786f;font-size:11px;letter-spacing:.12em}.episode-slide-caption h2{margin:6px 0;font:700 26px Outfit}.episode-slide-caption p{margin:0;color:#ddd}.watch-sidebar{display:grid;align-content:start;gap:24px}.episode-list-panel{padding:16px;border:1px solid #303030;border-radius:14px;background:#171717}.episode-list-title{display:flex;align-items:center;gap:9px;margin-bottom:12px}.episode-list-title h2,.watch-recommendations h2{margin:0;font:700 20px Outfit}.episode-list-title span{color:#999}.episode-list-panel button{display:flex;align-items:center;gap:10px;width:100%;padding:10px;border:0;border-radius:8px;background:transparent;color:#ccc;text-align:left;cursor:pointer}.episode-list-panel button:hover,.episode-list-panel button.active{background:#3a2223;color:#fff}.episode-list-panel button b{color:#ff786f}.episode-list-panel button span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.episode-list-panel button small{margin-left:auto}.watch-recommendations .media-card{margin-top:14px}@media(max-width:900px){.youtube-watch-layout{display:block}.watch-sidebar{margin-top:20px}.episode-slide,.episode-slide-player,.episode-slide-player .video-player,.episode-slide-placeholder{min-height:calc(100dvh - 190px)}.episode-feed{margin:0 -14px}.episode-slide{border-radius:0}.episode-slide-caption{bottom:28px}.watch-channel-bar,.watch-title,.watch-subtitle{margin-left:14px;margin-right:14px}}
.episode-picker{margin-top:24px;padding-top:20px;border-top:1px solid var(--line)}.episode-picker-heading{display:flex;align-items:center;gap:10px;margin-bottom:14px}.episode-picker-heading h2{margin:0;font:700 20px Outfit}.episode-picker-heading span{display:grid;place-items:center;min-width:24px;height:24px;border-radius:50%;background:#292929;color:#aaa;font-size:11px}.episode-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(120px,1fr));gap:10px}.episode-button{display:flex;align-items:center;gap:8px;min-height:48px;padding:8px 10px;border:1px solid #373737;border-radius:9px;background:#181818;color:#ddd;text-align:left;cursor:pointer}.episode-button:hover,.episode-button.active{border-color:#ff786f;background:#3a2223;color:#fff}.episode-button b{font-size:16px;color:#ff786f}.episode-button span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px}.episode-button small{margin-left:auto}.episode-button.locked{opacity:.72}@media(max-width:760px){.episode-grid{grid-template-columns:repeat(3,1fr)}.episode-button{min-width:0;padding:8px}.episode-button span{display:none}.episode-button b{margin:auto}}
.sidebar nav a.active{background:#272727;color:#fff}.media-card{min-width:0}.media-thumb{display:block;position:relative;aspect-ratio:16/9;overflow:hidden;border-radius:10px;background:#222}.media-thumb img{width:100%;height:100%;object-fit:cover;transition:transform .25s}.media-thumb:hover img{transform:scale(1.04)}.media-thumb b{position:absolute;right:7px;bottom:7px;padding:3px 6px;background:#000c;border-radius:4px;font-size:11px}.thumb-play{position:absolute;inset:0;display:grid;place-items:center;opacity:0;background:#0007;transition:opacity .2s}.media-thumb:hover .thumb-play{opacity:1}.media-meta{display:flex;gap:9px;padding-top:9px}.media-title{display:block;color:#fff;font-weight:600;line-height:1.4}.media-meta small{display:block;color:#999;font-size:11px;line-height:1.45;margin-top:4px}.media-card.compact{flex:0 0 150px}.media-card.compact .media-meta{display:none}.shorts-row .media-thumb{aspect-ratio:9/14;border-radius:11px}.shorts-row .media-thumb b,.shorts-row .thumb-play{display:none}.watch-layout{display:grid;grid-template-columns:minmax(0,1fr) 330px;gap:28px}.player{position:relative;aspect-ratio:16/9;background:#050505;border-radius:12px;overflow:hidden}.player img{width:100%;height:100%;object-fit:cover;filter:brightness(.7)}.player button{position:absolute;inset:50% auto auto 50%;transform:translate(-50%,-50%);width:64px;height:64px;border:0;border-radius:50%;background:#fff;color:#111;font-size:24px;cursor:pointer}.watch-title{margin:18px 0 8px;font:700 28px Outfit}.watch-subtitle{color:#999}.up-next h2{margin:0 0 16px;font:700 21px Outfit}.up-next .media-card{margin-bottom:16px}.up-next .channel-avatar{display:none}.up-next .media-title{font-size:13px}.up-next .media-meta small{font-size:10px}.empty-state{padding:40px;color:#999}@media(max-width:900px){.watch-layout{grid-template-columns:1fr}.up-next{display:grid;grid-template-columns:repeat(2,1fr);gap:12px}.up-next h2{grid-column:1/-1}}@media(max-width:760px){.media-card.compact{flex:0 0 130px}.watch-title{font-size:22px}.up-next{display:block}.up-next .media-card{margin-bottom:14px}.up-next .media-thumb{width:42%;display:inline-block;vertical-align:top}.up-next .media-meta{display:inline-flex;width:54%;vertical-align:top;padding-left:8px;padding-top:0}}
+9 -11
View File
@@ -1,22 +1,20 @@
// Author: fruit.com.cn
import { useEffect, useRef, useState } from 'react';
import { useParams } from 'react-router-dom';
import { videos } from '../data/catalog';
import { MediaCard } from '../components/MediaCard';
import { useNavigate, useParams } from 'react-router-dom';
import { useAppStore } from '../app/store';
import { appApi } from '../services/appApi';
import { normalizeDrama, resolvePlaybackUrl } from '../services/normalizers';
import { normalizeDrama, normalizePage, resolvePlaybackUrl } from '../services/normalizers';
import { useApi } from '../hooks/useApi';
import { VideoPlayer } from '../components/player/VideoPlayer';
function EpisodeSlide({ episode, poster, title, active, onActive }) {
const ref = useRef(null); const playback = useApi(() => appApi.episodePlay(episode.id), [episode.id]); const src = resolvePlaybackUrl(playback.data?.playUrl);
useEffect(() => { const node = ref.current; const observer = new IntersectionObserver(([entry]) => { if (entry.isIntersecting) onActive(episode.id); }, { threshold: 0.75 }); observer.observe(node); return () => observer.disconnect(); }, [episode.id, onActive]);
return <article id={`episode-${episode.id}`} ref={ref} className={`episode-slide ${active ? 'is-active' : ''}`}><div className="episode-slide-player">{src ? <VideoPlayer src={src} poster={poster} autoPlay={active} /> : <div className="episode-slide-placeholder"><img src={poster} alt={title} /><span>{playback.loading ? 'Loading signed stream…' : playback.error || (episode.locked ? 'Locked episode' : 'Playback unavailable')}</span></div>}</div><div className="episode-slide-caption"><span>EPISODE {episode.number}</span><h2>{episode.title || `Episode ${episode.number}`}</h2><p>{title}</p></div></article>;
function SwipeVideo({ video, active }) {
const ref = useRef(null); const playback = useApi(() => video.preview?.id ? appApi.episodePlay(video.preview.id) : Promise.resolve(null), [video.preview?.id]); const src = resolvePlaybackUrl(playback.data?.playUrl || video.preview?.playUrl); const image = video.image;
useEffect(() => { const node = ref.current; const observer = new IntersectionObserver(([entry]) => { if (entry.isIntersecting) node.classList.add('visible'); else node.classList.remove('visible'); }, { threshold: 0.7 }); observer.observe(node); return () => observer.disconnect(); }, []);
return <article ref={ref} className={`single-video-slide ${active ? 'active' : ''}`}><div className="single-video-stage">{src ? <VideoPlayer src={src} poster={image} autoPlay={active} /> : <div className="single-video-placeholder"><img src={image} alt={video.title} /><span>{playback.loading ? 'Loading video…' : playback.error || 'Preview unavailable'}</span></div>}</div><div className="single-video-info"><span>YMB SHORTS</span><h1>{video.title}</h1><p>{video.channel} · {video.views}</p></div></article>;
}
export function WatchPage() {
const { id } = useParams(); const { locale } = useAppStore(); const fallback = videos.find((item) => item.id === id) || videos[0];
const drama = useApi(() => appApi.drama(id).then((data) => normalizeDrama(data, locale.code)), [id, locale.code]); const video = drama.data || fallback; const [activeEpisodeId, setActiveEpisodeId] = useState(null); const image = video.image?.startsWith('/') || video.image?.startsWith('http') ? video.image : `/assets/${video.image}`; const episodes = video.episodes || [];
return <div className="youtube-watch-layout"><main className="watch-main"><div className="watch-channel-bar"><img src="/brand/ymb-logo-blue.png" alt="YMB" /><div><strong>{video.channel || 'YMB Originals'}</strong><small>{video.views}</small></div><button>Subscribe</button></div><h1 className="watch-title">{video.title}</h1><p className="watch-subtitle">{locale.swipeHint || 'Swipe up to continue watching'} · {episodes.length} episodes</p><div className="episode-feed">{drama.loading && <div className="api-note">{locale.loading}</div>}{episodes.map((episode) => <EpisodeSlide key={episode.id} episode={episode} poster={image} title={video.title} active={String(activeEpisodeId) === String(episode.id)} onActive={setActiveEpisodeId} />)}</div></main><aside className="watch-sidebar"><section className="episode-list-panel"><div className="episode-list-title"><h2>{locale.episodes || 'Episodes'}</h2><span>{episodes.length}</span></div>{episodes.map((episode) => <button key={episode.id} className={String(activeEpisodeId) === String(episode.id) ? 'active' : ''} onClick={() => document.getElementById(`episode-${episode.id}`)?.scrollIntoView({ behavior: 'smooth', block: 'start' })}><b>{episode.number}</b><span>{episode.title || `Episode ${episode.number}`}</span>{episode.locked && <small>🔒</small>}</button>)}</section><section className="watch-recommendations"><h2>{locale.picks}</h2>{videos.slice(0, 4).map((item) => <MediaCard key={item.id} video={item} />)}</section></aside></div>;
const { id } = useParams(); const navigate = useNavigate(); const { locale } = useAppStore(); const [activeId, setActiveId] = useState(id); const current = useApi(() => appApi.drama(id).then((data) => normalizeDrama(data, locale.code)), [id, locale.code]); const feed = useApi(() => appApi.dramas().then((payload) => normalizePage(payload).list.map((item) => normalizeDrama(item, locale.code))), [locale.code]); const items = feed.data || []; const ordered = [current.data, ...items.filter((item) => item.id !== id)].filter(Boolean);
useEffect(() => { const node = document.querySelector('.single-video-feed'); if (!node) return undefined; const observer = new IntersectionObserver((entries) => entries.forEach((entry) => { if (entry.isIntersecting) { const nextId = entry.target.dataset.id; setActiveId(nextId); if (nextId !== id) window.history.replaceState(null, '', `/watch/${nextId}`); } }), { root: node, threshold: 0.75 }); node.querySelectorAll('.single-video-slide').forEach((item) => observer.observe(item)); return () => observer.disconnect(); }, [ordered.length, id]);
return <div className="single-video-page"><header className="single-video-toolbar"><button onClick={() => navigate(-1)}>←</button><img src="/brand/ymb-logo-blue.png" alt="YMB" /><span>{locale.swipeHint || 'Swipe up for the next video'}</span></header><div className="single-video-feed">{current.loading && <div className="api-note">{locale.loading}</div>}{ordered.map((video) => <div key={video.id} data-id={video.id}><SwipeVideo video={video} active={String(activeId) === String(video.id)} /></div>)}</div></div>;
}