61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { Link } from 'react-router-dom';
|
|
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
|
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area';
|
|
import { getProfileUrl } from '@/lib/media-utils';
|
|
import type { Credit } from '@/types';
|
|
|
|
interface CastListProps {
|
|
credits: Credit[];
|
|
}
|
|
|
|
export function CastList({ credits }: CastListProps) {
|
|
const castCredits = credits.filter((c) => c.cast_type === 'cast');
|
|
|
|
if (castCredits.length === 0) return null;
|
|
|
|
return (
|
|
<div className="space-y-3">
|
|
<h3 className="text-lg font-semibold">Cast</h3>
|
|
<ScrollArea className="w-full">
|
|
<div className="flex gap-4 pb-4">
|
|
{castCredits.map((credit) => (
|
|
<CastCard key={credit.id} credit={credit} />
|
|
))}
|
|
</div>
|
|
<ScrollBar orientation="horizontal" />
|
|
</ScrollArea>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function CastCard({ credit }: { credit: Credit }) {
|
|
const profileUrl = credit.people?.profile_path
|
|
? getProfileUrl(credit.people.profile_path)
|
|
: undefined;
|
|
|
|
return (
|
|
<Link
|
|
to={`/people/${credit.people_id}`}
|
|
className="flex w-28 shrink-0 flex-col items-center gap-2 text-center"
|
|
>
|
|
<Avatar className="h-20 w-20">
|
|
<AvatarImage src={profileUrl} alt={credit.people?.name} />
|
|
<AvatarFallback className="text-xs">
|
|
{credit.people?.name
|
|
?.split(' ')
|
|
.map((n) => n[0])
|
|
.join('')}
|
|
</AvatarFallback>
|
|
</Avatar>
|
|
<div>
|
|
<p className="text-xs font-medium leading-tight line-clamp-2">
|
|
{credit.people?.name}
|
|
</p>
|
|
<p className="text-[10px] text-muted-foreground leading-tight line-clamp-1">
|
|
{credit.character}
|
|
</p>
|
|
</div>
|
|
</Link>
|
|
);
|
|
}
|