veza/apps/web/dist_verification/assets/UserProfilePage-CGqKROeh.js

1 line
9.9 KiB
JavaScript

import{a as P,j as s}from"./vendor-react-BHG7lGYR.js";import{d as K,L as p}from"./vendor-router-D-s5vIeO.js";import{a as B,u as f}from"./vendor-tanstack-BzWBL1hV.js";import{f as V,a as $,g as M,u as z}from"./users-BcpK1D4V.js";import{t as Q}from"./tracks-Bqg0pqgn.js";import{p as H}from"./playlists-C-Ora5VP.js";import{u as F,g as J,B as L,p as R,L as N,C as l,e as o,b as y,c as g}from"./index-BWcMVITa.js";import{i as G,aH as O,aI as W,J as q,ab as k,ad as _}from"./vendor-icons-DaGlTw4_.js";import{A as U}from"./avatar-B2y8ugWJ.js";import{T as X,a as Y,b as T,c as C}from"./tabs-DP-eavm_.js";import{P as Z}from"./PlaylistCard-z0bLl0kY.js";import{s as I}from"./socialService-is9ldyAe.js";import{h as ss}from"./vendor-utils-CgOSfOkx.js";import"./vendor-IYr-MHu4.js";import"./features-6vY6zDlz.js";function es({userId:t,initialFollowing:n=!1,onFollowChange:e,className:v,size:u="default",variant:i}){const{data:c}=F(),{success:m,error:b}=J(),r=B(),[x,d]=P.useState(n),[h,j]=P.useState(!1),{data:a}=f({queryKey:["userProfile",t],queryFn:()=>M(t),enabled:!!t&&t!==c?.id,staleTime:3e4});if(P.useEffect(()=>{a&&a.is_following!==void 0?d(a.is_following):n!==void 0&&d(n)},[a,n]),c?.id===t)return null;const S=async()=>{if(h||!c)return;j(!0);const w=!x;try{w?(await V(t),m("Vous suivez maintenant cet utilisateur")):(await $(t),m("Vous ne suivez plus cet utilisateur")),d(w),e?.(w),r.invalidateQueries({queryKey:["userProfile",t]}),r.invalidateQueries({queryKey:["userProfile"]})}catch(E){const D=R(E).message;b(D)}finally{j(!1)}};if(c?.id===t||!c)return null;const A=i||(x?"outline":"default");return s.jsx(L,{onClick:S,disabled:h,variant:A,size:u,className:v||"min-w-[100px]",children:h?s.jsxs(s.Fragment,{children:[s.jsx(G,{className:"h-4 w-4 animate-spin mr-2"}),x?"Désabonnement...":"Abonnement..."]}):x?s.jsxs(s.Fragment,{children:[s.jsx(O,{className:"h-4 w-4 mr-2"}),"Abonné"]}):s.jsxs(s.Fragment,{children:[s.jsx(W,{className:"h-4 w-4 mr-2"}),"Suivre"]})})}function Ns(){const{username:t}=K(),{data:n}=F(),{data:e,isLoading:v,error:u}=f({queryKey:["userProfile",t],queryFn:async()=>{if(!t)throw new Error("Username is required");return z.getProfileByUsername(t)},enabled:!!t,retry:!1}),{data:i,isLoading:c}=f({queryKey:["userTracks",e?.id],queryFn:()=>Q.list(1,12,{userId:e?.id}),enabled:!!e?.id}),{data:m,isLoading:b}=f({queryKey:["userPosts",e?.id],queryFn:()=>I.getPostsByUser(e.id,1,e),enabled:!!e?.id}),{data:r,isLoading:x}=f({queryKey:["userPlaylists",e?.id],queryFn:()=>H.list(1,12,e?.id),enabled:!!e?.id});if(v)return s.jsx("div",{className:"container mx-auto px-4 py-8",children:s.jsx("div",{className:"flex items-center justify-center min-h-[400px]",children:s.jsxs("div",{className:"text-center",children:[s.jsx(N,{}),s.jsx("p",{className:"mt-4 text-muted-foreground",children:"Loading profile..."})]})})});if(u||!t)return s.jsx("div",{className:"container mx-auto px-4 py-8",children:s.jsx(l,{children:s.jsx(o,{className:"pt-6",children:s.jsxs("div",{className:"text-center",children:[s.jsx("h2",{className:"text-2xl font-bold text-destructive mb-2",children:"Error"}),s.jsx("p",{className:"text-muted-foreground",children:u instanceof Error?u.message:t?"Failed to load profile":"Username is required"})]})})})});if(!e)return s.jsx("div",{className:"container mx-auto px-4 py-8",children:s.jsx(l,{children:s.jsx(o,{className:"pt-6",children:s.jsxs("div",{className:"text-center",children:[s.jsx("h2",{className:"text-2xl font-bold mb-2",children:"User Not Found"}),s.jsx("p",{className:"text-muted-foreground",children:"The user profile you're looking for doesn't exist."})]})})})});const d=e.first_name||e.last_name?`${e.first_name||""} ${e.last_name||""}`.trim():e.username,h=d.split(" ").map(a=>a[0]).join("").toUpperCase().slice(0,2),j=e.created_at?ss(new Date(e.created_at),"M/d/yyyy"):null;return s.jsx("div",{className:"container mx-auto px-4 py-8",children:s.jsxs("div",{className:"max-w-4xl mx-auto",children:[s.jsxs(l,{children:[s.jsx(y,{children:s.jsxs("div",{className:"flex items-start justify-between",children:[s.jsxs("div",{className:"flex items-center gap-4",children:[s.jsx(U,{src:e.avatar_url||void 0,alt:e.username,fallback:h,size:"3xl",className:"h-24 w-24"}),s.jsxs("div",{children:[s.jsx(g,{className:"text-3xl mb-1",children:e.username}),d!==e.username&&s.jsx("p",{className:"text-xl text-muted-foreground",children:d}),j&&s.jsxs("p",{className:"text-sm text-muted-foreground mt-2",children:["Member since ",j]})]})]}),s.jsx(es,{userId:e.id.toString()})]})}),s.jsx(o,{children:s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"grid grid-cols-3 gap-4 pb-4 border-b",children:[s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"text-2xl font-bold",children:i?.pagination.total||0}),s.jsx("div",{className:"text-sm text-muted-foreground",children:"Tracks"})]}),s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"text-2xl font-bold",children:r?.total||0}),s.jsx("div",{className:"text-sm text-muted-foreground",children:"Playlists"})]}),s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"text-2xl font-bold",children:e.followers_count||0}),s.jsx("div",{className:"text-sm text-muted-foreground",children:"Followers"})]})]}),e.bio&&s.jsxs("div",{children:[s.jsx("h3",{className:"font-semibold mb-2",children:"Bio"}),s.jsx("p",{className:"text-muted-foreground whitespace-pre-wrap",children:e.bio})]}),e.location&&s.jsxs("div",{children:[s.jsx("h3",{className:"font-semibold mb-2",children:"Location"}),s.jsx("p",{className:"text-muted-foreground",children:e.location})]}),!e.bio&&!e.location&&s.jsx("p",{className:"text-muted-foreground italic",children:"No additional information available."})]})})]}),s.jsxs(X,{defaultValue:"tracks",className:"w-full mt-6",children:[s.jsxs(Y,{children:[s.jsxs(T,{value:"posts",children:[s.jsx(q,{className:"mr-2 h-4 w-4"}),"Posts"]}),s.jsxs(T,{value:"tracks",children:[s.jsx(k,{className:"mr-2 h-4 w-4"}),"Tracks (",i?.pagination.total||0,")"]}),s.jsxs(T,{value:"playlists",children:[s.jsx(_,{className:"mr-2 h-4 w-4"}),"Playlists (",r?.total||0,")"]})]}),s.jsx(C,{value:"posts",className:"mt-6",children:s.jsxs(l,{children:[s.jsx(y,{children:s.jsx(g,{children:"Posts"})}),s.jsx(o,{children:b?s.jsx("div",{className:"flex justify-center py-8",children:s.jsx(N,{})}):m?.posts&&m.posts.length>0?s.jsx("div",{className:"space-y-4",children:m.posts.map(a=>s.jsx(l,{className:"p-4",children:s.jsxs("div",{className:"flex items-start gap-4",children:[s.jsx(U,{src:a.author.avatar,alt:a.author.name,fallback:a.author.name[0]}),s.jsxs("div",{className:"flex-1",children:[s.jsxs("div",{className:"flex items-baseline justify-between",children:[s.jsxs("h4",{className:"font-semibold",children:[a.author.name," ",s.jsx("span",{className:"text-sm font-normal text-muted-foreground",children:a.author.handle})]}),s.jsx("span",{className:"text-xs text-muted-foreground",children:new Date(a.timestamp).toLocaleDateString()})]}),s.jsx("p",{className:"mt-2 text-sm",children:a.content}),s.jsxs("div",{className:"mt-3 flex items-center gap-4 text-xs text-muted-foreground",children:[s.jsxs("span",{children:[a.likes," Likes"]}),s.jsxs("span",{children:[a.comments," Comments"]})]})]})]})},a.id))}):s.jsxs("div",{className:"text-center py-8",children:[s.jsx(q,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground opacity-50"}),s.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No posts yet"}),s.jsx("p",{className:"text-muted-foreground",children:"This user hasn't posted anything yet."})]})})]})}),s.jsx(C,{value:"tracks",className:"mt-6",children:s.jsxs(l,{children:[s.jsx(y,{children:s.jsx(g,{children:"Tracks"})}),s.jsxs(o,{children:[c?s.jsx("div",{className:"flex justify-center py-8",children:s.jsx(N,{})}):i?.tracks&&i.tracks.length>0?s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:i.tracks.map(a=>s.jsx(p,{to:`/tracks/${a.id}`,children:s.jsxs(l,{className:"overflow-hidden hover:shadow-lg transition-shadow cursor-pointer",children:[s.jsx("div",{className:"relative aspect-square bg-muted flex items-center justify-center",children:a.cover_art_path?s.jsx("img",{src:a.cover_art_path,alt:a.title,className:"w-full h-full object-cover"}):s.jsx(k,{className:"h-16 w-16 text-muted-foreground/50"})}),s.jsxs(o,{className:"p-4",children:[s.jsx("h3",{className:"font-medium truncate",children:a.title}),a.artist&&s.jsx("p",{className:"text-sm text-muted-foreground truncate",children:a.artist})]})]})},a.id))}):s.jsxs("div",{className:"text-center py-8",children:[s.jsx(k,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground opacity-50"}),s.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No tracks yet"}),s.jsx("p",{className:"text-muted-foreground",children:n?.id===e.id?"Start by uploading your first track to share with others.":"This user has not uploaded any tracks yet."})]}),i&&i.pagination.total>12&&s.jsx("div",{className:"mt-4 text-center",children:s.jsx(L,{variant:"outline",asChild:!0,children:s.jsx(p,{to:`/tracks?user_id=${e.id}`,children:"View All Tracks"})})})]})]})}),s.jsx(C,{value:"playlists",className:"mt-6",children:s.jsxs(l,{children:[s.jsx(y,{children:s.jsx(g,{children:"Playlists"})}),s.jsxs(o,{children:[x?s.jsx("div",{className:"flex justify-center py-8",children:s.jsx(N,{})}):r?.playlists&&r.playlists.length>0?s.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:r.playlists.map(a=>s.jsx(p,{to:`/playlists/${a.id}`,children:s.jsx(Z,{playlist:a})},a.id))}):s.jsxs("div",{className:"text-center py-8",children:[s.jsx(_,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground opacity-50"}),s.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No playlists yet"}),s.jsx("p",{className:"text-muted-foreground",children:n?.id===e.id?"Create your first playlist to organize your favorite tracks.":"This user has not created any playlists yet."})]}),r&&r.total>12&&s.jsx("div",{className:"mt-4 text-center",children:s.jsx(L,{variant:"outline",asChild:!0,children:s.jsx(p,{to:`/playlists?user_id=${e.id}`,children:"View All Playlists"})})})]})]})})]})]})})}export{Ns as UserProfilePage};