| [0d9725c] | 1 | import { useEffect, useState } from "react";
|
|---|
| 2 | import { useParams, useNavigate } from "react-router-dom";
|
|---|
| 3 |
|
|---|
| 4 | interface User {
|
|---|
| 5 | id: number;
|
|---|
| 6 | username: string;
|
|---|
| 7 | fullName: string;
|
|---|
| 8 | followerCount: number;
|
|---|
| 9 | followingCount: number;
|
|---|
| 10 | userType: string;
|
|---|
| 11 | contributions?: {
|
|---|
| 12 | role: string;
|
|---|
| 13 | title: string;
|
|---|
| 14 | musicalEntityId: number;
|
|---|
| 15 | entityType: string;
|
|---|
| 16 | }[];
|
|---|
| 17 |
|
|---|
| 18 | likedEntities?: {
|
|---|
| 19 | entityId: number;
|
|---|
| 20 | entityTitle: string;
|
|---|
| 21 | entityGenre: string;
|
|---|
| 22 | entityType: string;
|
|---|
| 23 | }[];
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | const UserDetail = () => {
|
|---|
| 27 | const { userId } = useParams();
|
|---|
| 28 | const navigate = useNavigate();
|
|---|
| 29 | const [user, setUser] = useState<User | null>(null);
|
|---|
| 30 |
|
|---|
| 31 | useEffect(() => {
|
|---|
| 32 | const fetchUser = async () => {
|
|---|
| 33 | console.log(userId);
|
|---|
| 34 | const response = await fetch(`http://localhost:8080/users/${userId}`);
|
|---|
| 35 | const data = await response.json();
|
|---|
| 36 | setUser(data);
|
|---|
| 37 | };
|
|---|
| 38 | fetchUser();
|
|---|
| 39 | }, [userId]);
|
|---|
| 40 |
|
|---|
| 41 | if (!user) return <div className="p-6">Loading...</div>;
|
|---|
| 42 |
|
|---|
| 43 | return (
|
|---|
| 44 | <div className="container mx-auto p-6">
|
|---|
| 45 | {/* <button
|
|---|
| 46 | onClick={() => navigate("/allUsers")}
|
|---|
| 47 | className="mb-4 px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
|
|---|
| 48 | >
|
|---|
| 49 | ← Back to All Users
|
|---|
| 50 | </button> */}
|
|---|
| 51 | <div className="bg-white shadow-lg rounded-lg p-8">
|
|---|
| 52 | <h1 className="text-4xl font-bold mb-4">{user.fullName}</h1>
|
|---|
| 53 | <p className="text-gray-600 text-lg mb-2">Username: @{user.username}</p>
|
|---|
| 54 | <p className="text-gray-600 text-lg mb-2">
|
|---|
| 55 | Followers: {user.followerCount}
|
|---|
| 56 | </p>
|
|---|
| 57 | <p className="text-gray-600 text-lg mb-2">
|
|---|
| 58 | Following: {user.followingCount}
|
|---|
| 59 | </p>
|
|---|
| 60 | <p>Type: {user.userType}</p>
|
|---|
| 61 | {user.userType === "Artist" && user.contributions && (
|
|---|
| 62 | <div className="mt-8 border-t pt-6">
|
|---|
| 63 | <h2 className="text-2xl font-bold mb-4">Discography</h2>
|
|---|
| 64 | <div className="grid gap-3">
|
|---|
| 65 | {user.contributions.map((item, index) => (
|
|---|
| 66 | <div
|
|---|
| 67 | key={index}
|
|---|
| 68 | className="p-4 border rounded flex justify-between items-center"
|
|---|
| 69 | >
|
|---|
| 70 | <div>
|
|---|
| 71 | <p className="font-semibold">{item.title}</p>
|
|---|
| 72 | <p className="text-sm text-gray-500">{item.entityType}</p>
|
|---|
| 73 | </div>
|
|---|
| 74 | <span className="bg-gray-100 px-3 py-1 rounded-full text-sm font-medium">
|
|---|
| 75 | {item.role}
|
|---|
| 76 | </span>
|
|---|
| 77 | <span className="bg-gray-100 px-3 py-1 rounded-full text-sm font-medium">
|
|---|
| 78 | {item.musicalEntityId}
|
|---|
| 79 | </span>
|
|---|
| 80 | </div>
|
|---|
| 81 | ))}
|
|---|
| 82 | </div>
|
|---|
| 83 | </div>
|
|---|
| 84 | )}
|
|---|
| 85 |
|
|---|
| 86 | {user.userType === "Listener" && user.likedEntities && (
|
|---|
| 87 | <div>
|
|---|
| 88 | <h3 className="text-2xl font-bold mb-4">Liked Songs & Albums</h3>
|
|---|
| 89 | <div className="grid gap-2">
|
|---|
| 90 | {user.likedEntities.map((like) => (
|
|---|
| 91 | <div
|
|---|
| 92 | key={like.entityId}
|
|---|
| 93 | className="p-3 bg-gray-50 rounded flex justify-between"
|
|---|
| 94 | >
|
|---|
| 95 | <span>{like.entityTitle}</span>
|
|---|
| 96 | <span className="text-sm text-gray-400">
|
|---|
| 97 | {like.entityType}
|
|---|
| 98 | </span>
|
|---|
| 99 | <span className="text-sm text-gray-400">
|
|---|
| 100 | {like.entityGenre}
|
|---|
| 101 | </span>
|
|---|
| 102 | </div>
|
|---|
| 103 | ))}
|
|---|
| 104 | </div>
|
|---|
| 105 | </div>
|
|---|
| 106 | )}
|
|---|
| 107 | </div>
|
|---|
| 108 | </div>
|
|---|
| 109 | );
|
|---|
| 110 | };
|
|---|
| 111 |
|
|---|
| 112 | export default UserDetail;
|
|---|