PageSourceSearch

https://clarity-digital.com/assets/Categories-CxrDTre1.js

js clarity-digital.com collected 2026-10-08 12:39:16 UTC 6,324 bytes, 1 lines download raw bytes

1import{j as e}from"./vendor-ui-D4uQKjpW.js";import{R as h,h as Y}from"./vendor-react-gyhv66PW.js";import{C as v,i as b,j as N,d as p,g as C,f as F,B as M,e as I,u as L}from"./index-Dy2BQWz9.js";import{P as G}from"./PageHeader-C2g6BN4f.js";import{p as w}from"./parseISO-CxP-o0Lo.js";import{R as T,B as H,b as S,X as P,Y as z,T as R,d as V,i as X,j as W}from"./vendor-charts-C9hs4La4.js";import{S as $}from"./ScrollableContainer-BsVHhAWH.js";import{a as q}from"./categories-CRCrk6a9.js";import{P as J}from"./PeriodSelector-yvCV_PXM.js";import{P as Q}from"./plus-O83cftAV.js";import{s as U}from"./startOfMonth-BHWehlss.js";import{e as Z}from"./endOfMonth-0iukLaqU.js";import{i as _}from"./isWithinInterval-BAR04CMu.js";import"./vendor-firebase-CRd2al95.js";import"./house-D3Xly9VQ.js";import"./sparkles-DhUJTdY4.js";import"./shield-CaJBvafj.js";import"./select-sBcVxHQC.js";import"./bottom-sheet-DbJo_xgQ.js";function ee({category:o}){return e.jsxs(v,{children:[e.jsxs(b,{className:"pb-3",children:[e.jsx(N,{className:"text-base",children:o.label}),e.jsxs("div",{className:"grid grid-cols-3 gap-2 mt-3",children:[e.jsxs("div",{className:"bg-muted/50 rounded p-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total"}),e.jsx("p",{className:"text-sm font-semibold",children:p(Math.abs(o.total))})]}),e.jsxs("div",{className:"bg-muted/50 rounded p-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Monthly Avg"}),e.jsx("p",{className:"text-sm font-semibold text-foreground",children:p(Math.abs(o.average))})]}),e.jsxs("div",{className:"bg-muted/50 rounded p-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Txns"}),e.jsx("p",{className:"text-sm font-semibold",children:o.count})]})]})]}),e.jsx(C,{children:e.jsx("div",{className:"h-48 overflow-y-auto space-y-2",children:o.transactions.map(s=>e.jsxs("div",{className:"text-xs border-b pb-2 flex justify-between",children:[e.jsxs("div",{className:"flex-1 min-w-0 pr-2",children:[e.jsx("span",{className:"font-medium block truncate",children:s.description}),e.jsx("span",{className:"text-muted-foreground",children:s.date?F(w(s.date),"MMM d"):"No date"})]}),e.jsx("span",{className:s.amount<0?"text-destructive":"text-[#a3cc2b]",children:p(s.amount)})]},s.id))})})]})}function se({data:o}){const[s,x]=h.useState("expense"),g=h.useMemo(()=>o.map(n=>({name:n.label,total:Math.abs(n.total),average:Math.abs(n.average),expenseAverage:Math.abs(n.expenseAverage)})),[o]);return e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs(v,{children:[e.jsx(b,{className:"pb-2",children:e.jsx(N,{className:"text-base",children:"Total by Category"})}),e.jsx(C,{children:e.jsx(T,{width:"100%",height:300,children:e.jsxs(H,{data:g,children:[e.jsx(S,{strokeDasharray:"3 3"}),e.jsx(P,{dataKey:"name",angle:-45,textAnchor:"end",height:80,tick:{fontSize:12}}),e.jsx(z,{tick:{fontSize:12}}),e.jsx(R,{formatter:n=>p(n)}),e.jsx(V,{dataKey:"total",fill:"hsl(var(--chart-1))"})]})})})]}),e.jsxs(v,{children:[e.jsxs(b,{className:"pb-2 flex flex-row items-center justify-between space-y-0",children:[e.jsx(N,{className:"text-base",children:s==="expense"?"Average Expense Value":"Net Average (All Tx)"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(M,{variant:s==="expense"?"default":"outline",size:"sm",className:"h-7 text-[10px] px-2 min-h-0",onClick:()=>x("expense"),children:"Expense"}),e.jsx(M,{variant:s==="net"?"default":"outline",size:"sm",className:"h-7 text-[10px] px-2 min-h-0",onClick:()=>x("net"),children:"Net"})]})]}),e.jsx(C,{children:e.jsx(T,{width:"100%",height:300,children:e.jsxs(X,{data:g,children:[e.jsx(S,{strokeDasharray:"3 3"}),e.jsx(P,{dataKey:"name",angle:-45,textAnchor:"end",height:80,tick:{fontSize:12}}),e.jsx(z,{tick:{fontSize:12}}),e.jsx(R,{formatter:n=>p(n)}),e.jsx(W,{type:"monotone",dataKey:s==="expense"?"expenseAverage":"average",stroke:"hsl(var(--chart-2))",dot:{fill:"hsl(var(--chart-2))"}})]})})})]})]})}function Ne(){console.log("CategoriesPage component rendered");const{user:o}=I(),s=L(),x=(s==null?void 0:s.customCategories)||[],g=(s==null?void 0:s.isLoading)||!1,n=(s==null?void 0:s.isRefreshing)||!1,B=s==null?void 0:s.refreshAll;s==null||s.getCategoryBreakdown;const c=(s==null?void 0:s.transactions)||[],E=Y(),[i,K]=h.useState("all"),y=h.useMemo(()=>
1Object.fromEntries(x.map(l=>[l.key,l])),[x]),A=h.useMemo(()=>{const l=q(y);let D=c,d=1;if(i!=="all"){let a,t;if(i==="ytd")a=new Date(new Date().getFullYear(),0,1),t=new Date,d=new Date().getMonth()+1;else if(/^\d{4}$/.test(i))a=new Date(parseInt(i),0,1),t=new Date(parseInt(i),11,31),d=12;else{const r=w(i+"-01");a=U(r),t=Z(r),d=1}D=c.filter(r=>{const u=w(r.date);return _(u,{start:a,end:t})})}else if(c.length>0){const a=c.map(t=>new Date(t.date).getTime()).filter(t=>!isNaN(t));if(a.length>0){const t=new Date(Math.min(...a)),r=new Date(Math.max(...a));d=(r.getFullYear()-t.getFullYear())*12+(r.getMonth()-t.getMonth())+1}}d=Math.max(1,d);const m={};return D.forEach(a=>{if(a.category==="transfer")return;const t=a.category||"uncategorized";m[t]||(m[t]={sum:0,txs:[],months:new Set}),m[t].sum+=a.amount||0,m[t].txs.push(a),a.date&&m[t].months.add(a.date.substring(0,7))}),Object.entries(m).map(([a,t])=>{const r=l[a],u=t.txs.sort((f,O)=>new Date(O.date).getTime()-new Date(f.date).getTime()),j=Math.abs(t.sum),k=j/d;return{key:a,label:(r==null?void 0:r.label)||a,total:j,count:t.txs.length,expenseTotal:j,expenseCount:t.txs.filter(f=>f.amount<0).length,average:k,expenseAverage:k,transactions:u.slice(0,50)}}).sort((a,t)=>t.total-a.total)},[c,i,y]);return g?e.jsx("div",{className:"flex items-center justify-center min-h-screen",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-slate-800 rounded-full animate-spin"})}):e.jsxs($,{onRefresh:B,isRefreshing:n,children:[e.jsx(G,{title:"Categories",description:"View spending by category",action:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(M,{variant:"outline",size:"sm",onClick:()=>E("/settings"),className:"min-h-[44px]",children:[e.jsx(Q,{className:"w-4 h-4 mr-2"})," Add Custom"]}),e.jsx(J,{transactions:c,value:i,onChange:K})]})}),e.jsx(se,{data:A}),e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6 mt-8",children:A.map(l=>e.jsx(ee,{category:l},l.key))})]})}export{Ne as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.