import React, { useEffect, useState } from "react"; import getNowPlayingItem from "./fetch"; import PlayingAnimation from "./animation"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faSpotify } from "@fortawesome/free-brands-svg-icons"; import Image from "next/image"; const Card = () => { const [loading, setLoading] = useState(true); const [result, setResult] = useState({}); useEffect(() => { const fetchData = async () => { const results = await Promise.all([getNowPlayingItem()]); console.log(results); setResult(results[0]); setLoading(false); }; fetchData(); // Fetch data immediately on component mount const intervalId = setInterval(fetchData, 60 * 1000); // ! Fetch data every minute: temporary return () => clearInterval(intervalId); }, []); return (
{loading ? (
{/* Replace this with your own loading spinner */}
) : (
backgroundImage

{result.isPlaying ? "Now playing" : "Currently offline"}

{result.isPlaying && }
{result.isPlaying && (
{result.title}

{result.artist}

)}
)}
); }; export default Card;