veza/apps/web/dist_verification/assets/LibraryPage-55ubQtbB.js

7 lines
15 KiB
JavaScript
Raw Normal View History

import{a as o,j as e}from"./vendor-react-BHG7lGYR.js";import{u as ce,a as de}from"./vendor-tanstack-BzWBL1hV.js";import{g as me,t as ue}from"./tracks-Bqg0pqgn.js";import{j as xe,D as he,k as pe,B as v,m as fe,l as je,n as ge,d as _}from"./index-BWcMVITa.js";import{I as L}from"./input-BGBI2Wze.js";import{u as we,D as be,a as Ne,b as ve,c as Q}from"./useIsRateLimited-HpmSVPdB.js";import{F as ye}from"./vendor-IYr-MHu4.js";import{P as ke}from"./progress-BQIngDvS.js";import{L as P}from"./label-N1Bsuay_.js";import{A as $}from"./alert-tey2YzVZ.js";import{as as z,X as Ce,A as Se,a9 as Le,h as X,ae as Ae,n as De,at as Ee,L as Te,ah as Me,au as Fe,a3 as K,g as Re,aj as Pe,D as ze,T as Ue}from"./vendor-icons-DaGlTw4_.js";import{c as Ie}from"./vendor-router-D-s5vIeO.js";import{f as W,d as Y}from"./vendor-utils-CgOSfOkx.js";import"./dropdown-BYn_8IId.js";const B={all:["library"],tracks:m=>[...B.all,"tracks",{userId:m}]};function Ve(m=1,p=50){const{user:i}=xe();return ce({queryKey:[...B.tracks(i?.id),{page:m,limit:p}],queryFn:()=>me({userId:i?.id,page:m,limit:p}),enabled:!!i?.id,placeholderData:f=>f})}const _e=100*1024*1024,qe={"audio/mpeg":[".mp3"],"audio/wav":[".wav"],"audio/ogg":[".ogg"],"audio/flac":[".flac"],"audio/mp4":[".m4a"],"audio/aac":[".aac"]},q=3;function Be({open:m,onClose:p}){const[i,f]=o.useState(null),[y,u]=o.useState(0),[n,g]=o.useState(!1),[k,c]=o.useState(null),[A,x]=o.useState(null),[C,w]=o.useState(!1),[b,S]=o.useState(0),[j,h]=o.useState(!1),s=we(),l=de(),[N,U]=o.useState({file:null,title:"",artist:"",album:"",genre:""}),[Z,I]=o.useState({}),D=t=>({value:N[t],onChange:a=>{U(d=>({...d,[t]:a.target.value}))}}),E=(t,a)=>{U(d=>({...d,[t]:a}))},T=()=>N,H=()=>{U({file:null,title:"",artist:"",album:"",genre:""}),I({})},J=(t,a)=>d=>{if(d.preventDefault(),!N.file){I({file:"Veuillez sélectionner un fichier"}),a?.({file:{message:"Veuillez sélectionner un fichier"}});return}I({}),t(N)},G=Z,ee=o.useCallback(t=>{const a=t[0];if(a){f(a),c(null),h(!1),E("file",a);const d=a.name.replace(/\.[^/.]+$/,"");T()||E("title",d)}},[E,T]),{getRootProps:se,getInputProps:te,isDragActive:O}=ye({onDrop:ee,accept:qe,maxSize:_e,multiple:!1,onError:t=>{c(`Erreur lors de la sélection du fichier: ${t.message}`)},onDropRejected:t=>{const a=t[0];a.errors[0]?.code==="file-too-large"?c("Le fichier est trop volumineux (max 100 MB)"):a.errors[0]?.code==="file-invalid-type"?c("Format de fichier non supporté. Formats acceptés: MP3, WAV, OGG, FLAC, M4A, AAC"):c(a.errors[0]?.message||"Erreur lors de la sélection du fichier")}}),M=o.useCallback(async(t,a=1)=>{if(!t.file){c("Veuillez sélectionner un fichier"),x(null),w(!1);return}g(!0),c(null),x(null),w(!1),h(!1),u(0);try{const d={title:t.title||t.file.name.replace(/\.[^/.]+$/,""),artist:t.artist,album:t.album,genre:t.genre,is_public:!1};await ue.create(t.file,d,r=>{u(r)}),h(!0),u(100),S(0),l.invalidateQueries({queryKey:B.all}),l.invalidateQueries({queryKey:["tracks"]}),setTimeout(()=>{V()},1500)}catch(d){let r="Erreur lors de l'upload",F=null,R=!1;if(d instanceof Error){r=d.message;const oe=r.toLowerCase().includes("network")||r.toLowerCase().includes("réseau")||r.toLowerCase().includes("timeout")||r.toLowerCase().includes("econnaborted")||r.toLowerCase().includes("etimedout")||r.toLowerCase().includes("se connecter"),ie=r.toLowerCase().includes("serveur")||r.toLowerCase().includes("server")||r.toLowerCase().includes("500")||r.toLowerCase().includes("503")||r.toLowerCase().includes("502"),ne=r.toLowerCase().includes("format")||r.toLowerCase().includes("taille")||r.toLowerCase().includes("invalide")||r.toLowerCase().includes("trop volumineux")||r.toLowerCase().includes("non supporté")||r.toLowerCase().includes("400")||r.toLowerCase().includes("413")||r.toLowerCase().includes("415");oe?(F="NETWORK",R=a<q):ie?(F="SERVER",R=a<q):ne&&(F="VALIDATION",R=!1)}c(r),x(F),w(R),u(0),S(a)}finally{g(!1)}},[l]),re=o.useCallback(async t=>{await M(t,1)},[M]),ae=o.useCallback(()=>{const t=T(),a=b+1;M(t,a)},[b,T,M]),V=()=>{n||(f(null),u(0),c(null),x(null),w(!1),S(0),h(!1),H(),p())},le=()=>{f(null),c(null),h(!1),u(0),E
border-2 border-dashed rounded-lg p-12 text-center cursor-pointer
transition-colors
${O?"border-primary bg-primary/5":"border-muted-foreground/25"}
hover:border-primary hover:bg-primary/5
`,children:[e.jsx("input",{...te()}),e.jsx(z,{className:"mx-auto h-12 w-12 text-muted-foreground mb-4"}),e.jsx("p",{className:"text-lg font-medium mb-2",children:O?"Déposez le fichier ici":"Glissez-déposez un fichier audio"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"ou cliquez pour sélectionner"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Formats acceptés: MP3, WAV, OGG, FLAC, M4A, AAC (max 100 MB)"})]}),n&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{children:"Upload en cours..."}),e.jsxs("span",{children:[y,"%"]})]}),e.jsx(ke,{value:y})]}),k&&e.jsx($,{variant:"destructive","data-testid":"upload-error",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx(Se,{className:"h-4 w-4 mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:k}),A&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Code d'erreur: ",A]}),b>0&&e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Tentative ",b,"/",q]})]}),C&&e.jsxs(v,{type:"button",variant:"outline",size:"sm",onClick:ae,disabled:n,className:"mt-2",children:[e.jsx(Le,{className:"h-4 w-4 mr-2"}),"Réessayer"]})]})]})}),j&&e.jsxs($,{className:"bg-kodo-lime/10 border-kodo-lime text-kodo-lime",children:[e.jsx(X,{className:"h-4 w-4"}),e.jsx("span",{children:"Fichier uploadé avec succès !"})]}),i&&!n&&!j&&e.jsxs("div",{className:"space-y-4 border-t pt-4",children:[e.jsx("h3",{className:"font-medium",children:"Métadonnées (optionnel)"}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"title",children:"Titre *"}),e.jsx(L,{id:"title",...D("title"),placeholder:"Titre du morceau"}),G.title&&e.jsx("p",{className:"text-sm text-destructive",children:G.title.message})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"artist",children:"Artiste"}),e.jsx(L,{id:"artist",...D("artist"),placeholder:"Nom de l'artiste"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"album",children:"Album"}),e.jsx(L,{id:"album",...D("album"),placeholder:"Nom de l'album"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(P,{htmlFor:"genre",children:"Genre"}),e.jsx(L,{id:"genre",...D("genre"),placeholder:"Genre musical"})]})]})]})]})}),e.jsxs(fe,{children:[e.jsx(v,{variant:"outline",onClick:V,disabled:n,type:"button",children:j?"Fermer":"Annuler"}),!j&&e.jsxs(v,{type:"submit",form:"upload-track-form",disabled:!i||n||s,className:"gap-2",children:[e.jsx(Ae,{className:"h-4 w-4"}),n?"Upload en cours...":"Uploader"]})]})]})})}function rs(){const[m,p]=o.useState("grid"),[i,f]=o.useState(""),[y,u]=o.useState(new Set),[n,g]=Ie(),{playTrack:k}=ge(),{data:c,isLoading:A}=Ve(1,100),x=c?.tracks||[],C=o.useMemo(()=>x?x.filter(s=>s.title.toLowerCase().includes(i.toLowerCase())||(typeof s.artist=="string"?s.artist:s.artist?.name)?.toLowerCase().includes(i.toLowerCase())):[],[x,i]),w=s=>{const l=new Set(y);l.has(s)?l.delete(s):l.add(s),u(l)},b=n.get("action")==="upload",S=()=>{n.delete("action"),g(n)},j=s=>typeof s.artist=="string"?s.artist:s.artist?.name||"Artiste inconnu",h=s=>{const l=typeof s=="number"?s:0;return l===0&&typeof s=="string"?s:`${Math.floor(l/60)}:${(l%60).toString().padStart(2,"0")}`};return e.jsxs("div",{className:"h-full flex flex-col space-y-6 animate-fadeIn pb-24",children:[e.jsxs("div",{className:"sticky top-0 z-20 bg-kodo-void/80 backdrop-blur-xl border-b border-white/5 py-4 -mx-4 px-4 md:-mx-8 md:px-8 flex flex-col md:flex-row gap-4 justify-between items-center transition-all",children:[e.jsxs("div",{className:"flex items-center gap-4 w-full md:w-auto",children:[e.jsx("h1",{className:"text-2xl font-display font-bold text-white hidden md:block",children:"Bibliothèque"}),e.jsxs("div",{className:"relative flex-1 md:w-80",children:[e.jsx(De,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 tex