diff --git a/src/pages/WatchPage.jsx b/src/pages/WatchPage.jsx
index cd216a1..ad95f72 100644
--- a/src/pages/WatchPage.jsx
+++ b/src/pages/WatchPage.jsx
@@ -13,10 +13,28 @@ function SwipeVideo({ video, active }) {
return {src ?
:
{playback.loading ? 'Loading video…' : playback.error || 'Preview unavailable'}}
YMB SHORTS{video.title}
{video.channel} · {video.views}
;
}
+function normalizeFeedItems(payload, localeCode) {
+ return uniqueDramas(normalizePage(payload).list.map((item) => normalizeDrama(item, localeCode)));
+}
+
+async function loadWatchFeed(localeCode) {
+ try {
+ const page = normalizeFeedItems(await appApi.dramas(), localeCode);
+ if (page.length) return page;
+ } catch (error) {
+ const fallback = await appApi.homeFeed();
+ const items = fallback?.sections?.flatMap((section) => section.dramas || []) || [];
+ return uniqueDramas(items.map((item) => normalizeDrama(item, localeCode)));
+ }
+ const fallback = await appApi.homeFeed();
+ const items = fallback?.sections?.flatMap((section) => section.dramas || []) || [];
+ return uniqueDramas(items.map((item) => normalizeDrama(item, localeCode)));
+}
+
export function WatchPage() {
- 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) => uniqueDramas(normalizePage(payload).list.map((item) => normalizeDrama(item, locale.code)))), [locale.code]); const items = feed.data || []; const ordered = uniqueDramas([current.data, ...items.filter((item) => item.id !== id)].filter(Boolean));
- const activeIndex = Math.max(0, ordered.findIndex((item) => String(item.id) === String(activeId))); const feedRef = useRef(null); const touchStart = useRef(0); const scrollToIndex = (index) => { const target = feedRef.current?.children[index]; target?.scrollIntoView({ behavior: 'smooth', block: 'start' }); }; const move = (delta) => scrollToIndex(Math.min(ordered.length - 1, Math.max(0, activeIndex + delta)));
+ 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(() => loadWatchFeed(locale.code), [locale.code]); const items = feed.data || []; const ordered = uniqueDramas([current.data, ...items.filter((item) => item.id !== String(id))].filter(Boolean));
+ const activeIndex = Math.max(0, ordered.findIndex((item) => String(item.id) === String(activeId))); const feedRef = useRef(null); const touchStart = useRef(0); const scrollToIndex = (index) => { const node = feedRef.current; if (!node) return; node.scrollTo({ top: index * node.clientHeight, behavior: 'smooth' }); }; const move = (delta) => { if (ordered.length < 2) return; scrollToIndex(Math.min(ordered.length - 1, Math.max(0, activeIndex + delta))); };
useEffect(() => { const node = feedRef.current; 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('[data-id]').forEach((item) => observer.observe(item)); const keydown = (event) => { if (event.key === 'ArrowDown' || event.key === 'PageDown') { event.preventDefault(); move(1); } if (event.key === 'ArrowUp' || event.key === 'PageUp') { event.preventDefault(); move(-1); } }; window.addEventListener('keydown', keydown); return () => { observer.disconnect(); window.removeEventListener('keydown', keydown); }; }, [ordered.length, id, activeIndex]);
const hasNext = feed.loading || activeIndex < ordered.length - 1; const hasPrevious = activeIndex > 0;
- return
{locale.swipeHint || 'Swipe up to discover the next story'}{current.loading &&
{locale.loading}
}
{ touchStart.current = event.touches[0].clientY; }} onTouchEnd={(event) => { const distance = touchStart.current - event.changedTouches[0].clientY; if (Math.abs(distance) > 45) move(distance > 0 ? 1 : -1); }} onWheel={(event) => { if (Math.abs(event.deltaY) > 20) move(event.deltaY > 0 ? 1 : -1); }}>{ordered.map((video) =>
)}
;
+ return
{locale.swipeHint || 'Swipe up to discover the next story'}{(current.loading || feed.loading) &&
{locale.loading}
}{feed.error &&
{feed.error}
}
{ touchStart.current = event.touches[0].clientY; }} onTouchEnd={(event) => { const distance = touchStart.current - event.changedTouches[0].clientY; if (Math.abs(distance) > 45) move(distance > 0 ? 1 : -1); }} onWheel={(event) => { if (Math.abs(event.deltaY) > 20) move(event.deltaY > 0 ? 1 : -1); }}>{ordered.map((video) =>
)}
;
}