import { useState, useEffect } from "react"; import { Card, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Star } from "lucide-react"; const SPOTIFY_RECENTLY_PLAYED_URL = "https://api.spotify.com/v1/me/player/recently-played"; const SPOTIFY_CURRENTLY_PLAYING_URL = "https://api.spotify.com/v1/me/player/currently-playing"; const RECOMMENDED_API_URL = "https://api.spotify.com/v1/recommendations"; const ALBUM_DETAILS_URL = "https://api.spotify.com/v1/albums"; const fetchSpotifyData = async (token) => { const response = await fetch(SPOTIFY_RECENTLY_PLAYED_URL, { headers: { Authorization: `Bearer ${token}` }, }); const data = await response.json(); return Promise.all(data.items.map(async (item) => { const albumResponse = await fetch(`${ALBUM_DETAILS_URL}/${item.track.album.id}`, { headers: { Authorization: `Bearer ${token}` }, }); const albumData = await albumResponse.json(); return { id: item.track.id, title: item.track.name, artist: item.track.artists.map(a => a.name).join(", "), rating: Math.floor(Math.random() * 5) + 1, // Placeholder rating releaseDate: albumData.release_date, cover: albumData.images[0]?.url || "", globalRating: (Math.random() * 5).toFixed(1), // Placeholder global rating }; })); }; export default function AlbumTracker() { const [albums, setAlbums] = useState([]); const [search, setSearch] = useState(""); useEffect(() => { const token = localStorage.getItem("spotify_token"); // Assumes token is stored if (token) { fetchSpotifyData(token).then(setAlbums); } }, []); const filteredAlbums = albums.filter(album => album.title.toLowerCase().includes(search.toLowerCase()) || album.artist.toLowerCase().includes(search.toLowerCase()) ); return (

Music Tracker

setSearch(e.target.value)} className="mb-4" />

Recently Played

{filteredAlbums.map(album => ( {album.title}

{album.title}

{album.artist}

Release Date: {album.releaseDate}

Global Rating: {album.globalRating} ★

{[...Array(album.rating)].map((_, i) => ( ))}
))}
); }