Spaces:
Running
Running
File size: 1,460 Bytes
96ac62a fcd4478 f80b091 c69ef3e 66e93d1 96ac62a fcd4478 f80b091 fcd4478 abb7588 f80b091 96ac62a f80b091 96ac62a f80b091 abb7588 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
'use client';
import React from 'react';
import Image from 'next/image';
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from '@/components/ui/Tooltip';
import { MediaDetails } from '@/lib/fetch';
import { useAtom } from 'jotai';
import { selectedMediaIdAtom } from '@/state/media';
import { cn } from '@/lib/utils';
export interface MediaTileProps {
media: MediaDetails;
}
export default function MediaTile({ media }: MediaTileProps) {
const {
url,
thumbnails,
id,
name,
properties: { width, height },
} = media;
const [selectedMediaId, setSelectedMediaId] = useAtom(selectedMediaIdAtom);
const selected = selectedMediaId === id;
// const imageSrc = thumbnails.length ? thumbnails[thumbnails.length - 1] : url;
const imageSrc = url;
return (
<Tooltip>
<TooltipTrigger asChild>
<Image
src={imageSrc}
draggable={false}
alt="dataset images"
width={width}
height={height}
onClick={() => setSelectedMediaId(id)}
className={cn(
'w-full h-auto relative rounded-xl overflow-hidden shadow-md cursor-pointer transition-transform hover:scale-105 box-content',
selected && 'border-2 border-primary',
)}
/>
</TooltipTrigger>
<TooltipContent>
<p>{name}</p>
<p className="font-light text-xs">{`${width} x ${height}`}</p>
</TooltipContent>
</Tooltip>
);
}
|