Changeset 98992cf for frontend/src


Ignore:
Timestamp:
01/30/26 00:08:04 (5 months ago)
Author:
Dimitar Arsov <dimitararsov04@…>
Branches:
main
Children:
2b08bed
Parents:
6de2873
Message:

refactor NonAdminUser dtos

Location:
frontend/src
Files:
4 edited

Legend:

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

    r6de2873 r98992cf  
    11import { useNavigate } from "react-router-dom";
    22import { Music, Disc3 } from "lucide-react";
    3 import type { ArtistContributionDTO } from "../../utils/types";
     3import type { ArtistContribution } from "../../utils/types";
    44
    55interface ArtistViewProps {
    6   contributions: ArtistContributionDTO[];
     6  contributions: ArtistContribution[];
    77}
    88
  • frontend/src/components/userProfile/ListenerView.tsx

    r6de2873 r98992cf  
    11import { useNavigate } from "react-router-dom";
    22import { Heart, ListMusic, Music, Album } from "lucide-react";
    3 import type { Playlist, MusicalEntityDTO } from "../../utils/types";
     3import type { Playlist, MusicalEntity } from "../../utils/types";
    44
    55interface ListenerViewProps {
    6   likedEntities: MusicalEntityDTO[];
    7   playlists?: Playlist[];
     6  likedEntities: MusicalEntity[] | [];
     7  playlists: Playlist[] | [];
    88}
    99
     
    1111  const navigate = useNavigate();
    1212
    13   const likedSongs = likedEntities.filter((e) => e.type === "SONG");
    14   const likedAlbums = likedEntities.filter((e) => e.type === "ALBUM");
     13  const likedSongs = likedEntities?.filter((e) => e.type === "SONG");
     14  const likedAlbums = likedEntities?.filter((e) => e.type === "ALBUM");
    1515
    1616  return (
     
    5555      )}
    5656
    57       {likedSongs.length > 0 && (
     57      {likedSongs && likedSongs.length > 0 && (
    5858        <section>
    5959          <div className="flex items-center gap-2 mb-6 pb-2 border-b-2 border-gray-200">
     
    6161            <h3 className="text-2xl font-bold text-gray-800">Liked Songs</h3>
    6262            <span className="text-sm text-gray-400 ml-1">
    63               ({likedSongs.length})
     63              ({likedSongs?.length})
    6464            </span>
    6565          </div>
     
    9090      )}
    9191
    92       {likedAlbums.length > 0 && (
     92      {likedAlbums && likedAlbums.length > 0 && (
    9393        <section>
    9494          <div className="flex items-center gap-2 mb-6 pb-2 border-b-2 border-gray-200">
     
    120120      )}
    121121
    122       {likedEntities.length === 0 && (!playlists || playlists.length === 0) && (
    123         <div className="flex flex-col items-center justify-center py-16 text-gray-300">
    124           <p className="text-lg font-medium text-gray-400">Nothing here yet</p>
    125           <p className="text-sm text-gray-400 mt-1">
    126             Start exploring music to build your collection
    127           </p>
    128         </div>
    129       )}
     122      {likedEntities &&
     123        likedEntities.length === 0 &&
     124        (!playlists || playlists.length === 0) && (
     125          <div className="flex flex-col items-center justify-center py-16 text-gray-300">
     126            <p className="text-lg font-medium text-gray-400">
     127              Nothing here yet
     128            </p>
     129            <p className="text-sm text-gray-400 mt-1">
     130              Start exploring music to build your collection
     131            </p>
     132          </div>
     133        )}
    130134    </div>
    131135  );
  • frontend/src/pages/UserDetailView.tsx

    r6de2873 r98992cf  
    55import ListenerView from "../components/userProfile/ListenerView";
    66import type {
    7   ArtistContributionDTO,
    8   MusicalEntityDTO,
     7  MusicalEntity,
    98  Playlist,
     9  ArtistContribution,
    1010} from "../utils/types";
    1111
    12 interface User {
     12interface BaseUser {
    1313  id: number;
    14   username: string;
    1514  fullName: string;
    1615  userType: string;
     
    1817  following: number;
    1918  isFollowedByCurrentUser: boolean;
     19}
    2020
    21   musicalEntities?: {
    22     contributions: ArtistContributionDTO[];
    23   };
     21interface Artist extends BaseUser {
     22  userType: "ARTIST";
     23  contributions: ArtistContribution[];
     24}
     25interface Listener extends BaseUser {
     26  userType: "LISTENER";
     27  likedEntities: MusicalEntity[];
     28  createdPlaylists: Playlist[];
     29}
    2430
    25   likes?: {
    26     likedEntities: MusicalEntityDTO[];
    27   };
    28 
    29   createdPlaylists?: Playlist[];
    30 }
     31type UserProfile = Artist | Listener;
    3132
    3233const UserDetail = () => {
     
    3435  const { userId } = useParams();
    3536  const navigate = useNavigate();
    36   const [user, setUser] = useState<User | null>(null);
     37  const [user, setUser] = useState<UserProfile | null>(null);
    3738  const [error, setError] = useState<string | null>(null);
    3839  const [isFollowing, setIsFollowing] = useState(false);
     
    4344    setIsFollowing(true);
    4445    try {
    45       const response = await axiosInstance.post<User>(
     46      const response = await axiosInstance.post<UserProfile>(
    4647        `/users/follow/${userId}`,
    4748      );
    48       setUser(response.data);
    4949    } catch (err: any) {
    5050      console.error(err.response?.data?.error);
     
    5959      try {
    6060        const response = await axiosInstance.get(`/users/${userId}`);
     61        console.log(response.data);
    6162
    6263        setUser(response.data);
     
    135136        </div>
    136137
    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        ) : (
    142141          <ListenerView
    143             likedEntities={user.likes.likedEntities}
     142            likedEntities={user.likedEntities}
    144143            playlists={user.createdPlaylists}
    145144          />
  • frontend/src/utils/types.ts

    r6de2873 r98992cf  
    11export interface User {
    2         username: string;
    3         fullName: string;
    4         email?: string;
    5         profilePhoto?: string | null;
    6         role?: "ADMIN" | "NONADMIN";
     2  username: string;
     3  fullName: string;
     4  email?: string;
     5  profilePhoto?: string | null;
     6  role?: "ADMIN" | "NONADMIN";
    77}
    88
    9 export interface ArtistContributionDTO {
    10         musicalEntityId: number;
    11         title: string;
    12         genre: string;
    13         role: string;
    14         entityType: string;
     9export interface ArtistContribution {
     10  musicalEntityId: number;
     11  title: string;
     12  genre: string;
     13  role: string;
     14  entityType: string;
    1515}
    16 export interface MusicalEntityDTO {
    17         id: number;
    18         title: string;
    19         genre: string;
    20         type: string;
     16export interface MusicalEntity {
     17  id: number;
     18  title: string;
     19  genre: string;
     20  type: string;
    2121}
    2222
    2323export interface Playlist {
    24         id: number;
    25         name: string;
    26         cover: string;
    27         creatorName: string;
     24  id: number;
     25  name: string;
     26  cover: string;
     27  creatorName: string;
    2828}
Note: See TracChangeset for help on using the changeset viewer.