import { useEffect, useState } from "react"; import axiosInstance from "../api/axiosInstance"; import type { BasicPlaylist, BasicSong, SidebarProps } from "../utils/types"; const Sidebar = ({ isOpen, onClose }: SidebarProps) => { const [recentlyListened, setRecentlyListened] = useState([]); const [playlists, setPlaylists] = useState([]); useEffect(() => { const fetchData = async () => { try { const data = await axiosInstance.get("/songs/recent"); setRecentlyListened(data.data); } catch (error) { console.error("Error fetching recently listened songs:", error); // todo: show toast } try { const data = await axiosInstance.get("/playlists/user"); setPlaylists(data.data); } catch (error) { console.error("Error fetching playlists:", error); // todo: show toast } }; fetchData(); }, []); return (
{/* Sidebar Header */}

Library

{/* Recently Listened */}

Recently Played

{recentlyListened.map((song) => (
{song.title}

{song.title}

{song.artist}

))}
{/* Playlists */}

Your Playlists

{playlists.map((playlist) => (

{playlist.name}

{playlist.songCount} songs

))}
); }; export default Sidebar;