Changeset 0f71490 for frontend/src/components/userProfile
- Timestamp:
- 01/27/26 12:55:23 (6 months ago)
- Branches:
- main
- Children:
- 4e5cf92
- Parents:
- c6e1892
- Location:
- frontend/src/components/userProfile
- Files:
-
- 3 edited
-
AllUsersHelper.tsx (modified) (3 diffs)
-
ArtistView.tsx (modified) (4 diffs)
-
UserDetailView.tsx (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/components/userProfile/AllUsersHelper.tsx
rc6e1892 r0f71490 1 1 import React, { useEffect, useState } from "react"; 2 2 import { useNavigate } from "react-router-dom"; 3 3 import axiosInstance from "../../api/axiosInstance"; 4 4 interface User { 5 5 id: number; … … 16 16 useEffect(() => { 17 17 const fetchUsers = async () => { 18 const response = await fetch("http://localhost:8080/users/all"); 19 const data = await response.json(); 20 setUsers(data); 18 const response = axiosInstance.get("/users/all"); 19 setUsers((await response).data); 21 20 }; 22 21 fetchUsers(); … … 30 29 e.preventDefault(); 31 30 try { 32 const response = await fetch( 33 `http://localhost:8080/users/search?name=${searchedUser}`, 34 ); 35 if (!response.ok) throw new Error("Search failed"); 36 37 const data = await response.json(); 38 setUsers(data); 31 const response = await axiosInstance.get(`/users/search`, { 32 params: { name: searchedUser }, 33 }); 34 setUsers(response.data); 39 35 } catch (err: any) { 40 setError(err.message); 36 const errorMessage = err.response?.data?.error || "Search failed"; 37 setError(errorMessage); 41 38 } 42 39 }; 43 40 44 41 if (users.length == 0) return <div className="p-6">Loading...</div>; 42 if (error) { 43 return ( 44 <div className="p-6 bg-red-50 border border-red-200 text-red-700 rounded-lg"> 45 <h2 className="font-bold">Error</h2> 46 <p>{error}</p> 47 </div> 48 ); 49 } 45 50 46 51 return ( -
frontend/src/components/userProfile/ArtistView.tsx
rc6e1892 r0f71490 1 1 import { useNavigate } from "react-router-dom"; 2 2 import { Music, Disc3, Mic2 } from "lucide-react"; 3 4 interface ArtistContributionDTO { 5 musicalEntityId: number; 6 title: string; 7 role: string; 8 entityType: string; 9 } 3 import type { ArtistContributionDTO } from "../../types"; 10 4 11 5 interface ArtistViewProps { … … 16 10 const navigate = useNavigate(); 17 11 18 const albums = contributions.filter((c) => c.entityType === "A lbum");19 const songs = contributions.filter((c) => c.entityType === "S ong");12 const albums = contributions.filter((c) => c.entityType === "ALBUM"); 13 const songs = contributions.filter((c) => c.entityType === "SONG"); 20 14 21 15 const getRoleColor = (role: string) => { … … 31 25 return ( 32 26 <div className="mt-8"> 33 {/* Albums Section */}34 27 {albums.length > 0 && ( 35 28 <div className="mb-12"> … … 91 84 </h3> 92 85 <div className="flex items-center gap-2 mt-1"> 93 <Mic2 className="w-4 h-4 text-gray-400" />86 {song.genre} 94 87 </div> 95 88 </div> -
frontend/src/components/userProfile/UserDetailView.tsx
rc6e1892 r0f71490 3 3 import ArtistView from "./ArtistView"; 4 4 import ListenerView from "./ListenerView"; 5 6 interface MusicalEntityDTO { 7 id: number; 8 title: string; 9 genre: string; 10 type: string; 11 } 12 13 interface ArtistContributionDTO { 14 musicalEntityId: number; 15 title: string; 16 role: string; 17 entityType: string; 18 } 19 20 interface Playlist { 21 id: number; 22 name: string; 23 cover: string; 24 creatorName: string; 25 } 5 import axiosInstance from "../../api/axiosInstance"; 6 import type { ArtistContributionDTO } from "../../types"; 7 import type { MusicalEntityDTO } from "../../types"; 8 import type { Playlist } from "../../types"; 26 9 27 10 interface User { … … 32 15 followers: number; 33 16 following: number; 17 isFollowedByCurrentUser: boolean; 34 18 35 19 musicalEntities?: { … … 45 29 46 30 const UserDetail = () => { 31 // user refers to the selected user NOT to the user from context 47 32 const { userId } = useParams(); 48 33 const navigate = useNavigate(); … … 54 39 setError(null); 55 40 try { 56 const response = await fetch(`http://localhost:8080/users/${userId}`);41 const response = await axiosInstance.get(`/users/${userId}`); 57 42 58 if (!response.ok) { 59 const errorData = await response.json(); 60 throw new Error(errorData.error || "Failed to fetch user"); 61 } 62 63 const data = await response.json(); 64 setUser(data); 43 setUser(response.data); 65 44 } catch (err: any) { 66 setError(err.message); 45 const errorMessage = 46 err.response?.data?.error || "Failed to fetch user"; 47 setError(errorMessage); 67 48 } 68 49 }; … … 115 96 </div> 116 97 117 <button className="px-6 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors font-medium">118 Follow98 <button className="px-6 py-2 bg-blue-500 hover:bg-blue-600 text-white font-semibold rounded-lg shadow-md transition-colors duration-200 cursor-pointer"> 99 {user.isFollowedByCurrentUser ? "Unfollow" : "Follow"} 119 100 </button> 120 101 </div>
Note:
See TracChangeset
for help on using the changeset viewer.
