Changeset 98992cf for frontend/src/pages/UserDetailView.tsx
- Timestamp:
- 01/30/26 00:08:04 (5 months ago)
- Branches:
- main
- Children:
- 2b08bed
- Parents:
- 6de2873
- File:
-
- 1 edited
-
frontend/src/pages/UserDetailView.tsx (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
frontend/src/pages/UserDetailView.tsx
r6de2873 r98992cf 5 5 import ListenerView from "../components/userProfile/ListenerView"; 6 6 import type { 7 ArtistContributionDTO, 8 MusicalEntityDTO, 7 MusicalEntity, 9 8 Playlist, 9 ArtistContribution, 10 10 } from "../utils/types"; 11 11 12 interface User {12 interface BaseUser { 13 13 id: number; 14 username: string;15 14 fullName: string; 16 15 userType: string; … … 18 17 following: number; 19 18 isFollowedByCurrentUser: boolean; 19 } 20 20 21 musicalEntities?: { 22 contributions: ArtistContributionDTO[]; 23 }; 21 interface Artist extends BaseUser { 22 userType: "ARTIST"; 23 contributions: ArtistContribution[]; 24 } 25 interface Listener extends BaseUser { 26 userType: "LISTENER"; 27 likedEntities: MusicalEntity[]; 28 createdPlaylists: Playlist[]; 29 } 24 30 25 likes?: { 26 likedEntities: MusicalEntityDTO[]; 27 }; 28 29 createdPlaylists?: Playlist[]; 30 } 31 type UserProfile = Artist | Listener; 31 32 32 33 const UserDetail = () => { … … 34 35 const { userId } = useParams(); 35 36 const navigate = useNavigate(); 36 const [user, setUser] = useState<User | null>(null);37 const [user, setUser] = useState<UserProfile | null>(null); 37 38 const [error, setError] = useState<string | null>(null); 38 39 const [isFollowing, setIsFollowing] = useState(false); … … 43 44 setIsFollowing(true); 44 45 try { 45 const response = await axiosInstance.post<User >(46 const response = await axiosInstance.post<UserProfile>( 46 47 `/users/follow/${userId}`, 47 48 ); 48 setUser(response.data);49 49 } catch (err: any) { 50 50 console.error(err.response?.data?.error); … … 59 59 try { 60 60 const response = await axiosInstance.get(`/users/${userId}`); 61 console.log(response.data); 61 62 62 63 setUser(response.data); … … 135 136 </div> 136 137 137 {user.userType === "ARTIST" && user.musicalEntities?.contributions && ( 138 <ArtistView contributions={user.musicalEntities.contributions} /> 139 )} 140 141 {user.userType === "LISTENER" && user.likes?.likedEntities && ( 138 {user.userType === "ARTIST" ? ( 139 <ArtistView contributions={user.contributions} /> 140 ) : ( 142 141 <ListenerView 143 likedEntities={user.like s.likedEntities}142 likedEntities={user.likedEntities} 144 143 playlists={user.createdPlaylists} 145 144 />
Note:
See TracChangeset
for help on using the changeset viewer.
