|
| 1 | +import { useGetTrackMetadata } from '@/hooks/useGetTrackMetadata'; |
| 2 | +import { ReleaseMetadata } from '@/types'; |
| 3 | +import { PauseButton, PlayButton } from '@/ui/Icons'; |
| 4 | +import { UiSpinner } from '@/ui/UiSpinner'; |
| 5 | +import Image from 'next/image'; |
| 6 | +import { useRef, useState } from 'react'; |
| 7 | + |
| 8 | +interface ReleaseMetadataProps { |
| 9 | + releaseMetadata: ReleaseMetadata; |
| 10 | +} |
| 11 | + |
| 12 | +export default function ReleaseInfo({ releaseMetadata }: ReleaseMetadataProps) { |
| 13 | + return ( |
| 14 | + <div className="flex flex-col items-center justify-center w-full"> |
| 15 | + <div className="flex flex-col w-full justify-between p-6 font-bold italic gap-2"> |
| 16 | + <h3 className="text-2xl ">{releaseMetadata.name}</h3> |
| 17 | + <div className="flex flex-row gap-2"> |
| 18 | + <h3>Description: </h3> |
| 19 | + <h3 className="font-normal">{releaseMetadata.description} </h3> |
| 20 | + </div> |
| 21 | + <div className="flex flex-row gap-2"> |
| 22 | + <h3>Genre: </h3> |
| 23 | + <h3 className="font-normal"> |
| 24 | + {releaseMetadata.attributes[1].value}{' '} |
| 25 | + </h3> |
| 26 | + </div> |
| 27 | + </div> |
| 28 | + <div className="w-full italic font-bold"> |
| 29 | + <h3 className="text-lg pl-6">Track list</h3> |
| 30 | + {releaseMetadata.attributes[0].value.map((trackUri) => ( |
| 31 | + <Track key={trackUri} trackUri={trackUri} /> |
| 32 | + ))} |
| 33 | + </div> |
| 34 | + </div> |
| 35 | + ); |
| 36 | +} |
| 37 | + |
| 38 | +interface TrackProps { |
| 39 | + trackUri: string; |
| 40 | +} |
| 41 | + |
| 42 | +function Track({ trackUri }: TrackProps) { |
| 43 | + const { trackMetadata, isLoading, error } = useGetTrackMetadata(trackUri); |
| 44 | + |
| 45 | + const storageUrl = process.env.NEXT_PUBLIC_STORAGE_URL; |
| 46 | + |
| 47 | + const [isPlaying, setIsPlaying] = useState(false); |
| 48 | + const audioRef = useRef<HTMLAudioElement>(null); |
| 49 | + |
| 50 | + const togglePlayPause = () => { |
| 51 | + if (audioRef.current) { |
| 52 | + if (audioRef.current.paused) { |
| 53 | + audioRef.current.play(); |
| 54 | + setIsPlaying(true); |
| 55 | + } else { |
| 56 | + audioRef.current.pause(); |
| 57 | + setIsPlaying(false); |
| 58 | + } |
| 59 | + } |
| 60 | + }; |
| 61 | + |
| 62 | + if (isLoading) { |
| 63 | + return ( |
| 64 | + <div className="flex flex-row justify-center items-center gap-24 p-4 border-b-2"> |
| 65 | + <UiSpinner /> |
| 66 | + </div> |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + return ( |
| 71 | + <div> |
| 72 | + {error ? ( |
| 73 | + <h3>{error.message}</h3> |
| 74 | + ) : ( |
| 75 | + <div className="flex flex-row justify-between items-center mx-6 py-4 border-b-2 "> |
| 76 | + <div className="flex flex-row gap-2 items-center"> |
| 77 | + <div className="relative h-12 w-12 shadow-md"> |
| 78 | + <Image |
| 79 | + src={`${storageUrl}${trackMetadata.image}`} |
| 80 | + alt={trackMetadata.name} |
| 81 | + fill |
| 82 | + /> |
| 83 | + </div> |
| 84 | + <div className="flex flex-col items-start justify-start"> |
| 85 | + <h3>{trackMetadata.name}</h3> |
| 86 | + |
| 87 | + {/* biome-ignore lint/a11y/useMediaCaption: <explanation> */} |
| 88 | + <audio |
| 89 | + src={`${storageUrl}${trackMetadata.animation_url}`} |
| 90 | + ref={audioRef} |
| 91 | + /> |
| 92 | + {!isPlaying ? ( |
| 93 | + <PlayButton |
| 94 | + className="rounded-full h-5 w-5 bg-gray-400 flex flex-col items-center justify-center" |
| 95 | + className_Icon="h-3 w-3 text-white font-semibold" |
| 96 | + onClick={togglePlayPause} |
| 97 | + /> |
| 98 | + ) : ( |
| 99 | + <PauseButton |
| 100 | + className="rounded-full h-5 w-5 bg-gray-400 flex flex-col items-center justify-center" |
| 101 | + className_Icon="h-3 w-3 text-white font-semibold" |
| 102 | + onClick={togglePlayPause} |
| 103 | + /> |
| 104 | + )} |
| 105 | + </div> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + )} |
| 109 | + </div> |
| 110 | + ); |
| 111 | +} |
0 commit comments