2025-01-06 01:12:21 -05:00
|
|
|
"use client";
|
|
|
|
|
2025-01-06 01:19:32 -05:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import Image from 'next/image';
|
2025-01-06 01:12:21 -05:00
|
|
|
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
|
|
|
import { faLastfm } from '@fortawesome/free-brands-svg-icons'
|
|
|
|
import { faCompactDisc, faUser } from '@fortawesome/free-solid-svg-icons'
|
|
|
|
|
|
|
|
interface Track {
|
|
|
|
name: string;
|
|
|
|
artist: { '#text': string };
|
|
|
|
album: { '#text': string };
|
|
|
|
image: { '#text': string; size: string }[];
|
|
|
|
url: string;
|
|
|
|
'@attr'?: { nowplaying: string };
|
|
|
|
}
|
|
|
|
|
2025-01-23 22:38:44 -05:00
|
|
|
const LastPlayed: React.FC = () => {
|
2025-01-06 01:12:21 -05:00
|
|
|
const [track, setTrack] = useState<Track | null>(null);
|
|
|
|
const apiUrl = process.env.LASTFM_API_URL || 'https://lastfm-last-played.biancarosa.com.br/aidxn_/latest-song';
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
fetch(apiUrl)
|
|
|
|
.then(response => response.json())
|
|
|
|
.then(data => setTrack(data.track))
|
|
|
|
.catch(error => console.error('Error fetching now playing:', error));
|
|
|
|
}, [apiUrl]);
|
|
|
|
|
|
|
|
if (!track) {
|
|
|
|
return (
|
2025-01-06 16:43:48 -05:00
|
|
|
<div className="max-w-2xl mx-auto mt-4">
|
2025-01-23 22:38:44 -05:00
|
|
|
<h2 className="text-2xl font-bold mb-4 pt-10 text-gray-200">Last Played Song</h2>
|
2025-01-06 01:12:21 -05:00
|
|
|
<div className="flex justify-center items-center border border-gray-300 rounded-lg p-4 max-w-md mt-8">
|
|
|
|
<span className="spinner-border animate-spin inline-block w-8 h-8 border-4 rounded-full" role="status"></span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2025-01-06 16:43:48 -05:00
|
|
|
<div className="max-w-2xl mx-auto mt-4">
|
2025-01-23 22:38:44 -05:00
|
|
|
<h2 className="text-2xl font-bold mb-4 pt-10 text-gray-200">Last Played Song</h2>
|
2025-01-06 01:12:21 -05:00
|
|
|
<div className="now-playing flex items-center border border-gray-300 rounded-lg p-4 max-w-md mt-8 bg-white bg-opacity-10 backdrop-filter backdrop-blur-lg">
|
2025-01-06 01:19:32 -05:00
|
|
|
<Image
|
|
|
|
src={track.image.find(img => img.size === 'large')?.['#text'] || '/placeholder.png'}
|
2025-01-06 01:12:21 -05:00
|
|
|
alt={track.name}
|
2025-01-06 01:19:32 -05:00
|
|
|
width={96}
|
|
|
|
height={96}
|
|
|
|
className="rounded-lg mr-4"
|
2025-01-06 01:12:21 -05:00
|
|
|
/>
|
|
|
|
<div>
|
|
|
|
<p className="font-bold">{track.name}</p>
|
|
|
|
<p><FontAwesomeIcon icon={faCompactDisc} className="mr-1" /> {track.album['#text']}</p>
|
|
|
|
<i><FontAwesomeIcon icon={faUser} className="mr-1" /> {track.artist['#text']}</i>
|
|
|
|
<a href={track.url} target="_blank" rel="noopener noreferrer" className="text-blue-500 flex items-center">
|
|
|
|
<FontAwesomeIcon icon={faLastfm} className="mr-2" /> View on Last.fm
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2025-01-23 22:38:44 -05:00
|
|
|
export default LastPlayed;
|