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

2 lines
11 KiB
JavaScript
Raw Normal View History

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 transla