-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMediaItem.tsx
75 lines (67 loc) · 2.03 KB
/
MediaItem.tsx
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"use client";
import useLoadImage from "@/hooks/useLoadImage";
import usePlayer from "@/hooks/usePlayer";
import { Song } from "@/types";
import Image from "next/image";
import React from "react";
interface MediaItemProps {
data: Song;
onClick?: (id: string) => void;
}
const MediaItem: React.FC<MediaItemProps> = ({
data,
onClick
}) => {
const player = usePlayer(); //It gets the player from the server and returns it to the client using the usePlayer hook
const imageUrl = useLoadImage(data); //It gets a url from the server and returns it to the client using the useLoadImage hook
const handleClick = () => {
if (onClick) {
return onClick(data.id);
}
return player.setId(data.id);
}
return (
<div
onClick={handleClick}
className="
flex
items-center
gap-x-3
cursor-pointer
hover:bg-neutral-800/50
w-full
rounded-md
p-2
transition
hover:scale-105
"
>
<div className=" relative rounded-md min-h-[48px] min-w-[48px] overflow-hidden">
<Image
alt="Song Cover"
src={imageUrl || "/Images/liked.png"}
fill
className="object-cover"
/>
</div>
<div className="
flex
flex-col
items-start
justify-center
flex-grow
gap-y-1
overflow-hidden
"
>
<p className=" text-white truncate">
{data.title}
</p>
<p className=" text-neutral-400 truncate">
{data.author}
</p>
</div>
</div>
);
}
export default MediaItem;