PageSourceSearch

https://analyticsindiamag.com/assets/ManageInfographics-BtK64iAs.js

js analyticsindiamag.com collected 2026-09-24 08:27:48 UTC 10,740 bytes, 1 lines download raw bytes

1import{r,a as le,s as n,j as e,B as f,q as ne,I as F,F as N,X as R,a3 as oe,a9 as ce}from"./index-KSWbwNeY.js";import{C as O}from"./card-CwL_ed79.js";import{L as _}from"./label-ndOKmXJw.js";import{T as de}from"./textarea-BXv-lbww.js";import{A as pe}from"./AdminNav-DsaLvjFx.js";import{D as me,a as ue,b as he,c as fe}from"./dialog-Bpfij23O.js";import{P as xe,a as ge,b as C,c as je,e as ve,d as Ne,f as be}from"./pagination-BF8fs3MF.js";import{U as ye}from"./upload-CstIFHrJ.js";import{P as we}from"./pen-BKGmuNWh.js";import{T as Pe}from"./trash-2-CwcwS_bf.js";import{D as _e}from"./download-BtORIOsS.js";import"./index-DsYLezIw.js";import"./user-cog-DvqSS7bY.js";import"./book-open-DS7Nmuzn.js";import"./receipt-DgWJf9Ou.js";import"./chevron-down-D7IdZFzc.js";import"./index-BpbyRUKB.js";import"./chevron-left-C0OR5oyH.js";import"./ellipsis-aIaacu3o.js";const Ve=()=>{const[z,H]=r.useState([]),[Q,I]=r.useState(!0),[D,V]=r.useState(""),[x,W]=r.useState(""),[o,b]=r.useState(1),[S,K]=r.useState(0),[E,U]=r.useState(!1),[y,T]=r.useState(null),[s,w]=r.useState(null),[c,P]=r.useState({title:"",alt_text:"",caption:""}),k=24,{toast:i}=le();r.useEffect(()=>{const t=setTimeout(()=>{W(D),b(1)},300);return()=>clearTimeout(t)},[D]),r.useEffect(()=>{m()},[o,x]);const m=async()=>{I(!0);const t=(o-1)*k;let a=n.from("infographics").select("*",{count:"exact"}).order("created_at",{ascending:!1});x&&(a=a.ilike("title",`%${x}%`)),a=a.range(t,t+k-1);const{data:d,count:p,error:l}=await a;l&&i({variant:"destructive",title:"Error",description:l.message}),H(d||[]),K(p||0),I(!1)},X=async t=>{var d;const a=(d=t.target.files)==null?void 0:d[0];if(a){U(!0);try{const p=a.type==="application/pdf";let l=a,u=a.type,j=a.name.split(".").pop()||"bin",h="";if(p)j="pdf",u="application/pdf",h=`PDF uploaded (${(a.size/1024).toFixed(0)} KB)`;else{const{optimizeImage:te,formatFileSize:M,calculateSavings:ae}=await ce(async()=>{const{optimizeImage:se,formatFileSize:ie,calculateSavings:re}=await import("./imageOptimizer-DU1AwbgF.js");return{optimizeImage:se,formatFileSize:ie,calculateSavings:re}},[]),v=await te(a,{maxWidth:2e3,maxHeight:4e3,quality:.9,format:"webp"});l=v.blob,u="image/webp",j="webp",h=`${ae(v.originalSize,v.optimizedSize)} size reduction (${M(v.originalSize)} → ${M(v.optimizedSize)})`}const q=`infographics/${Date.now()}-${Math.random().toString(36).substring(7)}.${j}`,{error:B}=await n.storage.from("imported-images").upload(q,l,{contentType:u,cacheControl:"public, max-age=31536000, immutable"});if(B)throw B;const{data:{publicUrl:Z}}=n.storage.from("imported-images").getPublicUrl(q),ee=a.name.replace(/\.[^/.]+$/,""),{error:L}=await n.from("infographics").insert({title:ee,image_url:Z});if(L)throw L;i({title:"Uploaded",description:h}),m()}catch(p){i({variant:"destructive",title:"Upload failed",description:p.message})}finally{U(!1)}}},$=async(t,a)=>{var p;const d=(p=a.target.files)==null?void 0:p[0];if(!d||d.type!=="application/pdf"){i({variant:"destructive",title:"Invalid file",description:"Please select a PDF file."});return}T(t);try{const l=`infographics/pdfs/${Date.now()}-${Math.random().toString(36).substring(7)}.pdf`,{error:u}=await n.storage.from("imported-images").upload(l,d,{contentType:"application/pdf",cacheControl:"public, max-age=604800"});if(u)throw u;const{data:{publicUrl:j}}=n.storage.from("imported-images").getPublicUrl(l),{error:h}=await n.from("infographics").update({pdf_url:j}).eq("id",t);if(h)throw h;i({title:"PDF attached"}),m()}catch(l){i({variant:"destructive",title:"PDF upload failed",description:l.message})}finally{T(null)}},A=async t=>{const{error:a}=await n.from("infographics").update({pdf_url:null}).eq("id",t);a?i({variant:"destructive",title:"Error",description:a.message}):(i({title:"PDF removed"}),m())},G=async t=>{if(!confirm("Delete this infographic?"))return;const{error:a}=await n.from("infographics").delete().eq("id",t);a?i({variant:"destructive",title:"Error",description:a.message}):(i({title:"Deleted"}),m())},J=t=>{w(t),P({title:t.title,alt_text:t.alt_text||"",caption:t.caption||""})},Y=async()=>{if(!s)return;const{error:t}=await n.from("infographics").update({title:c.title,alt_text:c.alt_text||null,caption:c.caption||null}).eq("id",s.id);t?i({variant:"destructive",title:"Error",description:t.message}):(i({title:"Updated"}),w(null),m())},g=Math.ceil(S/k);return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(pe,{}),e.jsxs("main",{className:"md:ml-52 p-8",children:[e.jsxs("div",{className:"max-w-7xl mx-auto",children:[e.jsxs("div",{className:"flex justify-between items-center mb-8",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"font-serif text-4xl font-bold",children:"Infographic Library"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:[S," ",S===1?"infographic":"infographics"]})]}),e.jsxs("div",{children:[e.jsx("input",{type:"file",id:"infographic-upload",className:"hidden",accept:"image/*,application/pdf",onChange:X,disabled:E}),e.jsxs(f,{onClick:()=>{var t;return(t=document.getElementById("infographic-upload"))==null?void 0:t.click()},disabled:E,children:[e.jsx(ye,{className:"mr-2 h-4 w-4"}),E?"Uploading...":"Upload Infographic"]})]})]}),e.jsxs("div",{className:"mb-6 relative",children:[e.jsx(ne,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(F,{placeholder:"Search by title...",value:D,onChange:t=>V(t.target.value),className:"pl-10"})]}
1),Q?e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4",children:Array.from({length:12}).map((t,a)=>e.jsxs(O,{className:"overflow-hidden animate-pulse",children:[e.jsx("div",{className:"aspect-[3/4] bg-muted"}),e.jsx("div",{className:"p-3",children:e.jsx("div",{className:"h-4 bg-muted rounded w-3/4"})})]},a))}):z.length===0?e.jsx("div",{className:"text-center py-12 text-muted-foreground",children:x?`No results for "${x}"`:"No infographics yet. Upload your first one!"}):e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-6 gap-4",children:z.map(t=>e.jsxs(O,{className:"overflow-hidden group",children:[e.jsxs("div",{className:"aspect-[3/4] relative bg-muted",children:[t.image_url.endsWith(".pdf")?e.jsxs("div",{className:"w-full h-full flex flex-col items-center justify-center bg-muted/50 gap-2",children:[e.jsx(N,{className:"h-12 w-12 text-primary/60"}),e.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:"PDF"})]}):e.jsx("img",{src:t.image_url,alt:t.alt_text||t.title,className:"w-full h-full object-cover",loading:"lazy"}),t.pdf_url&&e.jsx("div",{className:"absolute top-2 right-2 bg-primary/90 text-primary-foreground rounded-full p-1.5",children:e.jsx(N,{className:"h-3.5 w-3.5"})}),e.jsxs("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/30 transition-colors flex items-center justify-center gap-2 opacity-0 group-hover:opacity-100",children:[e.jsx(f,{size:"icon",variant:"secondary",className:"h-8 w-8",onClick:()=>J(t),children:e.jsx(we,{className:"h-4 w-4"})}),e.jsx(f,{size:"icon",variant:"destructive",className:"h-8 w-8",onClick:()=>G(t.id),children:e.jsx(Pe,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"p-3 space-y-2",children:[e.jsx("p",{className:"font-medium text-sm truncate",children:t.title}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:new Date(t.created_at).toLocaleDateString()}),t.pdf_url?e.jsxs("div",{className:"flex gap-1",children:[e.jsxs("a",{href:t.pdf_url,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-primary hover:underline flex items-center gap-0.5",children:[e.jsx(_e,{className:"h-3 w-3"})," PDF"]}),e.jsx("button",{onClick:()=>A(t.id),className:"text-xs text-destructive hover:underline ml-1",children:e.jsx(R,{className:"h-3 w-3"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"file",id:`pdf-upload-${t.id}`,className:"hidden",accept:"application/pdf",onChange:a=>$(t.id,a)}),e.jsxs("button",{onClick:()=>{var a;return(a=document.getElementById(`pdf-upload-${t.id}`))==null?void 0:a.click()},disabled:y===t.id,className:"text-xs text-muted-foreground hover:text-primary transition-colors flex items-center gap-0.5",children:[e.jsx(N,{className:"h-3 w-3"}),y===t.id?"...":"+ PDF"]})]})]})]})]},t.id))}),g>1&&e.jsx("div",{className:"mt-8",children:e.jsx(xe,{children:e.jsxs(ge,{children:[e.jsx(C,{children:e.jsx(je,{onClick:()=>b(t=>Math.max(1,t-1)),className:o===1?"pointer-events-none opacity-50":"cursor-pointer"})}),Array.from({length:g},(t,a)=>a+1).map(t=>t===1||t===g||t>=o-1&&t<=o+1?e.jsx(C,{children:e.jsx(ve,{onClick:()=>b(t),isActive:o===t,className:"cursor-pointer",children:t})},t):t===o-2||t===o+2?e.jsx(C,{children:e.jsx(Ne,{})},t):null),e.jsx(C,{children:e.jsx(be,{onClick:()=>b(t=>Math.min(g,t+1)),className:o===g?"pointer-events-none opacity-50":"cursor-pointer"})})]})})})]}),e.jsx(me,{open:!!s,onOpenChange:()=>w(null),children:e.jsxs(ue,{children:[e.jsx(he,{children:e.jsx(fe,{children:"Edit Infographic"})}),s&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("img",{src:s.image_url,alt:"",className:"w-full max-h-48 object-contain rounded bg-muted"}),e.jsxs("div",{children:[e.jsx(_,{children:"Title"}),e.jsx(F,{value:c.title,onChange:t=>P({...c,title:t.target.value})})]}),e.jsxs("div",{children:[e.jsx(_,{children:"Alt Text"}),e.jsx(F,{value:c.alt_text,onChange:t=>P({...c,alt_text:t.target.value}),placeholder:"Describe the infographic for accessibility"})]}),e.jsxs("div",{children:[e.jsx(_,{children:"Caption"}),e.jsx(de,{value:c.caption,onChange:t=>P({...c,caption:t.target.value}),placeholder:"Optional caption displayed below",rows:2})]}),e.jsxs("div",{children:[e.jsx(_,{children:"PDF Attachment"}),s.pdf_url?e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[e.jsxs("a",{href:s.pdf_url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline flex items-center gap-1",children:[e.jsx(N,{className:"h-4 w-4"})," View PDF"]}),e.jsxs(f,{size:"sm",variant:"ghost",className:"text-destructive h-7",onClick:()=>{A(s.id),w({...s,pdf_url:null})},children:[e.jsx(R,{className:"h-3 w-3 mr-1"})," Remove"]})]}):e.jsxs("div",{className:"mt-1",children:[e.jsx("input",{type:"file",id:"pdf-upload-edit",className:"hidden",accept:"application/pdf",onChange:t=>$(s.id,t)}),e.jsxs(f,{size:"sm",variant:"outline",onClick:()=>{var t;return(t=document.getElementById("pdf-upload-edit"))==null?void 0:t.click()},disabled:y===s.id,children:[e.jsx(N,{className:"mr-2 h-4 w-4"}),y===s.id?"Uploading...":"Attach PDF"]})]})]}),e.jsxs(f,{onClick:Y,className:"w-full",children:[e.jsx(oe,{className:"mr-2 h-4 w-4"}),"Save Changes"]})]})]})})]})]})};export{Ve 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.