fix: retina images

This commit is contained in:
ner committed 2024-10-21 21:03:32 +03:00
1 parent 0cface89bf
commit 8473a104ca
4 files changed
+29 -16

No files matched your search

+8 -2
View File
@@ -7,8 +7,14 @@ export const mapMovieSeriesToShow = (
overview, overview,
rating: vote_average, rating: vote_average,
votes: vote_count, votes: vote_count,
backdrop: backdrop_path ? `https://image.tmdb.org/t/p/w1280/${backdrop_path}` : '', backdrop: backdrop_path ? `https://image.tmdb.org/t/p/w1280${backdrop_path}` : '',
poster: poster_path ? `https://image.tmdb.org/t/p/w342/${poster_path}` : '', poster: poster_path
? {
'1x': `https://image.tmdb.org/t/p/w342${poster_path}`,
'1.5x': `https://image.tmdb.org/t/p/w500${poster_path}`,
'2x': `https://image.tmdb.org/t/p/w780${poster_path}`
}
: { '1x': '', '1.5x': '', '2x': '' },
release: 'release_date' in item ? item.release_date : item.first_air_date, release: 'release_date' in item ? item.release_date : item.first_air_date,
title: 'release_date' in item ? item.title : item.name title: 'release_date' in item ? item.title : item.name
}); });
+10 -6
View File
@@ -22,12 +22,16 @@ const Poster: FC<Props> = ({ show, onClick, className, rounded, containerProps,
className={cn('card-aspect-ratio relative bg-black overflow-hidden rounded-lg text-lg', className, rounded)} className={cn('card-aspect-ratio relative bg-black overflow-hidden rounded-lg text-lg', className, rounded)}
> >
<div className='flex size-full'> <div className='flex size-full'>
<img <picture>
className={cn('size-full rounded-lg object-cover', rounded)} <source srcSet={show.poster['1x']} media='(min-width: 601px)' />
loading={lazy ? 'lazy' : 'eager'} <source srcSet={show.poster['2x']} media='(max-width: 600px)' />
src={show.poster} <img
alt={show.title} className={cn('size-full rounded-lg object-cover', rounded)}
/> loading={lazy ? 'lazy' : 'eager'}
src={show.poster['1x']}
alt={show.title}
/>
</picture>
</div> </div>
<div <div
className={cn( className={cn(
+10 -7
View File
@@ -4,11 +4,12 @@ import { cn } from '@/lib/utils';
type Tab = { title: string }; type Tab = { title: string };
type CursorProps = { left: number; width: number; opacity: number }; type CursorProps = { left: number; width: number; opacity: number; onTransitionEnd: () => void };
const Cursor: FC<CursorProps> = ({ width, left, opacity }) => ( const Cursor: FC<CursorProps> = ({ width, left, opacity, onTransitionEnd }) => (
<li <li
className='pointer-events-none absolute z-0 h-full rounded-2xl bg-primary transition-all' className='pointer-events-none absolute z-0 h-full rounded-2xl bg-primary transition-all'
onTransitionEnd={onTransitionEnd}
style={{ width, left, opacity }} style={{ width, left, opacity }}
/> />
); );
@@ -23,12 +24,14 @@ export type NavProps<T extends Tab> = {
function Nav<T extends Tab>({ tabs, active, className, children, onChange }: NavProps<T>) { function Nav<T extends Tab>({ tabs, active, className, children, onChange }: NavProps<T>) {
const [cursor, setCursor] = useState({ left: 0, width: 0, opacity: 0 }); const [cursor, setCursor] = useState({ left: 0, width: 0, opacity: 0 });
const [transitionEnded, setTransitionEnded] = useState(false);
const currentRef = useRef<HTMLLIElement>(null); const currentRef = useRef<HTMLLIElement>(null);
useLayoutEffect(() => { useLayoutEffect(() => {
const link = currentRef.current; const link = currentRef.current;
setCursor({ width: link?.clientWidth || 0, left: link?.offsetLeft || 0, opacity: link ? 1 : 0 }); setCursor({ width: link?.clientWidth || 0, left: link?.offsetLeft || 0, opacity: link ? 1 : 0 });
setTransitionEnded(false);
}, [active?.title]); }, [active?.title]);
return ( return (
@@ -43,16 +46,16 @@ function Nav<T extends Tab>({ tabs, active, className, children, onChange }: Nav
key={title} key={title}
ref={isActive ? currentRef : undefined} ref={isActive ? currentRef : undefined}
onClick={() => onChange?.(tab)} onClick={() => onChange?.(tab)}
className={cn( className={cn('z-10 px-2.5 py-0.5 font-normal cursor-pointer', {
'mix-blend-difference text-white z-10 px-2.5 py-0.5 font-normal cursor-default', 'cursor-default text-secondary': isActive,
!isActive && 'cursor-pointer' 'mix-blend-difference text-white': !transitionEnded
)} })}
> >
{children?.(tab) || <div>{title}</div>} {children?.(tab) || <div>{title}</div>}
</li> </li>
); );
})} })}
<Cursor {...cursor} /> <Cursor {...cursor} onTransitionEnd={() => setTransitionEnded(true)} />
</ul> </ul>
); );
} }
Vendored
+1 -1
View File
@@ -60,7 +60,7 @@ interface Show {
title: string; title: string;
overview: string; overview: string;
backdrop: string; backdrop: string;
poster: string; poster: { '1x': string; '1.5x': string; '2x': string };
release: Date; release: Date;
rating: number; rating: number;
votes: number; votes: number;