analytics.showViewed({...}) reads better than track('show_viewed', {...}) and
drops the track_ alias Captions needed, where vidstack already exports track.
The methods are derived from the event catalogue with a mapped type plus a
Proxy rather than written out, so the catalogue stays the only place an event
is declared and the two cannot drift. Names stay snake_case on the wire.
Emitters are cached so a method is referentially stable and safe to pass to a
hook or use as an effect dependency.
Events with no payload are typed void and take no arguments.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
'use client';
|
|
|
|
import { FC, useState } from 'react';
|
|
|
|
import useSimilar from '@/components/Trending/useSimilar';
|
|
import Nav from '@/components/ui/nav';
|
|
import analytics from '@/lib/analytics';
|
|
|
|
import Gallery from './components/Gallery';
|
|
import { tabs as initialTabs } from './constants';
|
|
import useTrending from './useTrending';
|
|
|
|
interface Props {
|
|
showType: Show['type'];
|
|
showId: Show['id'];
|
|
preview?: boolean;
|
|
}
|
|
|
|
const Trending: FC<Props> = ({ showId, showType, preview }) => {
|
|
const tabs = preview ? initialTabs.filter(({ type }) => ['similar', 'recommendations'].includes(type)) : initialTabs;
|
|
|
|
const [active, setActive] = useState(tabs[0]);
|
|
|
|
const streaming = useTrending({ type: 'streaming', enabled: !preview });
|
|
const trending = useTrending({ type: 'trending', enabled: active.type === 'trending' });
|
|
const theater = useTrending({ type: 'theater', enabled: active.type === 'theater' });
|
|
const similar = useSimilar({
|
|
showId,
|
|
showType,
|
|
type: 'similar',
|
|
enabled: active.type === 'similar'
|
|
});
|
|
const recommendations = useSimilar({
|
|
showId,
|
|
showType,
|
|
type: 'recommendations',
|
|
enabled: active.type === 'recommendations'
|
|
});
|
|
|
|
const tab = { trending, streaming, theater, similar, recommendations }[active.type]!;
|
|
|
|
return (
|
|
(streaming.isFetched || similar.isFetched) && (
|
|
<div className='hidden md:block'>
|
|
<Nav
|
|
tabs={tabs}
|
|
active={active}
|
|
onChange={(active) => {
|
|
analytics.galleryTabChanged({ tab: active.type });
|
|
setActive(active);
|
|
}}
|
|
className='mb-3'
|
|
/>
|
|
{!tab.isPending && <Gallery key={active.type} shows={tab.data || []} />}
|
|
</div>
|
|
)
|
|
);
|
|
};
|
|
|
|
export default Trending;
|