veza/apps/web/dist_verification/assets/DashboardPage-DBeOkkV3.js

1 line
11 KiB
JavaScript

import{a as h,j as e}from"./vendor-react-BHG7lGYR.js";import{a as y,l as N,C as u,b as f,c as b,d as x,e as g,B as k,u as _,f as p}from"./index-BWcMVITa.js";import{u as M}from"./vendor-tanstack-BzWBL1hV.js";import{aa as v,ab as C,J as D,O as S,F as z,ac as A,ad as P,ae as L,af as E,g as F,ag as T,ah as $}from"./vendor-icons-DaGlTw4_.js";import{g as q,h as B,d as w,f as U}from"./vendor-utils-CgOSfOkx.js";import{u as H}from"./vendor-router-D-s5vIeO.js";import"./vendor-IYr-MHu4.js";async function I(s){try{const t={};s?.activityLimit,s?.libraryLimit,s?.statsPeriod;const r=(await y.get("/dashboard",{params:t})).data;if(!r)throw new Error("Invalid dashboard response format");return{stats:r.stats||{tracks_played:0,messages_sent:0,favorites:0,active_friends:0,period:s?.statsPeriod||"30d"},recent_activity:r.recent_activity||[],library_preview:r.library_preview}}catch(t){return N.error("Failed to fetch dashboard data from aggregated endpoint",{error:t instanceof Error?t.message:String(t),stack:t instanceof Error?t.stack:void 0,options:s}),{stats:{tracks_played:0,messages_sent:0,favorites:0,active_friends:0,period:s?.statsPeriod||"30d"},recent_activity:[],library_preview:void 0}}}const j={all:["dashboard"],data:s=>[...j.all,"data",s]};function J(s){const t=M({queryKey:j.data(s),queryFn:()=>I(s),staleTime:3e4,gcTime:12e4,retry:1,retryDelay:1e3}),o=t.data?.stats||null,r=t.data?.recent_activity||[],i=t.data?.library_preview||null;return{stats:o,recentActivity:r,libraryPreview:i,isLoading:t.isLoading,error:t.error instanceof Error?t.error:t.error?new Error(String(t.error)):null,refetch:async()=>{await t.refetch()}}}const K=s=>{const t=[];for(let o=s;o>=0;o--){const r=q(new Date,o),i=50+Math.random()*50,d=(s-o)*2;t.push({date:r.toISOString(),label:B(r,"d MMM",{locale:w}),value:Math.min(100,Math.max(10,Math.floor(i+d)))})}return t};function R(){const[s,t]=h.useState(7),[o,r]=h.useState(null),i=h.useMemo(()=>K(s),[s]),d=Math.max(...i.map(n=>n.value));return e.jsxs(u,{variant:"glass",className:"h-full flex flex-col overflow-hidden",children:[e.jsxs(f,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs(b,{className:"flex items-center gap-2 text-base font-medium",children:[e.jsx(v,{className:"w-4 h-4 text-kodo-cyan"}),"Activité d'écoute"]}),e.jsx("p",{className:"text-xs text-kodo-text-dim",children:"+14.5% par rapport à la période précédente"})]}),e.jsxs("div",{className:"flex bg-kodo-ink/50 p-1 rounded-lg border border-white/5",children:[e.jsx("button",{onClick:()=>t(7),className:x("px-3 py-1 text-xs font-medium rounded-md transition-all",s===7?"bg-kodo-cyan/20 text-kodo-cyan shadow-sm":"text-kodo-text-dim hover:text-white"),children:"7J"}),e.jsx("button",{onClick:()=>t(30),className:x("px-3 py-1 text-xs font-medium rounded-md transition-all",s===30?"bg-kodo-cyan/20 text-kodo-cyan shadow-sm":"text-kodo-text-dim hover:text-white"),children:"30J"})]})]}),e.jsxs(g,{className:"flex-1 flex items-end justify-between gap-2 pt-8 pb-4 px-6 relative",children:[e.jsxs("div",{className:"absolute inset-0 px-6 pt-8 pb-10 flex flex-col justify-between pointer-events-none opacity-20",children:[e.jsx("div",{className:"border-t border-dashed border-kodo-steel w-full h-0"}),e.jsx("div",{className:"border-t border-dashed border-kodo-steel w-full h-0"}),e.jsx("div",{className:"border-t border-dashed border-kodo-steel w-full h-0"})]}),i.map((n,c)=>{const a=n.value/d*100,l=o===c;return e.jsxs("div",{className:"relative flex-1 h-full flex items-end group",onMouseEnter:()=>r(c),onMouseLeave:()=>r(null),children:[e.jsx("div",{className:x("w-full rounded-t-sm transition-all duration-300 relative z-10",l?"bg-kodo-cyan opacity-100":"bg-kodo-cyan/30 opacity-70","animate-slideUp"),style:{height:`${a}%`,animationDelay:`${c*50}ms`},children:l&&e.jsx("div",{className:"absolute inset-0 bg-kodo-cyan blur-md opacity-50"})}),e.jsxs("div",{className:x("absolute bottom-[110%] left-1/2 -translate-x-1/2 z-20 transition-all duration-200 pointer-events-none",l?"opacity-100 translate-y-0":"opacity-0 translate-y-2"),children:[e.jsxs("div",{className:"bg-kodo-ink border border-kodo-steel/50 px-3 py-2 rounded-lg shadow-xl whitespace-nowrap",children:[e.jsxs("div",{className:"text-xs font-bold text-white mb-0.5",children:[n.value," écoutes"]}),e.jsx("div",{className:"text-[10px] text-kodo-text-dim font-mono",children:n.label})]}),e.jsx("div",{className:"w-2 h-2 bg-kodo-ink border-b border-r border-kodo-steel/50 rotate-45 absolute -bottom-1 left-1/2 -translate-x-1/2"})]}),(s===7||c%5===0)&&e.jsx("div",{className:"absolute top-full mt-2 left-1/2 -translate-x-1/2 text-[10px] text-kodo-text-dim font-mono whitespace-nowrap",children:n.label.split(" ")[0]})]},c)})]})]})}const O={"bottom-right":"bottom-6 right-6","bottom-left":"bottom-6 left-6","top-right":"top-6 right-6","top-left":"top-6 left-6"},Q={sm:"h-12 w-12 text-base",md:"h-14 w-14 text-lg",lg:"h-16 w-16 text-xl"};function V({position:s="bottom-right",size:t="lg",showLabel:o=!1,label:r,className:i,containerClassName:d,children:n,...c}){return e.jsxs("div",{className:x("fixed z-50 flex items-center gap-4",O[s],d),children:[o&&r&&e.jsx("span",{className:"text-sm font-semibold text-white bg-kodo-ink/90 backdrop-blur-md px-4 py-2 rounded-lg border border-white/10 shadow-lg whitespace-nowrap",children:r}),e.jsx(k,{variant:"default",className:x("rounded-full aspect-square p-0","shadow-[0_0_30px_rgba(102,252,241,0.5)] hover:shadow-[0_0_40px_rgba(102,252,241,0.7)]","transition-all duration-300","active:opacity-80",Q[t],i),...c,children:n})]})}function te(){const{stats:s,recentActivity:t,isLoading:o}=J(),r=H(),{data:i}=_(),d=a=>a>=1e6?`${(a/1e6).toFixed(1)}M`:a>=1e3?`${(a/1e3).toFixed(1)}K`:a.toString(),n=[{title:"Pistes écoutées",value:s?d(s.tracks_played):"0",change:s?.tracks_played_change||"+0%",icon:e.jsx(C,{className:"w-4 h-4"}),color:"cyan"},{title:"Messages",value:s?d(s.messages_sent):"0",change:s?.messages_sent_change||"+0%",icon:e.jsx(D,{className:"w-4 h-4"}),color:"lime"},{title:"Favoris",value:s?d(s.favorites):"0",change:s?.favorites_change||"+0%",icon:e.jsx(S,{className:"w-4 h-4"}),color:"magenta"},{title:"Amis",value:s?d(s.active_friends):"0",change:s?.active_friends_change||"+0%",icon:e.jsx(z,{className:"w-4 h-4"}),color:"gold"}],c=h.useMemo(()=>{const a={};return t.reduce((l,m)=>{if(!a[m.timestamp])try{a[m.timestamp]=U(new Date(m.timestamp),{addSuffix:!0,locale:w})}catch{a[m.timestamp]="Récemment"}return l[m.timestamp]=a[m.timestamp],l},{})},[t]);return e.jsxs("div",{className:"space-y-6 pb-20 animate-fadeIn max-w-full overflow-hidden",children:[e.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4 py-2",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-gradient-to-br from-kodo-cyan to-kodo-magenta p-[1px] shadow-lg shadow-kodo-cyan/20",children:e.jsx("div",{className:"w-full h-full rounded-2xl bg-kodo-void flex items-center justify-center",children:e.jsx(A,{className:"w-6 h-6 text-kodo-cyan"})})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-display font-bold text-kodo-text-main",children:["Bonjour, ",i?.username]}),e.jsxs("p",{className:"text-sm text-kodo-text-dim flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-kodo-lime animate-pulse"}),"Système opérationnel"]})]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(p,{variant:"outline",size:"sm",onClick:()=>r("/library"),className:"hidden sm:flex border-kodo-steel/30 hover:bg-white/5",icon:e.jsx(P,{className:"w-4 h-4"}),children:"Bibliothèque"}),e.jsx(p,{variant:"primary",size:"sm",onClick:()=>r("/library?action=upload"),className:"shadow-glow-cyan",icon:e.jsx(L,{className:"w-4 h-4"}),children:"Upload"})]})]}),e.jsx("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:n.map((a,l)=>e.jsx("div",{className:"group",children:e.jsxs("div",{className:"bg-kodo-graphite/40 border border-white/5 rounded-xl p-4 hover:bg-white/5 hover:border-kodo-cyan/30 transition-all duration-300 relative overflow-hidden",children:[e.jsx("div",{className:`absolute top-0 right-0 p-3 opacity-20 group-hover:opacity-100 group-hover:scale-110 transition-all text-kodo-${a.color}`,children:a.icon}),e.jsx("div",{className:"text-xs font-mono text-kodo-text-dim uppercase tracking-wider mb-1",children:a.title}),e.jsx("div",{className:"text-2xl font-display font-bold text-kodo-text-main mb-1",children:a.value}),e.jsxs("div",{className:`text-xs font-medium text-kodo-${a.color==="red"?"danger":"success"} flex items-center gap-1`,children:[e.jsx(E,{className:"w-3 h-3"}),a.change]})]})},l))}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-12 gap-6 h-auto xl:h-[500px]",children:[e.jsx("div",{className:"xl:col-span-8 h-[300px] xl:h-full",children:e.jsx(R,{})}),e.jsx("div",{className:"xl:col-span-4 h-full flex flex-col gap-4",children:e.jsxs(u,{variant:"glass",className:"flex-1 flex flex-col overflow-hidden border-kodo-steel/20",children:[e.jsx(f,{className:"py-4 px-5 border-b border-white/5 bg-white/2 backdrop-blur-sm sticky top-0 z-10",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(b,{className:"text-sm font-bold flex items-center gap-2",children:[e.jsx(F,{className:"w-4 h-4 text-kodo-cyan"}),"Flux Récent"]}),e.jsx(p,{variant:"ghost",size:"sm",className:"h-6 text-[10px] uppercase",children:"Tout voir"})]})}),e.jsx(g,{className:"flex-1 overflow-y-auto p-0 custom-scrollbar",children:e.jsx("div",{className:"flex flex-col",children:o?Array(5).fill(0).map((a,l)=>e.jsxs("div",{className:"p-4 border-b border-white/5 flex gap-3 animate-pulse",children:[e.jsx("div",{className:"w-8 h-8 bg-white/5 rounded-full"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-3 bg-white/5 rounded w-3/4"}),e.jsx("div",{className:"h-2 bg-white/5 rounded w-1/2"})]})]},l)):t.length>0?t.map((a,l)=>e.jsxs("div",{className:"group flex items-start gap-3 p-4 border-b border-white/5 hover:bg-white/5 transition-colors cursor-pointer",children:[e.jsx("div",{className:"mt-1 min-w-[32px] w-8 h-8 rounded-full bg-kodo-steel/10 flex items-center justify-center border border-white/5 group-hover:border-kodo-cyan/50 group-hover:text-kodo-cyan transition-all",children:e.jsx(T,{className:"w-4 h-4 text-kodo-text-dim"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between mb-0.5",children:[e.jsx("span",{className:"text-sm font-medium text-kodo-text-main truncate pr-2",children:a.title}),e.jsx("span",{className:"text-[10px] text-kodo-text-dim whitespace-nowrap",children:c[a.timestamp]})]}),e.jsx("p",{className:"text-xs text-kodo-text-dim line-clamp-2",children:a.description||"Activité détectée sur le réseau Veza."})]})]},l)):e.jsxs("div",{className:"h-full flex flex-col items-center justify-center p-8 text-center opacity-60",children:[e.jsx(v,{className:"w-8 h-8 text-kodo-text-dim mb-2"}),e.jsx("p",{className:"text-sm",children:"Aucune activité récente"})]})})})]})})]}),e.jsx(V,{position:"bottom-right",size:"lg",showLabel:!1,onClick:()=>r("/library?action=upload"),className:"md:hidden shadow-glow-cyan",children:e.jsx($,{className:"w-6 h-6"})})]})}export{te as DashboardPage};