feat(trending): amazon tab, tab group divider and arrow-hover wheel scroll

- Amazon tab for the series trending row (TMDB provider 9, Amazon
  Prime Video US), lazy-loaded like Netflix/HBO
- Nav renders a divider before tabs flagged with 'divider', separating
  the trending group from Similar/Recommendations (no leading divider
  on the show-page preview)
- Vertical wheel now steps the row card-by-card only while hovering the
  prev/next arrow zones: deltas accumulate and a smooth scroll lands on
  the next/previous snap point, so mandatory snap never pulls back.
  Everywhere else the wheel scrolls the page as before
This commit is contained in:
ner committed 2026-09-24 16:25:35 +03:00
1 parent f22f3c45b4
commit 09aceccec9
5 files changed
+114 -22

No files matched your search

+75 -3
View File
@@ -33,6 +33,9 @@ function ScrollNavigation<E extends HTMLElement>({
children children
}: Props<E>) { }: Props<E>) {
const [scrollElement, setScrollElement] = useState<E | null>(null); const [scrollElement, setScrollElement] = useState<E | null>(null);
const scrollElementRef = useRef<E | null>(null);
const containerRef = useRef<HTMLDivElement>(null);
const isArrowHoveredRef = useRef(false);
const onEndReachedRef = useRef(onEndReached); const onEndReachedRef = useRef(onEndReached);
const endReachedFiredRef = useRef(false); const endReachedFiredRef = useRef(false);
@@ -43,6 +46,10 @@ function ScrollNavigation<E extends HTMLElement>({
const [isArrowHovered, setIsArrowHovered] = useState(false); const [isArrowHovered, setIsArrowHovered] = useState(false);
useEffect(() => {
scrollElementRef.current = scrollElement;
}, [scrollElement]);
const [childWidth, setChildWidth] = useState(0); const [childWidth, setChildWidth] = useState(0);
const slideWidth = initialSlideWidth ?? childWidth + gap; const slideWidth = initialSlideWidth ?? childWidth + gap;
@@ -92,6 +99,65 @@ function ScrollNavigation<E extends HTMLElement>({
}; };
}, [scrollElement, initialSlideWidth]); }, [scrollElement, initialSlideWidth]);
useEffect(() => {
const container = containerRef.current;
if (!container) return;
let accumulated = 0;
const handleWheel = (event: WheelEvent) => {
if (!isArrowHoveredRef.current) return;
const element = scrollElementRef.current;
if (!element) return;
const delta = event.deltaY;
if (!delta) return;
const atStart = element.scrollLeft <= 0;
const atEnd = element.scrollLeft + element.clientWidth >= element.scrollWidth - 1;
if ((delta > 0 && atEnd) || (delta < 0 && atStart)) {
accumulated = 0;
return;
}
event.preventDefault();
if (accumulated * delta < 0) accumulated = 0;
accumulated += delta;
const first = element.querySelector('.snap-start') as HTMLElement | null;
if (!first) return;
const second = first.nextElementSibling as HTMLElement | null;
const step = second ? second.offsetLeft - first.offsetLeft : first.clientWidth + gap;
if (!step || Math.abs(accumulated) < step / 2) return;
const index = Math.round(element.scrollLeft / step);
const direction = accumulated > 0 ? 1 : -1;
accumulated = 0;
element.scrollTo({
left: (index + direction) * step,
behavior: 'smooth'
});
};
container.addEventListener('wheel', handleWheel, { passive: false });
return () => {
container.removeEventListener('wheel', handleWheel);
};
}, [gap]);
const handleScrollNext = (direction: 1 | -1) => () => { const handleScrollNext = (direction: 1 | -1) => () => {
if (!scrollElement) return; if (!scrollElement) return;
@@ -102,7 +168,7 @@ function ScrollNavigation<E extends HTMLElement>({
}; };
return ( return (
<div className={cn('relative group', className)}> <div ref={containerRef} className={cn('relative group', className)}>
{children({ setScrollElement, isArrowHovered })} {children({ setScrollElement, isArrowHovered })}
{[ {[
{ {
@@ -127,8 +193,14 @@ function ScrollNavigation<E extends HTMLElement>({
<div <div
key={className} key={className}
onClick={handleScroll} onClick={handleScroll}
onMouseEnter={() => setIsArrowHovered(true)} onMouseEnter={() => {
onMouseLeave={() => setIsArrowHovered(false)} isArrowHoveredRef.current = true;
setIsArrowHovered(true);
}}
onMouseLeave={() => {
isArrowHoveredRef.current = false;
setIsArrowHovered(false);
}}
className={cn( className={cn(
'opacity-0 hover-none:hidden hover-none:pointer-events-none transition-opacity absolute top-1/2 transform -translate-y-1/2 bg-gradient-to-r h-full w-14 flex items-center cursor-pointer', 'opacity-0 hover-none:hidden hover-none:pointer-events-none transition-opacity absolute top-1/2 transform -translate-y-1/2 bg-gradient-to-r h-full w-14 flex items-center cursor-pointer',
{ {
+8 -2
View File
@@ -13,7 +13,8 @@ export const tabs = [
}, },
{ {
title: 'Similar', title: 'Similar',
type: 'similar' type: 'similar',
divider: true
}, },
{ {
title: 'Recommendations', title: 'Recommendations',
@@ -34,9 +35,14 @@ export const seriesTabs = [
title: 'HBO', title: 'HBO',
type: 'hbo' type: 'hbo'
}, },
{
title: 'Amazon',
type: 'amazon'
},
{ {
title: 'Similar', title: 'Similar',
type: 'similar' type: 'similar',
divider: true
}, },
{ {
title: 'Recommendations', title: 'Recommendations',
+12 -1
View File
@@ -39,6 +39,7 @@ const Trending: FC<Props> = ({ showId, showType, preview }) => {
const apple = useTrending({ type: 'apple', enabled: isSeries && !preview }); const apple = useTrending({ type: 'apple', enabled: isSeries && !preview });
const netflix = useTrending({ type: 'netflix', enabled: isSeries && active.type === 'netflix' }); const netflix = useTrending({ type: 'netflix', enabled: isSeries && active.type === 'netflix' });
const hbo = useTrending({ type: 'hbo', enabled: isSeries && active.type === 'hbo' }); const hbo = useTrending({ type: 'hbo', enabled: isSeries && active.type === 'hbo' });
const amazon = useTrending({ type: 'amazon', enabled: isSeries && active.type === 'amazon' });
const similar = useSimilar({ const similar = useSimilar({
showId, showId,
showType, showType,
@@ -52,7 +53,17 @@ const Trending: FC<Props> = ({ showId, showType, preview }) => {
enabled: active.type === 'recommendations' enabled: active.type === 'recommendations'
}); });
const tab = { streaming, trending, theater, apple, netflix, hbo, similar, recommendations }[active.type]!; const tab = {
streaming,
trending,
theater,
apple,
netflix,
hbo,
amazon,
similar,
recommendations
}[active.type]!;
return ( return (
(streaming.isFetched || apple.isFetched || similar.isFetched) && ( (streaming.isFetched || apple.isFetched || similar.isFetched) && (
+16 -14
View File
@@ -1,8 +1,8 @@
import { FC, ReactNode, useLayoutEffect, useRef, useState } from 'react'; import { FC, Fragment, ReactNode, useLayoutEffect, useRef, useState } from 'react';
import { cn } from '@/lib/utils'; import { cn } from '@/lib/utils';
type Tab = { title: string }; type Tab = { title: string; divider?: boolean };
type CursorProps = { left: number; width: number; opacity: number; onTransitionEnd: () => void }; type CursorProps = { left: number; width: number; opacity: number; onTransitionEnd: () => void };
@@ -36,23 +36,25 @@ function Nav<T extends Tab>({ tabs, active, className, children, onChange }: Nav
return ( return (
<ul className={cn('relative hidden md:flex items-center whitespace-nowrap text-[13px] gap-3', className)}> <ul className={cn('relative hidden md:flex items-center whitespace-nowrap text-[13px] gap-3', className)}>
{tabs.map((tab) => { {tabs.map((tab, index) => {
const { title } = tab; const { title } = tab;
const isActive = title === active?.title; const isActive = title === active?.title;
return ( return (
<li <Fragment key={title}>
key={title} {index > 0 && tab.divider && <span aria-hidden className='h-4 w-px shrink-0 bg-muted-foreground/40' />}
ref={isActive ? currentRef : undefined} <li
onClick={() => onChange?.(tab)} ref={isActive ? currentRef : undefined}
className={cn('z-10 px-2.5 py-0.5 font-normal text-[15px] leading-[20px] cursor-pointer', { onClick={() => onChange?.(tab)}
'cursor-default text-secondary': isActive, className={cn('z-10 px-2.5 py-0.5 font-normal text-[15px] leading-[20px] cursor-pointer', {
'mix-blend-difference text-white': active && !transitionEnded 'cursor-default text-secondary': isActive,
})} 'mix-blend-difference text-white': active && !transitionEnded
> })}
{children?.(tab) || <div>{title}</div>} >
</li> {children?.(tab) || <div>{title}</div>}
</li>
</Fragment>
); );
})} })}
<Cursor {...cursor} onTransitionEnd={() => setTransitionEnded(true)} /> <Cursor {...cursor} onTransitionEnd={() => setTransitionEnded(true)} />
+3 -2
View File
@@ -2,14 +2,15 @@ import movieAdvisor from '../clients/movieAdvisor';
import mapMoviesSeriesResponseToShows from '../dto/Show'; import mapMoviesSeriesResponseToShows from '../dto/Show';
export type TrendingQueryProps = { export type TrendingQueryProps = {
type: 'trending' | 'streaming' | 'theater' | 'apple' | 'netflix' | 'hbo'; type: 'trending' | 'streaming' | 'theater' | 'apple' | 'netflix' | 'hbo' | 'amazon';
enabled?: boolean; enabled?: boolean;
}; };
const TV_WATCH_PROVIDERS: Partial<Record<TrendingQueryProps['type'], number>> = { const TV_WATCH_PROVIDERS: Partial<Record<TrendingQueryProps['type'], number>> = {
apple: 350, apple: 350,
netflix: 8, netflix: 8,
hbo: 1899 hbo: 1899,
amazon: 9
}; };
const trendingQuery = ({ type, enabled }: TrendingQueryProps) => ({ const trendingQuery = ({ type, enabled }: TrendingQueryProps) => ({