source: frontend/src/components/userProfile/UserDetail.tsx@ fd81a18

main
Last change on this file since fd81a18 was fd81a18, checked in by Dimitar Arsov <dimitararsov04@…>, 6 months ago

add playlists to user profile

  • Property mode set to 100644
File size: 3.5 KB
Line 
1import { useEffect, useState } from "react";
2import { useParams, useNavigate } from "react-router-dom";
3import ArtistView from "./ArtistView";
4import ListenerView from "./ListenerView";
5
6interface MusicalEntityDTO {
7 id: number;
8 title: string;
9 genre: string;
10 type: string;
11}
12
13interface ArtistContributionDTO {
14 musicalEntityId: number;
15 title: string;
16 role: string;
17 entityType: string;
18}
19
20interface Playlist {
21 id: number;
22 name: string;
23 cover: string;
24 creatorName: string;
25}
26
27interface User {
28 id: number;
29 username: string;
30 fullName: string;
31 userType: string;
32 followers: number;
33 following: number;
34
35 musicalEntities?: {
36 contributions: ArtistContributionDTO[];
37 };
38
39 likes?: {
40 likedEntities: MusicalEntityDTO[];
41 };
42
43 createdPlaylists?: Playlist[];
44}
45
46const UserDetail = () => {
47 const { userId } = useParams();
48 const navigate = useNavigate();
49 const [user, setUser] = useState<User | null>(null);
50
51 useEffect(() => {
52 const fetchUser = async () => {
53 console.log(userId);
54 const response = await fetch(`http://localhost:8080/users/${userId}`);
55 const data = await response.json();
56 console.log("Fetched user data:", data);
57 setUser(data);
58 };
59 fetchUser();
60 }, [userId]);
61
62 if (!user) return <div className="p-6">Loading...</div>;
63
64 return (
65 <div className="container mx-auto p-6">
66 <button
67 onClick={() => navigate(-1)}
68 className="mb-4 px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
69 >
70 ← Back
71 </button>
72
73 <div className="bg-white shadow-lg rounded-lg p-8">
74 {/* Profile Header */}
75 <div className="flex items-start gap-6 mb-8">
76 {/* Profile Photo */}
77 <div className="shrink-0">
78 <div className="w-32 h-32 rounded-full bg-linear-to-br from-blue-400 to-purple-500 flex items-center justify-center text-white text-4xl font-bold shadow-lg">
79 {user.fullName.charAt(0).toUpperCase()}
80 </div>
81 </div>
82
83 {/* User Info */}
84 <div className="flex-1">
85 <h1 className="text-4xl font-bold mb-2">{user.fullName}</h1>
86 <span className="inline-block px-3 py-1 bg-blue-100 text-blue-800 rounded-full text-sm font-medium mb-4">
87 {user.userType}
88 </span>
89
90 {/* Followers/Following Stats */}
91 <div className="flex gap-6 mb-4 text-gray-700">
92 <div className="flex flex-col">
93 <span className="text-2xl font-bold">{user.followers}</span>
94 <span className="text-sm text-gray-500">Followers</span>
95 </div>
96 <div className="flex flex-col">
97 <span className="text-2xl font-bold">{user.following}</span>
98 <span className="text-sm text-gray-500">Following</span>
99 </div>
100 </div>
101
102 <button className="px-6 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors font-medium">
103 Follow
104 </button>
105 </div>
106 </div>
107
108 {user.userType === "ARTIST" && user.musicalEntities?.contributions && (
109 <ArtistView contributions={user.musicalEntities.contributions} />
110 )}
111
112 {user.userType === "LISTENER" && user.likes?.likedEntities && (
113 <ListenerView
114 likedEntities={user.likes.likedEntities}
115 playlists={user.createdPlaylists}
116 />
117 )}
118 </div>
119 </div>
120 );
121};
122
123export default UserDetail;
Note: See TracBrowser for help on using the repository browser.