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
}: Props<E>) {
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 endReachedFiredRef = useRef(false);
@@ -43,6 +46,10 @@ function ScrollNavigation<E extends HTMLElement>({
const [isArrowHovered, setIsArrowHovered] = useState(false);
useEffect(() => {
scrollElementRef.current = scrollElement;
}, [scrollElement]);
const [childWidth, setChildWidth] = useState(0);
const slideWidth = initialSlideWidth ?? childWidth + gap;
@@ -92,6 +99,65 @@ function ScrollNavigation<E extends HTMLElement>({
};
}, [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) => () => {
if (!scrollElement) return;
@@ -102,7 +168,7 @@ function ScrollNavigation<E extends HTMLElement>({
};
return (
<div className={cn('relative group', className)}>
<div ref={containerRef} className={cn('relative group', className)}>
{children({ setScrollElement, isArrowHovered })}
{[
{
@@ -127,8 +193,14 @@ function ScrollNavigation<E extends HTMLElement>({
<div
key={className}
onClick={handleScroll}
onMouseEnter={() => setIsArrowHovered(true)}
onMouseLeave={() => setIsArrowHovered(false)}
onMouseEnter={() => {
isArrowHoveredRef.current = true;
setIsArrowHovered(true);
}}
onMouseLeave={() => {
isArrowHoveredRef.current = false;
setIsArrowHovered(false);
}}
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',
{
+8 -2
View File
@@ -13,7 +13,8 @@ export const tabs = [
},
{
title: 'Similar',
type: 'similar'
type: 'similar',
divider: true
},
{
title: 'Recommendations',
@@ -34,9 +35,14 @@ export const seriesTabs = [
title: 'HBO',
type: 'hbo'
},
{
title: 'Amazon',
type: 'amazon'
},
{
title: 'Similar',
type: 'similar'
type: 'similar',
divider: true
},
{
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 netflix = useTrending({ type: 'netflix', enabled: isSeries && active.type === 'netflix' });
const hbo = useTrending({ type: 'hbo', enabled: isSeries && active.type === 'hbo' });
const amazon = useTrending({ type: 'amazon', enabled: isSeries && active.type === 'amazon' });
const similar = useSimilar({
showId,
showType,
@@ -52,7 +53,17 @@ const Trending: FC<Props> = ({ showId, showType, preview }) => {
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 (
(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';
type Tab = { title: string };
type Tab = { title: string; divider?: boolean };
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 (
<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 isActive = title === active?.title;
return (
<li
key={title}
ref={isActive ? currentRef : undefined}
onClick={() => onChange?.(tab)}
className={cn('z-10 px-2.5 py-0.5 font-normal text-[15px] leading-[20px] cursor-pointer', {
'cursor-default text-secondary': isActive,
'mix-blend-difference text-white': active && !transitionEnded
})}
>
{children?.(tab) || <div>{title}</div>}
</li>
<Fragment key={title}>
{index > 0 && tab.divider && <span aria-hidden className='h-4 w-px shrink-0 bg-muted-foreground/40' />}
<li
ref={isActive ? currentRef : undefined}
onClick={() => onChange?.(tab)}
className={cn('z-10 px-2.5 py-0.5 font-normal text-[15px] leading-[20px] cursor-pointer', {
'cursor-default text-secondary': isActive,
'mix-blend-difference text-white': active && !transitionEnded
})}
>
{children?.(tab) || <div>{title}</div>}
</li>
</Fragment>
);
})}
<Cursor {...cursor} onTransitionEnd={() => setTransitionEnded(true)} />