2025-04-20 20:49:54 -05:00
|
|
|
import { asset, Avatar } from '@blitzkit/core';
|
2024-10-24 18:21:37 -05:00
|
|
|
import { Cross1Icon, DownloadIcon } from '@radix-ui/react-icons';
|
|
|
|
|
import {
|
|
|
|
|
Dialog,
|
|
|
|
|
Flex,
|
|
|
|
|
IconButton,
|
|
|
|
|
Link,
|
|
|
|
|
Skeleton,
|
|
|
|
|
Text,
|
|
|
|
|
} from '@radix-ui/themes';
|
2024-10-24 17:46:02 -05:00
|
|
|
import { useRef } from 'react';
|
|
|
|
|
import { useIntersection } from '../../hooks/useIntersection';
|
2025-04-20 20:49:54 -05:00
|
|
|
import { useLocale } from '../../hooks/useLocale';
|
2024-10-24 17:46:02 -05:00
|
|
|
import type { MaybeSkeletonComponentProps } from '../../types/maybeSkeletonComponentProps';
|
|
|
|
|
|
|
|
|
|
type GalleryCardProps = MaybeSkeletonComponentProps<{
|
2025-04-20 20:49:54 -05:00
|
|
|
avatar: Avatar;
|
2024-10-24 17:46:02 -05:00
|
|
|
}>;
|
|
|
|
|
|
|
|
|
|
export function GalleryCard(props: GalleryCardProps) {
|
2025-04-20 20:49:54 -05:00
|
|
|
const src = asset(
|
|
|
|
|
`gallery/avatars/${!props.skeleton && `${props.avatar.id}${props.avatar.extension}`}`,
|
|
|
|
|
);
|
2024-10-24 17:46:02 -05:00
|
|
|
const card = useRef<HTMLDivElement>(null);
|
2025-04-20 20:49:54 -05:00
|
|
|
const { unwrap } = useLocale();
|
2024-10-24 17:46:02 -05:00
|
|
|
|
|
|
|
|
useIntersection(() => props.skeleton && props.onIntersection?.(), card, {
|
|
|
|
|
disabled: !props.skeleton || props.onIntersection === undefined,
|
|
|
|
|
});
|
|
|
|
|
|
2024-10-24 18:21:37 -05:00
|
|
|
const content = (
|
|
|
|
|
<Flex
|
|
|
|
|
direction="column"
|
|
|
|
|
align="center"
|
|
|
|
|
width="6rem"
|
|
|
|
|
gap="1"
|
|
|
|
|
ref={card}
|
|
|
|
|
style={{ cursor: 'pointer' }}
|
|
|
|
|
>
|
2024-10-24 17:46:02 -05:00
|
|
|
{props.skeleton && (
|
|
|
|
|
<>
|
|
|
|
|
<Skeleton width="100%" height="4.57rem" />
|
|
|
|
|
<Skeleton width="100%" height="1em" />
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{!props.skeleton && (
|
|
|
|
|
<>
|
|
|
|
|
<img
|
|
|
|
|
style={{
|
|
|
|
|
width: '4rem',
|
|
|
|
|
height: '4.57rem',
|
|
|
|
|
// aspect ratio 7 / 8
|
|
|
|
|
objectFit: 'cover',
|
|
|
|
|
}}
|
2024-10-24 18:21:37 -05:00
|
|
|
src={src}
|
2025-04-20 20:49:54 -05:00
|
|
|
alt={unwrap(props.avatar.name)}
|
2024-10-24 17:46:02 -05:00
|
|
|
/>
|
|
|
|
|
|
2024-10-24 18:21:37 -05:00
|
|
|
<Text size="1" align="center" style={{ maxWidth: '100%' }}>
|
2025-04-20 20:49:54 -05:00
|
|
|
{unwrap(props.avatar.name)}
|
2024-10-24 17:46:02 -05:00
|
|
|
</Text>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Flex>
|
|
|
|
|
);
|
2024-10-24 18:21:37 -05:00
|
|
|
|
|
|
|
|
if (props.skeleton) return content;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Dialog.Root>
|
|
|
|
|
<Dialog.Trigger>{content}</Dialog.Trigger>
|
|
|
|
|
|
|
|
|
|
<Dialog.Content
|
|
|
|
|
onOpenAutoFocus={(event) => event.preventDefault()}
|
|
|
|
|
width="fit-content"
|
|
|
|
|
>
|
|
|
|
|
<Flex position="absolute" top="3" right="3" gap="3">
|
|
|
|
|
<Link download href={src}>
|
|
|
|
|
<IconButton variant="ghost">
|
|
|
|
|
<DownloadIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Link>
|
|
|
|
|
|
|
|
|
|
<Dialog.Close>
|
|
|
|
|
<IconButton variant="ghost">
|
|
|
|
|
<Cross1Icon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Dialog.Close>
|
|
|
|
|
</Flex>
|
|
|
|
|
|
2024-10-24 18:23:38 -05:00
|
|
|
<Flex px="4" justify="center" mt="3">
|
2025-04-20 20:49:54 -05:00
|
|
|
<img src={src} alt={unwrap(props.avatar.name)} />
|
2024-10-24 18:21:37 -05:00
|
|
|
</Flex>
|
|
|
|
|
|
|
|
|
|
<Flex justify="center" mt="4">
|
|
|
|
|
<Dialog.Title align="center" style={{ maxWidth: '10rem' }}>
|
2025-04-20 20:49:54 -05:00
|
|
|
{unwrap(props.avatar.name)}
|
2024-10-24 18:21:37 -05:00
|
|
|
</Dialog.Title>
|
|
|
|
|
</Flex>
|
|
|
|
|
</Dialog.Content>
|
|
|
|
|
</Dialog.Root>
|
|
|
|
|
);
|
2024-10-24 17:46:02 -05:00
|
|
|
}
|