refactoring: poster

This commit is contained in:
ner committed 2024-10-30 21:14:15 +02:00
1 parent 053283564c
commit 32e7885791
6 files changed
+30 -54

No files matched your search

+22 -36
View File
@@ -1,50 +1,36 @@
import { DetailedHTMLProps, FC, HTMLAttributes } from 'react';
import { FC } from 'react';
import { cn } from '@/lib/utils';
import Handlers from './components/Handlers';
interface Props {
show?: Show;
show: Show;
onClick?: () => void;
className?: string;
rounded?: string;
lazy?: boolean;
containerProps?: DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
}
const Poster: FC<Props> = ({ show, onClick, className, rounded, containerProps, lazy = true }) => {
if (!show) return null;
return (
<div
{...(containerProps || {})}
className={cn('card-aspect-ratio relative bg-black overflow-hidden rounded-lg text-lg', className, rounded)}
>
<div className='flex size-full'>
<picture>
<source srcSet={show.poster['1x']} media='(max-resolution: 191dpi)' />
<source srcSet={show.poster['1x']} media='(max-device-pixel-ratio: 1.99)' />
<source srcSet={show.poster['1.5x']} media='(min-resolution: 192dpi)' />
<source srcSet={show.poster['1.5x']} media='(min-device-pixel-ratio: 2)' />
<img
className={cn('size-full rounded-lg object-cover', rounded)}
loading={lazy ? 'lazy' : 'eager'}
src={show.poster['1x']}
alt={show.title}
/>
</picture>
</div>
<div
className={cn(
'absolute left-0 top-0 flex size-full flex-col justify-between rounded-md bg-vignette p-2 text-white',
rounded
)}
>
<Handlers show={show} onClick={onClick} />
</div>
const Poster: FC<Props> = ({ show, onClick, className, lazy = true }) => (
<div className={cn('card-aspect-ratio relative bg-black overflow-hidden rounded-lg text-lg', className)}>
<div className='flex size-full'>
<picture>
<source srcSet={show.poster['1x']} media='(max-resolution: 191dpi)' />
<source srcSet={show.poster['1x']} media='(max-device-pixel-ratio: 1.99)' />
<source srcSet={show.poster['1.5x']} media='(min-resolution: 192dpi)' />
<source srcSet={show.poster['1.5x']} media='(min-device-pixel-ratio: 2)' />
<img
className='size-full rounded-lg object-cover md:rounded-none md:rounded-l-lg'
loading={lazy ? 'lazy' : 'eager'}
src={show.poster['1x']}
alt={show.title}
/>
</picture>
</div>
);
};
<div className='absolute left-0 top-0 flex size-full flex-col justify-between rounded-md bg-vignette p-2 text-white md:rounded-none md:rounded-l-lg'>
<Handlers show={show} onClick={onClick} />
</div>
</div>
);
export default Poster;
+1 -1
View File
@@ -35,7 +35,7 @@ const Preview: FC<Props> = ({ show: baseShow, className, onClose, poster }) => {
className
)}
>
{poster || <Poster className='mx-auto' rounded='md:rounded-none md:rounded-l-xl' show={show} />}
{poster || <Poster className='mx-auto md:rounded-none md:rounded-l-xl' show={show} />}
<div className={cn('flex grow flex-col bg-background', { 'p-0 pt-1 md:p-2': isModal })}>
<span className='order-3 mb-4 text-3xl md:order-1 md:line-clamp-2'>{show.title}</span>