PageSourceSearch

https://getmelon.com.au/assets/AdminBlogEditor-DuUdM1tc.js

js getmelon.com.au collected 2026-09-30 06:39:17 UTC 6,371 bytes, 1 lines download raw bytes

1import{p as U,u as B,r as u,d,i,j as e,X as L}from"./index-DjvjYx8D.js";import{B as p}from"./button-Cz5sYbhP.js";import{I as c}from"./input-vy9OFss5.js";import{L as l}from"./label-BVrYemgw.js";import{T as h}from"./textarea-BNnM3daC.js";import{S as T}from"./switch-BSzd-ca8.js";import{C as I,b as P,d as A,a as D}from"./card-BoeYN9zz.js";import{u as M}from"./useAdminCheck-B3x8uYLY.js";import{A as q}from"./arrow-left-DXjop1Hu.js";import{U as H}from"./upload-Pf0DR9Sz.js";import"./index-Dv7kNRC4.js";import"./useImpersonation-CWFUls8c.js";import"./queryTimeout-DjX5RWJs.js";import"./roleCache-CPULw5mK.js";const te=()=>{M();const{id:o}=U(),n=B(),[x,f]=u.useState(!1),[j,v]=u.useState(!1),[t,r]=u.useState({title:"",slug:"",excerpt:"",content:"",category:"Announcements",is_published:!1,meta_title:"",meta_description:"",meta_keywords:"",featured_image_url:"",featured_image_key:""});u.useEffect(()=>{o&&y()},[o]);const y=async()=>{const{data:s,error:a}=await d.from("blog_posts").select("*").eq("id",o).single();a?(i.error("Failed to load blog post"),n("/admin/blog")):r(s)},_=s=>s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,""),N=s=>{r(a=>({...a,title:s,slug:_(s)}))},w=async s=>{var b;const a=(b=s.target.files)==null?void 0:b[0];if(!a)return;v(!0);const m=a.name.split(".").pop(),g=`${`${Math.random()}.${m}`}`,{error:F,data:$}=await d.storage.from("blog-images").upload(g,a);if(F)i.error("Failed to upload image");else{const{data:{publicUrl:S}}=d.storage.from("blog-images").getPublicUrl(g);r(E=>({...E,featured_image_url:S,featured_image_key:g})),i.success("Image uploaded successfully")}v(!1)},C=async()=>{t.featured_image_key&&await d.storage.from("blog-images").remove([t.featured_image_key]),r(s=>({...s,featured_image_url:"",featured_image_key:""}))},k=async s=>{s.preventDefault(),f(!0);const a={...t,published_at:t.is_published?new Date().toISOString():null};if(o){const{error:m}=await d.from("blog_posts").update(a).eq("id",o);m?i.error("Failed to update blog post"):(i.success("Blog post updated successfully"),n("/admin/blog"))}else{const{error:m}=await d.from("blog_posts").insert([a]);m?i.error("Failed to create blog post"):(i.success("Blog post created successfully"),n("/admin/blog"))}f(!1)};return e.jsx("div",{className:"min-h-screen bg-background",children:e.jsxs("div",{className:"container mx-auto px-4 py-8 max-w-4xl",children:[e.jsxs(p,{variant:"ghost",onClick:()=>n("/admin/blog"),className:"mb-6",children:[e.jsx(q,{className:"h-4 w-4 mr-2"}),"Back to Blog"]}),e.jsx("form",{onSubmit:k,children:e.jsxs(I,{children:[e.jsx(P,{children:e.jsx(A,{children:o?"Edit Blog Post":"New Blog Post"})}),e.jsxs(D,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"title",children:"Title"}),e.jsx(c,{id:"title",value:t.title,onChange:s=>N(s.target.value),placeholder:"Enter post title",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"slug",children:"Slug (URL)"}),e.jsx(c,{id:"slug",value:t.slug,onChange:s=>r(a=>({...a,slug:s.target.value})),placeholder:"post-url-slug",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"category",children:"Category"}),e.jsx(c,{id:"category",value:t.category,onChange:s=>r(a=>({...a,category:s.target.value})),placeholder:"Announcements"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"excerpt",children:"Excerpt"}),e.jsx(h,{id:"excerpt",value:t.excerpt,onChange:s=>r(a=>({...a,excerpt:s.target.value})),placeholder:"Short summary of the post",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{children:"Featured Image"}),t.featured_image_url?e.jsxs("div",{className:"relative aspect-video w-full overflow-hidden rounded-lg border",children:[e.jsx("img",{src:t.featured_image_url,alt:"Featured",className:"w-full h-full object-cover"}),e.jsx(p,{type:"button",variant:"destructive",size:"sm",className:"absolute top-2 right-2",onClick:C,children:e.jsx(L,{className:"h-4 w-4"})})]}):e.jsxs("div",{className:"border-2 border-dashed rounded-lg p-8 text-center",children:[e.jsx(c,{type:"file",accept:"image/*",onChange:w,disabled:j,className:"hidden",id:"image-upload"}),e.jsxs(l,{htmlFor:"image-upload",className:"cursor-pointer",children:[e.jsx(H,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:j?"Uploading...":"Click to upload image"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"content",children:"Content (HTML)"}),e.jsx(h,{id:"content",value:t.content,onChange:s=>r(a=>({...a,content:s.target.value})),placeholder:"<h2>Heading</h2><p>Your content here...</p>",rows:12,required:!0,className:"font-mono text-sm"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Use HTML tags for formatting: h2, h3, p, ul, li, strong, em, a"})]}),e.jsxs("div",{className:"space-y-4 pt-4 border-t",children:[e.jsx("h3",{className:"font-semibold",children:"SEO Settings"}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"meta_title",children:"Meta Title"}),e.jsx(c,{id:"meta_title",value:t.meta_title,onChange:s=>r(a=>({...a,meta_title:s.target.value})),placeholder:"SEO title (leave empty to use post title)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"meta_description",children:"Meta Description"}),e.jsx(h,{id:"meta_description",value:t.meta_description,onChange:s=>r(a=>({...a,meta_description:s.target.value})),placeholder:"SEO description (leave empty to use excerpt)",rows:2})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(l,{htmlFor:"meta_keywords",children:"Meta Keywords"}),e.jsx(c,{id:"meta_keywords",value:t.meta_keywords,onChange:s=>r(a=>({...a,meta_keywords:s.target.value})),placeholder:"keyword1, keyword2, keyword3"})]})]}),e.jsxs("div",{className:"flex items-center justify-between pt-4 border-t",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(T,{id:"is_published",checked:t.is_published,onCheckedChange:s=>r(a=>({...a,is_published:s}))}),e.jsx(l,{htmlFor:"is_published",children:"Publish post"})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(p,{type:"button",variant:"outline",onClick:()=>n("/admin/blog"),children:"Cancel"}),e.jsx(p,{type:"submit",disabled:x,children:x?"Saving...":o?"Update":"Create"})]})]})]})]})})]})})};export{te 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.