Ignore:
Timestamp:
02/06/26 20:05:09 (5 months ago)
Author:
Filip Gavrilovski <filipgavrilovski28@…>
Branches:
main
Children:
591919d
Parents:
2ce7c1e
Message:

replace mock data in sidebar with real user data

File:
1 edited

Legend:

Unmodified
Added
Removed
  • frontend/src/components/Sidebar.tsx

    r2ce7c1e rb071fb4  
    1 interface SidebarProps {
    2         isOpen: boolean;
    3         onClose: () => void;
    4 }
     1import { useEffect, useState } from "react";
     2import axiosInstance from "../api/axiosInstance";
     3import type { BasicPlaylist, BasicSong, SidebarProps } from "../utils/types";
    54
    65const 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[]>([]);
    158
    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        }, []);
    2429        return (
    2530                <div
     
    6570                                                        >
    6671                                                                <img
    67                                                                         src={song.cover}
     72                                                                        src={song.cover || "/favicon.png"}
    6873                                                                        alt={song.title}
    6974                                                                        className="w-10 h-10 rounded object-cover"
Note: See TracChangeset for help on using the changeset viewer.