veza/.build/incus/web/js/LibraryPage-JATWW-qD.js
senke 1ed6e7f07b state-ownership: delete unused optimisticStoreUpdates.ts file
- Deleted apps/web/src/utils/optimisticStoreUpdates.ts (unused file)
- File was unused - no imports found in codebase
- Mutations already use React Query's onMutate pattern
- No TypeScript errors after deletion
- Actions 4.4.1.2 and 4.4.1.3 complete
2026-01-15 19:26:53 +01:00

2 lines
11 KiB
JavaScript

import{t as fe,a3 as we,r as t,a4 as be,j as e,E as V,B as l,aR as ke,X as ve,aS as Ne,c as S,aT as Ce,aa as Se,U as X,aL as y,aM as f,a8 as Te,G as De,aU as Me,aV as W,aW as Y,aX as Z,aY as Pe,aZ as H,a_ as ze,a$ as T,a as Ee,a9 as J,M as Ae,b0 as Ue,b1 as qe,b2 as Fe,aK as _e,b3 as Be,b4 as Re,b5 as Ie,l as F,aD as _}from"./chunk-Cad8leGS.js";import{a as Le}from"./index-D792PhRw.js";import{u as Ke,a as Qe,C as ee}from"./chunk-BNmrw_On.js";import{U as $e,b as Oe,a as Ge,g as Ve}from"./chunk-B7sOPOlf.js";import{P as Xe}from"./chunk-C2j-MMB3.js";import"./chunk-wkfC2Tom.js";import"./chunk-BoPufJSi.js";import"./chunk-VMUEamc6.js";import"./chunk-Df4po8fP.js";import"./chunk-B4NZlYwU.js";import"./chunk-BlDLB1ZZ.js";function is(){const w=fe(),D=we(),[p,B]=t.useState(1),[M]=t.useState(50),[se,R]=t.useState(!1),[ae,b]=t.useState(!1),[P,I]=t.useState("grid"),[k,re]=t.useState(""),x=Le(k,300),[z,te]=t.useState(""),[E,oe]=t.useState(""),[d,ie]=t.useState("created_at"),[u,L]=t.useState("desc"),[o,v]=t.useState(new Set),[c,A]=t.useState(!1),[K,i]=t.useState(null),[Q,g]=t.useState(0),n=t.useRef(null),j={page:p,limit:M,sortBy:d,sortOrder:u};z&&(j.genre=z),E&&(j.format=E),x.trim()&&(j.search=x.trim());const{data:m,isLoading:ne,isError:le,error:ce}=be({queryKey:["tracks","library",j,x],queryFn:()=>Ve(p,M,j)}),{data:de}=Ke(),me=Qe(),U=m?.tracks||[];t.useEffect(()=>{x.trim()&&p!==1&&B(1)},[x,p]);const ue=Array.from(new Set(m?.tracks.map(s=>s.genre).filter(s=>!!s)||[])).sort(),he=Array.from(new Set(m?.tracks.map(s=>s.format).filter(s=>!!s)||[])).sort(),pe=async(s,r)=>{const a=async()=>{await me.mutateAsync({playlistId:s,trackId:r}),D.success("Piste ajoutée à la playlist"),i(null),g(0),n.current=null};n.current=a,i(null);try{await a()}catch(h){F.error("Failed to add track to playlist:",{error:h});const C=_(h);i(new Error(C.message||"Impossible d'ajouter la piste à la playlist"))}},$=()=>{R(!0)},xe=()=>{R(!1),w.invalidateQueries({queryKey:["tracks"]})},N=s=>{v(r=>{const a=new Set(r);return a.has(s)?a.delete(s):a.add(s),a})},ge=async()=>{o.size!==0&&b(!0)},je=async()=>{if(o.size===0)return;const s=Array.from(o),r=async()=>{await Ge(s),D.success(`${s.length} piste(s) supprimée(s)`),v(new Set),A(!1),b(!1),w.invalidateQueries({queryKey:["tracks"]}),i(null),g(0),n.current=null};n.current=r,i(null);try{await r()}catch(a){F.error("Failed to bulk delete tracks:",{error:a});const h=_(a);i(new Error(h.message||"Impossible de supprimer les pistes")),b(!1)}},O=async s=>{if(o.size===0)return;const r=Array.from(o),a=async()=>{await Oe(r,s),D.success(`${r.length} piste(s) mise(s) à jour`),v(new Set),A(!1),w.invalidateQueries({queryKey:["tracks"]}),i(null),g(0),n.current=null};n.current=a,i(null);try{await a()}catch(h){const C=_(h);F.error("Erreur lors de la mise à jour des pistes:",{error:C.message}),i(new Error(C.message))}},ye=async()=>{if(!(!n.current||Q>=3)){g(s=>s+1);try{await n.current()}catch{}}},q=s=>{d===s?L(u==="asc"?"desc":"asc"):(ie(s),L("desc"))},G=s=>{const r=Math.floor(s/60),a=s%60;return`${r}:${a.toString().padStart(2,"0")}`};return e.jsxs("div",{className:"space-y-6 animate-fade-in",children:[K&&e.jsx(V,{error:K,variant:"banner",severity:"error",onRetry:Q<3?ye:void 0,onDismiss:()=>{i(null),g(0),n.current=null}}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold text-white tracking-tight",children:"Bibliothèque"}),e.jsx("p",{className:"text-kodo-secondary text-sm mt-1",children:"Gérez et organisez vos fichiers audio"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[c&&o.size>0&&e.jsxs(e.Fragment,{children:[e.jsxs(l,{variant:"destructive",onClick:ge,size:"sm",children:[e.jsx(ke,{className:"mr-2 h-4 w-4"}),"Supprimer (",o.size,")"]}),e.jsxs(l,{variant:"outline",onClick:()=>O({is_public:!0}),size:"sm",children:["Public (",o.size,")"]}),e.jsxs(l,{variant:"outline",onClick:()=>O({is_public:!1}),size:"sm",children:["Privé (",o.size,")"]})]}),e.jsx(l,{variant:c?"default":"outline",onClick:()=>{A(!c),v(new Set)},size:"sm",children:c?e.jsxs(e.Fragment,{children:[e.jsx(ve,{className:"mr-2 h-4 w-4"}),"Annuler"]}):e.jsxs(e.Fragment,{children:[e.jsx(Ne,{className:"mr-2 h-4 w-4"}),"Sélection"]})}),e.jsxs("div",{className:"flex items-center border border-white/10 rounded-lg overflow-hidden",children:[e.jsx("button",{onClick:()=>I("grid"),className:S("p-2 transition-colors",P==="grid"?"bg-kodo-cyan/20 text-kodo-cyan":"text-kodo-secondary hover:text-white"),children:e.jsx(Ce,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>I("list"),className:S("p-2 transition-colors border-l border-white/10",P==="list"?"bg-kodo-cyan/20 text-kodo-cyan":"text-kodo-secondary hover:text-white"),children:e.jsx(Se,{className:"w-4 h-4"})})]}),e.jsxs(l,{onClick:$,size:"sm",children:[e.jsx(X,{className:"mr-2 h-4 w-4"}),"Upload"]})]})]}),e.jsx(y,{children:e.jsxs(f,{className:"p-4 space-y-4",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Te,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-kodo-secondary"}),e.jsx(De,{placeholder:"Rechercher dans la bibliothèque...",value:k,onChange:s=>re(s.target.value),className:"pl-10"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Me,{className:"h-4 w-4 text-kodo-secondary"}),e.jsx(W,{options:[{value:"",label:"Tous les genres"},...ue.map(s=>({value:s,label:s}))],value:z,onChange:s=>te(Array.isArray(s)?s[0]:s),placeholder:"Tous les genres",className:"w-[180px]"})]}),e.jsx(W,{options:[{value:"",label:"Tous les formats"},...he.map(s=>({value:s,label:s}))],value:E,onChange:s=>oe(Array.isArray(s)?s[0]:s),placeholder:"Tous les formats",className:"w-[180px]"}),e.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[e.jsx("span",{className:"text-sm text-kodo-secondary",children:"Trier par:"}),e.jsxs(Y,{children:[e.jsx(Z,{asChild:!0,children:e.jsxs(l,{variant:"outline",size:"sm",children:[e.jsx(Pe,{className:"mr-2 h-4 w-4"}),d==="created_at"?"Date":d==="title"?"Titre":"Popularité",u==="asc"?" ↑":" ↓"]})}),e.jsxs(H,{children:[e.jsx(ze,{children:"Trier par"}),e.jsxs(T,{onClick:()=>q("created_at"),children:["Date"," ",d==="created_at"&&(u==="asc"?"↑":"↓")]}),e.jsxs(T,{onClick:()=>q("title"),children:["Titre"," ",d==="title"&&(u==="asc"?"↑":"↓")]}),e.jsxs(T,{onClick:()=>q("popularity"),children:["Popularité"," ",d==="popularity"&&(u==="asc"?"↑":"↓")]})]})]})]})]})]})}),ne?e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6",children:Array(8).fill(0).map((s,r)=>e.jsx(y,{className:"animate-pulse",children:e.jsxs(f,{className:"p-6",children:[e.jsx("div",{className:"aspect-square bg-white/5 rounded-xl mb-4"}),e.jsx("div",{className:"h-4 bg-white/5 rounded mb-2"}),e.jsx("div",{className:"h-3 bg-white/5 rounded w-2/3"})]})},r))}):le?e.jsx(V,{error:ce||new Error("Une erreur est survenue lors du chargement des pistes"),variant:"card",severity:"error",context:{action:"fetching tracks",resource:"tracks"},onRetry:()=>{w.invalidateQueries({queryKey:["tracks","library"]})}}):P==="grid"?e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6",children:[U.map(s=>e.jsx(y,{className:S("group cursor-pointer hover:border-kodo-cyan/30 transition-all duration-300 overflow-hidden",o.has(s.id)&&"border-kodo-cyan ring-2 ring-kodo-cyan/20"),onClick:()=>c&&N(s.id),children:e.jsxs(f,{className:"p-0",children:[e.jsxs("div",{className:"relative aspect-square bg-gradient-to-br from-kodo-ink to-kodo-graphite overflow-hidden",children:[c&&e.jsx("div",{className:"absolute top-2 left-2 z-10",children:e.jsx(ee,{checked:o.has(s.id),onCheckedChange:()=>N(s.id),onClick:r=>r.stopPropagation()})}),e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity bg-black/40",children:e.jsx(l,{size:"icon",variant:"premium",className:"rounded-full w-14 h-14 shadow-glow-cyan",onClick:r=>{r.stopPropagation()},children:e.jsx(Ee,{className:"w-6 h-6 ml-1",fill:"currentColor"})})}),e.jsx("div",{className:"absolute bottom-2 right-2 bg-black/60 backdrop-blur-sm px-2 py-1 rounded text-xs text-white font-mono",children:G(s.duration)})]}),e.jsxs("div",{className:"p-4",children:[e.jsx("h3",{className:"font-semibold text-white mb-1 line-clamp-1 group-hover:text-kodo-cyan transition-colors",children:s.title}),e.jsx("p",{className:"text-sm text-kodo-secondary mb-2 line-clamp-1",children:s.artist||"Artiste inconnu"}),e.jsxs("div",{className:"flex items-center justify-between text-xs text-kodo-secondary",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(J,{className:"w-3 h-3"}),new Date(s.created_at).toLocaleDateString("fr-FR")]}),s.genre&&e.jsx("span",{className:"px-2 py-0.5 bg-kodo-cyan/10 text-kodo-cyan rounded-full",children:s.genre})]})]})]})},s.id)),U.length===0&&e.jsx("div",{className:"col-span-full",children:e.jsx(y,{children:e.jsxs(f,{className:"p-12 text-center",children:[e.jsx(Ae,{className:"w-16 h-16 text-kodo-secondary mx-auto mb-4"}),e.jsx("p",{className:"text-lg font-semibold text-white mb-2",children:"Aucun titre trouvé"}),e.jsx("p",{className:"text-kodo-secondary mb-4",children:k?"Essayez avec d'autres termes de recherche":"Commencez par uploader votre premier track"}),!k&&e.jsxs(l,{onClick:$,children:[e.jsx(X,{className:"mr-2 h-4 w-4"}),"Upload Track"]})]})})})]}):e.jsx(y,{children:e.jsx(f,{className:"p-0",children:e.jsx("div",{className:"divide-y divide-white/5",children:U.map((s,r)=>e.jsxs("div",{className:S("flex items-center gap-4 p-4 hover:bg-white/5 transition-colors cursor-pointer group",o.has(s.id)&&"bg-kodo-cyan/10"),onClick:()=>c&&N(s.id),children:[c&&e.jsx(ee,{checked:o.has(s.id),onCheckedChange:()=>N(s.id),onClick:a=>a.stopPropagation()}),e.jsx("div",{className:"w-12 h-12 rounded-lg bg-gradient-to-br from-kodo-ink to-kodo-graphite flex items-center justify-center text-kodo-secondary font-mono text-xs",children:r+1}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"font-semibold text-white group-hover:text-kodo-cyan transition-colors truncate",children:s.title}),e.jsx("p",{className:"text-sm text-kodo-secondary truncate",children:s.artist||"Artiste inconnu"})]}),e.jsxs("div",{className:"hidden md:flex items-center gap-4 text-sm text-kodo-secondary",children:[s.genre&&e.jsx("span",{className:"px-2 py-1 bg-kodo-cyan/10 text-kodo-cyan rounded",children:s.genre}),e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(J,{className:"w-4 h-4"}),G(s.duration)]})]}),e.jsxs(Y,{children:[e.jsx(Z,{asChild:!0,onClick:a=>a.stopPropagation(),children:e.jsx(l,{variant:"ghost",size:"icon",className:"h-8 w-8",children:e.jsx(Ue,{className:"h-4 w-4"})})}),e.jsx(H,{align:"end",children:e.jsxs(qe,{children:[e.jsxs(Fe,{children:[e.jsx(_e,{className:"mr-2 h-4 w-4"}),"Ajouter à une playlist"]}),e.jsx(Be,{children:e.jsx(Re,{children:de?.playlists.map(a=>e.jsx(T,{onClick:()=>pe(a.id,s.id),children:a.title},a.id))})})]})})]})]},s.id))})})}),m?.pagination&&m.pagination.total_pages>1&&e.jsx(Xe,{currentPage:p,totalPages:m.pagination.total_pages,onPageChange:B,totalItems:m.pagination.total,itemsPerPage:M,showItemsInfo:!0}),e.jsx($e,{open:se,onClose:xe}),e.jsx(Ie,{open:ae,onClose:()=>b(!1),onConfirm:je,title:"Supprimer les pistes",description:`Êtes-vous sûr de vouloir supprimer ${o.size} piste(s) ? Cette action est irréversible.`,confirmLabel:"Supprimer",variant:"destructive"})]})}export{is as default};
//# sourceMappingURL=LibraryPage-JATWW-qD.js.map