PageSourceSearch

https://thestreamlinefactory.com/assets/AdminCategories-C0bLG13S.js

js thestreamlinefactory.com collected 2026-09-24 14:20:05 UTC 4,331 bytes, 1 lines download raw bytes

1import{r as a,j as e}from"./react-vendor-C-_weJGF.js";import{b as F,u as q,c as u}from"./query-DA-B5yju.js";import{B as r,s as n,a as o}from"./index-DiEum5Ju.js";import{A as E}from"./AdminLayout-Byts1X3Z.js";import{I as l}from"./input-TSEJWV9X.js";import{F as N}from"./FormField-sjggNfPQ.js";import{C as A}from"./ConfirmDialog-D19QEs3y.js";import{u as k,d as z,X as Q,a2 as B,a5 as I}from"./icons-BZJMmL1V.js";import"./radix-CMA3xQgM.js";import"./supabase-BppBjPB2.js";import"./motion-CfmjrLVm.js";import"./logo-BWhOaj1e.js";function G(){const d=F(),[i,g]=a.useState(""),[x,h]=a.useState(""),[c,m]=a.useState(null),[p,y]=a.useState(""),[f,j]=a.useState(""),{data:b=[]}=q({queryKey:["admin-categories"],queryFn:async()=>{const{data:s}=await n.from("blog_categories").select("*").order("name");return s||[]}}),v=u({mutationFn:async()=>{const{error:s}=await n.from("blog_categories").insert({name:i,slug:x||i.toLowerCase().replace(/\s+/g,"-")});if(s)throw s},onSuccess:()=>{d.invalidateQueries({queryKey:["admin-categories"]}),g(""),h(""),o.success("Category created!")},onError:()=>o.error("Failed to create category")}),C=u({mutationFn:async()=>{if(!c)return;const{error:s}=await n.from("blog_categories").update({name:p,slug:f}).eq("id",c);if(s)throw s},onSuccess:()=>{d.invalidateQueries({queryKey:["admin-categories"]}),m(null),o.success("Category updated!")},onError:()=>o.error("Failed to update")}),w=u({mutationFn:async s=>{const{error:t}=await n.from("blog_categories").delete().eq("id",s);if(t)throw t},onSuccess:()=>{d.invalidateQueries({queryKey:["admin-categories"]}),o.success("Category deleted")}}),S=s=>{m(s.id),y(s.name),j(s.slug)};return e.jsxs(E,{children:[e.jsx("h1",{className:"font-display text-2xl font-bold mb-2",children:"Blog Categories"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-6",children:"Organize your blog posts into categories for easier browsing."}),e.jsxs("div",{className:"bg-card border border-border rounded-lg p-4 mb-6 space-y-3",children:[e.jsx("h3",{className:"font-display font-medium text-sm",children:"Add New Category"}),e.jsxs("div",{className:"flex gap-2 items-end",children:[e.jsx("div",{className:"flex-1",children:e.jsx(N,{label:"Name",hint:"The display name for this category.",children:e.jsx(l,{value:i,onChange:s=>g(s.target.value),className:"bg-secondary",placeholder:"Category name"})})}),e.jsx("div",{className:"flex-1",children:e.jsx(N,{label:"Slug",hint:"URL-friendly identifier. Auto-generated if left blank.",children:e.jsx(l,{value:x,onChange:s=>h(s.target.value),className:"bg-secondary",placeholder:"auto-generated"})})}),e.jsxs(r,{onClick:()=>v.mutate(),disabled:!i.trim(),children:[e.jsx(k,{className:"w-4 h-4 mr-1"})," Add"]})]})]}),b.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground bg-card border border-border rounded-lg",children:[e.jsx("p",{className:"font-medium",children:"No categories yet"}),e.jsx("p",{className:"text-sm mt-1",children:"Add your first category above."})]}):e.jsx("div",{className:"space-y-2",children:b.map(s=>e.jsx("div",{className:"bg-card border border-border rounded-lg p-4 flex items-center justify-between",children:c===s.id?e.jsxs("div",{className:"flex items-center gap-2 flex-1 mr-2",children:[e.jsx(l,{value:p,onChange:t=>y(t.target.value),className:"bg-secondary h-8 text-sm"}),e.jsx(l,{value:f,onChange:t=>j(t.target.value),className:"bg-secondary h-8 text-sm"}),e.jsx(r,{variant:"ghost",size:"sm",onClick:()=>C.mutate(),children:e.jsx(z,{className:"w-4 h-4 text-primary"})}),e.jsx(r,{variant:"ghost",size:"sm",onClick:()=>m(null),children:e.jsx(Q,{className:"w-4 h-4"})})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-semibold",children:s.name}),e.jsxs("span",{className:"text-xs text-muted-foreground ml-2",children:["/",s.slug]})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(r,{variant:"ghost",size:"sm",onClick:()=>S(s),title:"Edit category",children:e.jsx(B,{className:"w-4 h-4"})}),e.jsx(A,{title:"Delete this category?",description:`"${s.name}" will be permanently removed. Blog posts in this category will become uncategorized.`,onConfirm:()=>w.mutate(s.id),trigger:e.jsx(r,{variant:"ghost",size:"sm",title:"Delete category",children:e.jsx(I,{className:"w-4 h-4 text-destructive"})})})]})]})},s.id))})]})}export{G 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.