feat(show-type): path-based /series filter and infinite trending galleries

Persist the show-type filter in the path via a /series prefix: movies
keep bare URLs, series use /series across random, popular, top,
favorites and watchlist. The path is the single source of truth - the
jotai atom is removed and the toggle navigates with router.replace so
the server prefetches the target variant. Legacy ?type=tv deep links
redirect to the prefixed URLs.

Trending and similar/recommendations queries are now paginated and feed
useInfiniteList like the main lists. Gallery wires fetchNextPage to a
new ScrollNavigation onEndReached callback (fires within two slides of
the end, once per approach), so all gallery tabs load more on scroll.
The show page prefetches the first similar page with
prefetchInfiniteQuery, and trending/similar/recommendations are added
to the analytics ListName.
This commit is contained in:
ner committed 2026-09-24 15:54:40 +03:00
1 parent 0824090c6d
commit f22f3c45b4
31 files changed
+372 -229

No files matched your search

+3 -21
View File
@@ -1,13 +1,10 @@
'use client';
import { FC, useRef } from 'react';
import { useAtom } from 'jotai';
import { FC } from 'react';
import Preview from '@/components/Preview';
import { showTypeAtom } from '@/components/ShowTypeToggle';
import Trending from '@/components/Trending';
import { Skeleton } from '@/components/ui/skeleton';
import { generatePage } from '@/data/queries/random';
import Carousel from './components/Carousel';
import useRandomMovie from './useRandomMovie';
@@ -18,20 +15,7 @@ interface Props {
}
const Container: FC<Props> = ({ page, type }) => {
const [showType] = useAtom(showTypeAtom);
const pagesRef = useRef<Record<Show['type'], number>>();
if (!pagesRef.current) {
pagesRef.current = {
movie: type === 'movie' ? page : generatePage('movie'),
tv: type === 'tv' ? page : generatePage('tv')
};
}
const { show, shows, onIndexChange, fetchNextPage, isLoading } = useRandomMovie({
page: pagesRef.current[showType],
type: showType
});
const { show, shows, onIndexChange, fetchNextPage } = useRandomMovie({ page, type });
return (
<div className='flex flex-1 flex-col'>
@@ -40,9 +24,7 @@ const Container: FC<Props> = ({ page, type }) => {
<Preview
show={show}
className='rounded-md bg-background'
poster={
<Carousel key={showType} shows={shows} onIndexChange={onIndexChange} onEndReached={fetchNextPage} />
}
poster={<Carousel key={type} shows={shows} onIndexChange={onIndexChange} onEndReached={fetchNextPage} />}
/>
) : (
<Skeleton className='card-aspect-ratio static-aspect-ratio mx-auto rounded-lg' />
+6 -5
View File
@@ -1,12 +1,12 @@
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
import { Metadata } from 'next';
import Link from 'next/link';
import { redirect } from 'next/navigation';
import JsonLd from '@/components/JsonLd';
import randomQuery, { generatePage } from '@/data/queries/random';
import { SITE_URL, TITLE } from '@/env';
import getQueryClient from '@/lib/queryClient';
import { parseShowType } from '@/lib/showType';
import Container from './container';
@@ -19,18 +19,19 @@ export const metadata: Metadata = {
};
const Random = async ({ searchParams }: { searchParams: SearchParams }) => {
if (searchParams.type === 'tv') redirect('/series');
const queryClient = getQueryClient();
const type = parseShowType(searchParams.type);
const page = generatePage(type);
const page = generatePage('movie');
await queryClient.prefetchInfiniteQuery(randomQuery({ page, type }));
await queryClient.prefetchInfiniteQuery(randomQuery({ page, type: 'movie' }));
return (
<HydrationBoundary state={dehydrate(queryClient)}>
<JsonLd data={{ '@context': 'https://schema.org', '@type': 'WebSite', name: TITLE, url: SITE_URL }} />
<h1 className='sr-only'>{TITLE} — Discover Your Next Favorite Movie</h1>
<Container page={page} type={type} />
<Container page={page} type='movie' />
<section className='sr-only'>
<h2>Discover your next favorite movie</h2>
<p>