Bare ids are unreadable in the dashboard, so every event that points at a show or a person now carries its title or name. Ids stay for disambiguation, since titles collide across remakes. - ShowRef gains showTitle, so show_viewed, library_toggled, torrents_searched, torrent_selected, playback_started and playback_failed all report it - person_viewed sends personName - random_shuffled sends the title of the movie scrolled to - torrent_selected sends the torrent title next to the show title - subtitles_selected sends the track label, such as English, rather than the internal track value Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
113 lines
3.6 KiB
TypeScript
113 lines
3.6 KiB
TypeScript
'use client';
|
|
|
|
import { FC, ReactNode } from 'react';
|
|
import { create, InstanceProps } from 'react-modal-promise';
|
|
|
|
import Poster from '@/components/Poster';
|
|
import Credits from '@/components/Preview/components/Credits';
|
|
import useDetails from '@/components/Preview/useDetails';
|
|
import { Modal } from '@/components/ui/dialog';
|
|
import analytics from '@/lib/analytics';
|
|
import useTrackOnce from '@/lib/analytics/useTrackOnce';
|
|
import { cn } from '@/lib/utils';
|
|
|
|
import Actions from './components/Actions';
|
|
import Airing from './components/Airing';
|
|
import YearHint from './components/YearHint';
|
|
|
|
interface Props {
|
|
show?: Show & Partial<Details>;
|
|
showType?: Show['type'];
|
|
showId?: Show['id'];
|
|
className?: string;
|
|
posterClassName?: string;
|
|
onClose?: () => void;
|
|
poster?: ReactNode;
|
|
externalLink?: boolean;
|
|
heading?: boolean;
|
|
}
|
|
|
|
const Preview: FC<Props> = ({
|
|
show: baseShow,
|
|
showType,
|
|
showId,
|
|
className,
|
|
posterClassName,
|
|
onClose,
|
|
poster,
|
|
externalLink = true,
|
|
heading = false
|
|
}) => {
|
|
const { data: detailedShow } = useDetails({ showId: showId || baseShow?.id, showType: showType || baseShow?.type });
|
|
|
|
const show = (detailedShow || baseShow) as (Show & Partial<Details>) | undefined;
|
|
|
|
const isModal = Boolean(onClose);
|
|
|
|
useTrackOnce(analytics.showViewed, show?.id, () => ({
|
|
showId: show!.id,
|
|
showType: show!.type,
|
|
showTitle: show!.title,
|
|
surface: isModal ? ('modal' as const) : ('page' as const)
|
|
}));
|
|
|
|
if (!show) return null;
|
|
|
|
const Title = heading ? 'h1' : 'span';
|
|
|
|
return (
|
|
<div
|
|
className={cn(
|
|
'flex flex-col md:flex-row gap-2 rounded-xl overflow-hidden',
|
|
{ 'gap-0 md:p-0 p-2': isModal },
|
|
className
|
|
)}
|
|
>
|
|
{poster || <Poster className={cn('mx-auto md:rounded-none md:rounded-l-xl', posterClassName)} show={show} />}
|
|
<div className={cn('flex grow flex-col bg-background', { 'p-0 pt-2 md:p-2': isModal })}>
|
|
<Title className='order-3 mb-4 text-3xl md:order-1 md:line-clamp-2'>{show.title}</Title>
|
|
|
|
<div className='order-3 mb-4 flex w-full flex-wrap items-center gap-5 whitespace-nowrap text-sm md:order-2'>
|
|
{Boolean(show.availability) ? <YearHint show={show} /> : <span>{new Date(show.release).getFullYear()}</span>}
|
|
{Boolean(show.airing) && <Airing airing={show.airing!} className='animate-fade-aside-slide-in opacity-0' />}
|
|
{Boolean(show.runtime) && (
|
|
<span className='animate-fade-aside-slide-in opacity-0'>{show.runtime} minutes</span>
|
|
)}
|
|
{Boolean(show.genres) && (
|
|
<span className='animate-fade-aside-slide-in opacity-0'>
|
|
{show.genres
|
|
?.slice(0, 3)
|
|
.map(({ name }) => name)
|
|
.join(' | ')}
|
|
</span>
|
|
)}
|
|
</div>
|
|
|
|
<Actions externalLink={externalLink} className='order-1 mb-4 md:order-2' show={show} />
|
|
|
|
<p key={show.id} className='order-4 md:order-4 md:line-clamp-3' title={show.overview}>
|
|
{show.overview}
|
|
</p>
|
|
<div className='order-5 mt-5 grid grid-cols-1 rounded-lg md:order-5 md:mt-auto'>
|
|
<Credits showType={show.type} showId={show.id} onClick={onClose} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export const showPreviewModal = create(({ onResolve, onClose, show }: Props & InstanceProps<void>) => (
|
|
<Modal className='block bg-background p-0 md:bg-black' onClose={onResolve}>
|
|
<Preview
|
|
show={show}
|
|
onClose={() => {
|
|
onClose?.();
|
|
onResolve();
|
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
}}
|
|
/>
|
|
</Modal>
|
|
));
|
|
|
|
export default Preview;
|