Changeset b071fb4 for frontend/src/components/Sidebar.tsx
- Timestamp:
- 02/06/26 20:05:09 (5 months ago)
- Branches:
- main
- Children:
- 591919d
- Parents:
- 2ce7c1e
- File:
-
- 1 edited
-
frontend/src/components/Sidebar.tsx (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/components/Sidebar.tsx
r2ce7c1e rb071fb4 1 interface SidebarProps { 2 isOpen: boolean; 3 onClose: () => void; 4 } 1 import { useEffect, useState } from "react"; 2 import axiosInstance from "../api/axiosInstance"; 3 import type { BasicPlaylist, BasicSong, SidebarProps } from "../utils/types"; 5 4 6 5 const Sidebar = ({ isOpen, onClose }: SidebarProps) => { 7 // mock data for recently listened songs 8 const recentlyListened = [ 9 { id: 1, title: "Song One", artist: "Artist A", cover: "/favicon.png" }, 10 { id: 2, title: "Song Two", artist: "Artist B", cover: "/favicon.png" }, 11 { id: 3, title: "Song Three", artist: "Artist C", cover: "/favicon.png" }, 12 { id: 4, title: "Song Four", artist: "Artist D", cover: "/favicon.png" }, 13 { id: 5, title: "Song Five", artist: "Artist E", cover: "/favicon.png" }, 14 ]; 6 const [recentlyListened, setRecentlyListened] = useState<BasicSong[]>([]); 7 const [playlists, setPlaylists] = useState<BasicPlaylist[]>([]); 15 8 16 // mock data for my playlists 17 const playlists = [ 18 { id: 1, name: "My Favorites", songCount: 25 }, 19 { id: 2, name: "Workout Mix", songCount: 18 }, 20 { id: 3, name: "Chill Vibes", songCount: 32 }, 21 { id: 4, name: "Party Hits", songCount: 45 }, 22 ]; 23 9 useEffect(() => { 10 const fetchData = async () => { 11 try { 12 const data = await axiosInstance.get<BasicSong[]>("/songs/recent"); 13 setRecentlyListened(data.data); 14 } catch (error) { 15 console.error("Error fetching recently listened songs:", error); 16 // todo: show toast 17 } 18 try { 19 const data = 20 await axiosInstance.get<BasicPlaylist[]>("/playlists/user"); 21 setPlaylists(data.data); 22 } catch (error) { 23 console.error("Error fetching playlists:", error); 24 // todo: show toast 25 } 26 }; 27 fetchData(); 28 }, []); 24 29 return ( 25 30 <div … … 65 70 > 66 71 <img 67 src={song.cover }72 src={song.cover || "/favicon.png"} 68 73 alt={song.title} 69 74 className="w-10 h-10 rounded object-cover"
Note:
See TracChangeset
for help on using the changeset viewer.
