Ignore:
Timestamp:
01/27/26 12:55:23 (6 months ago)
Author:
Dimitar Arsov <dimitararsov04@…>
Branches:
main
Children:
4e5cf92
Parents:
c6e1892
Message:

show follow/following button

File:
1 edited

Legend:

Unmodified
Added
Removed
  • frontend/src/components/userProfile/UserDetailView.tsx

    rc6e1892 r0f71490  
    33import ArtistView from "./ArtistView";
    44import 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 }
     5import axiosInstance from "../../api/axiosInstance";
     6import type { ArtistContributionDTO } from "../../types";
     7import type { MusicalEntityDTO } from "../../types";
     8import type { Playlist } from "../../types";
    269
    2710interface User {
     
    3215  followers: number;
    3316  following: number;
     17  isFollowedByCurrentUser: boolean;
    3418
    3519  musicalEntities?: {
     
    4529
    4630const UserDetail = () => {
     31  // user refers to the selected user NOT to the user from context
    4732  const { userId } = useParams();
    4833  const navigate = useNavigate();
     
    5439      setError(null);
    5540      try {
    56         const response = await fetch(`http://localhost:8080/users/${userId}`);
     41        const response = await axiosInstance.get(`/users/${userId}`);
    5742
    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);
    6544      } catch (err: any) {
    66         setError(err.message);
     45        const errorMessage =
     46          err.response?.data?.error || "Failed to fetch user";
     47        setError(errorMessage);
    6748      }
    6849    };
     
    11596            </div>
    11697
    117             <button className="px-6 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors font-medium">
    118               Follow
     98            <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"}
    119100            </button>
    120101          </div>
Note: See TracChangeset for help on using the changeset viewer.