1 line
16 KiB
JavaScript
1 line
16 KiB
JavaScript
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[563],{10255:(e,t,r)=>{"use strict";function s(e){let{moduleIds:t}=e;return null}Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"PreloadChunks",{enumerable:!0,get:function(){return s}}),r(95155),r(47650),r(85744),r(20589)},17828:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"workAsyncStorageInstance",{enumerable:!0,get:function(){return s}});let s=(0,r(64054).createAsyncLocalStorage)()},36645:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"default",{enumerable:!0,get:function(){return a}});let s=r(88229)._(r(67357));function a(e,t){var r;let a={};"function"==typeof e&&(a.loader=e);let l={...a,...t};return(0,s.default)({...l,modules:null==(r=l.loadableGenerated)?void 0:r.modules})}("function"==typeof t.default||"object"==typeof t.default&&null!==t.default)&&void 0===t.default.__esModule&&(Object.defineProperty(t.default,"__esModule",{value:!0}),Object.assign(t.default,t),e.exports=t.default)},51689:(e,t,r)=>{Promise.resolve().then(r.bind(r,98308))},62146:(e,t,r)=>{"use strict";function s(e){let{reason:t,children:r}=e;return r}Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"BailoutToCSR",{enumerable:!0,get:function(){return s}}),r(45262)},64054:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),!function(e,t){for(var r in t)Object.defineProperty(e,r,{enumerable:!0,get:t[r]})}(t,{bindSnapshot:function(){return n},createAsyncLocalStorage:function(){return l},createSnapshot:function(){return o}});let r=Object.defineProperty(Error("Invariant: AsyncLocalStorage accessed in runtime where it is not available"),"__NEXT_ERROR_CODE",{value:"E504",enumerable:!1,configurable:!0});class s{disable(){throw r}getStore(){}run(){throw r}exit(){throw r}enterWith(){throw r}static bind(e){return e}}let a="undefined"!=typeof globalThis&&globalThis.AsyncLocalStorage;function l(){return a?new a:new s}function n(e){return a?a.bind(e):s.bind(e)}function o(){return a?a.snapshot():function(e,...t){return e(...t)}}},65581:(e,t,r)=>{"use strict";r.d(t,{A:()=>l});var s=r(95155);r(12115);var a=r(87481);function l(e){var t,r;let{endpoint:l,onUploadComplete:n,className:o}=e,[i,c]=useState(!1),{startUpload:d,permittedFileInfo:u}=useUploadThing(l,{onClientUploadComplete:e=>{c(!1),e&&e[0]&&(null==n||n(e[0].url,new File([],e[0].name)),(0,a.o)({title:"Success",description:"File uploaded successfully!",status:"success"}))},onUploadError:e=>{c(!1),(0,a.o)({title:"Error",description:"Upload failed: ".concat(e.message),status:"error"})},onUploadBegin:()=>{c(!0)}});return(0,s.jsxs)("div",{className:o,children:[(0,s.jsx)("div",{className:"flex items-center justify-center w-full",children:(0,s.jsxs)("label",{className:"flex flex-col items-center justify-center w-full h-64 border-2 border-dashed border-text-muted rounded-lg cursor-pointer bg-bg-light hover:bg-bg-light/50 transition-colors",children:[(0,s.jsxs)("div",{className:"flex flex-col items-center justify-center pt-5 pb-6",children:[(0,s.jsx)("svg",{className:"w-8 h-8 mb-4 text-text-muted","aria-hidden":"true",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 20 16",children:(0,s.jsx)("path",{stroke:"currentColor",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M13 13h3a3 3 0 0 0 0-6h-.025A5.56 5.56 0 0 0 16 6.5 5.5 5.5 0 0 0 5.207 5.021C5.137 5.017 5.071 5 5 5a4 4 0 0 0 0 8h2.167M10 15V6m0 0L8 8m2-2 2 2"})}),(0,s.jsxs)("p",{className:"mb-2 text-sm text-text-muted",children:[(0,s.jsx)("span",{className:"font-semibold",children:"Click to upload"})," or drag and drop"]}),(0,s.jsx)("p",{className:"text-xs text-text-muted",children:(null==u||null==(t=u.config.image)?void 0:t.maxFileSize)||(null==u||null==(r=u.config.video)?void 0:r.maxFileSize)||"Any file type"})]}),(0,s.jsx)("input",{type:"file",className:"hidden",onChange:e=>{var t;let r=null==(t=e.target.files)?void 0:t[0];r&&d([r]).catch(e=>{(0,a.o)({title:"Error",description:"Upload failed. Please try again.",status:"error"})})},disabled:i})]})}),i&&(0,s.jsx)("p",{className:"text-text-muted mt-2 text-center",children:"Uploading..."})]})}},66766:(e,t,r)=>{"use strict";r.d(t,{default:()=>a.a});var s=r(71469),a=r.n(s)},67357:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"default",{enumerable:!0,get:function(){return i}});let s=r(95155),a=r(12115),l=r(62146);function n(e){return{default:e&&"default"in e?e.default:e}}r(10255);let o={loader:()=>Promise.resolve(n(()=>null)),loading:null,ssr:!0},i=function(e){let t={...o,...e},r=(0,a.lazy)(()=>t.loader().then(n)),i=t.loading;function c(e){let n=i?(0,s.jsx)(i,{isLoading:!0,pastDelay:!0,error:null}):null,o=!t.ssr||!!t.loading,c=o?a.Suspense:a.Fragment,d=t.ssr?(0,s.jsxs)(s.Fragment,{children:[null,(0,s.jsx)(r,{...e})]}):(0,s.jsx)(l.BailoutToCSR,{reason:"next/dynamic",children:(0,s.jsx)(r,{...e})});return(0,s.jsx)(c,{...o?{fallback:n}:{},children:d})}return c.displayName="LoadableComponent",c}},71469:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),!function(e,t){for(var r in t)Object.defineProperty(e,r,{enumerable:!0,get:t[r]})}(t,{default:function(){return i},getImageProps:function(){return o}});let s=r(88229),a=r(38883),l=r(33063),n=s._(r(51193));function o(e){let{props:t}=(0,a.getImgProps)(e,{defaultLoader:n.default,imgConf:{deviceSizes:[640,750,828,1080,1200,1920,2048,3840],imageSizes:[16,32,48,64,96,128,256,384],path:"/_next/image",loader:"default",dangerouslyAllowSVG:!1,unoptimized:!1}});for(let[e,r]of Object.entries(t))void 0===r&&delete t[e];return{props:t}}let i=l.Image},85744:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),Object.defineProperty(t,"workAsyncStorage",{enumerable:!0,get:function(){return s.workAsyncStorageInstance}});let s=r(17828)},87481:(e,t,r)=>{"use strict";r.d(t,{d:()=>d,o:()=>c});var s=r(12115);let a={ADD_TOAST:"ADD_TOAST",UPDATE_TOAST:"UPDATE_TOAST",DISMISS_TOAST:"DISMISS_TOAST",REMOVE_TOAST:"REMOVE_TOAST"},l=0,n=[],o={toasts:[]};function i(e){o=((e,t)=>{switch(t.type){case a.ADD_TOAST:return{...e,toasts:[t.toast,...e.toasts].slice(0,3)};case a.DISMISS_TOAST:{let{toastId:r}=t;return{...e,toasts:e.toasts.map(e=>e.id===r?{...e,status:"error"}:e)}}case a.REMOVE_TOAST:return{...e,toasts:e.toasts.filter(e=>e.id!==t.toastId)}}})(o,e),n.forEach(e=>{e(o)})}function c(e){var t;let{...r}=e,s=(l=(l+1)%Number.MAX_SAFE_INTEGER).toString();return i({type:a.ADD_TOAST,toast:{...r,id:s,status:null!=(t=r.status)?t:"info",title:r.title,description:r.description,action:r.action}}),{id:s,dismiss:()=>i({type:a.DISMISS_TOAST,toastId:s}),update:e=>i({type:a.UPDATE_TOAST,toast:{...e,id:s}})}}function d(){let[e,t]=s.useState(o);return s.useEffect(()=>(n.push(t),()=>{let e=n.indexOf(t);e>-1&&n.splice(e,1)}),[e]),{...e,toast:c,dismiss:e=>i({type:a.DISMISS_TOAST,toastId:e})}}},98308:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>h});var s=r(95155),a=r(12115),l=r(35695),n=r(12108),o=r(6874),i=r.n(o),c=r(36645),d=r.n(c),u=r(66766),p=r(65581),m=r(87481);let f=d()(()=>Promise.all([r.e(827),r.e(962),r.e(78)]).then(r.bind(r,77078)).then(e=>e.default),{loadableGenerated:{webpack:()=>[null]},ssr:!1});function h(){let{data:e,status:t}=(0,n.useSession)(),r=(0,l.useRouter)(),[o,c]=(0,a.useState)([]),[d,h]=(0,a.useState)(!0),[b,x]=(0,a.useState)(null),[g,j]=(0,a.useState)(!1),[y,v]=(0,a.useState)("");(0,a.useEffect)(()=>{"loading"!==t&&(e||r.push("/admin/login"))},[e,t,r]),(0,a.useEffect)(()=>{let t=async()=>{try{let e=await fetch("/api/blog");if(!e.ok)throw Error("Failed to fetch blog posts");let t=await e.json();c(t)}catch(e){console.error("Error fetching blog posts:",e)}finally{h(!1)}};e&&t()},[e]);let w=async e=>{if(confirm("Are you sure you want to delete this post?"))try{if(!(await fetch("/api/blog/".concat(e),{method:"DELETE"})).ok)throw Error("Failed to delete post");let t=async()=>{try{let e=await fetch("/api/blog");if(!e.ok)throw Error("Failed to fetch blog posts");let t=await e.json();c(t)}catch(e){console.error("Error fetching blog posts:",e)}};await t(),(0,m.o)({title:"Success",description:"Post deleted successfully",status:"success"})}catch(e){console.error("Error deleting post:",e),(0,m.o)({title:"Error",description:"Failed to delete post",status:"error"})}},N=async e=>{if(e.preventDefault(),b)try{let e;if(!(e=b.id?await fetch("/api/blog/".concat(b.id),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({...b,tags:y.split(",").map(e=>e.trim()).filter(e=>e),readTime:Math.ceil(b.content.split(" ").length/200)})}):await fetch("/api/blog",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...b,tags:y.split(",").map(e=>e.trim()).filter(e=>e),readTime:Math.ceil(b.content.split(" ").length/200)})})).ok){let t=await e.json();throw Error(t.error||"Failed to save post")}let t=async()=>{try{let e=await fetch("/api/blog");if(!e.ok)throw Error("Failed to fetch blog posts");let t=await e.json();c(t)}catch(e){console.error("Error fetching blog posts:",e)}};await t(),j(!1),x(null),v(""),(0,m.o)({title:"Success",description:"Post saved successfully",status:"success"})}catch(e){console.error("Error saving post:",e),(0,m.o)({title:"Error",description:"Failed to save post",status:"error"})}},S=async e=>{try{let t=o.find(t=>t.id===e);if(!t)return;if(!(await fetch("/api/blog/".concat(e),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({...t,published:!t.published})})).ok)throw Error("Failed to update post");let r=async()=>{try{let e=await fetch("/api/blog");if(!e.ok)throw Error("Failed to fetch blog posts");let t=await e.json();c(t)}catch(e){console.error("Error fetching blog posts:",e)}};await r(),(0,m.o)({title:"Success",description:"Post updated successfully",status:"success"})}catch(e){console.error("Error updating post:",e),(0,m.o)({title:"Error",description:"Failed to update post",status:"error"})}};return"loading"===t||d?(0,s.jsx)("div",{className:"min-h-screen bg-bg-dark flex items-center justify-center",children:(0,s.jsx)("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-accent"})}):(0,s.jsxs)("div",{className:"min-h-screen bg-bg-dark",children:[(0,s.jsx)("header",{className:"bg-bg-light border-b border-bg-light/50",children:(0,s.jsxs)("div",{className:"max-w-7xl mx-auto px-6 py-4 flex items-center justify-between",children:[(0,s.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,s.jsx)(i(),{href:"/admin",className:"text-text-muted hover:text-white",children:"← Back"}),(0,s.jsx)("h1",{className:"text-2xl font-bold text-white",children:"Manage Blog Posts"})]}),(0,s.jsx)("button",{onClick:()=>{var t;x({id:"",title:"",slug:"",excerpt:"",content:"",featuredImage:"",author:(null==e||null==(t=e.user)?void 0:t.name)||"Admin",date:new Date().toISOString().split("T")[0],tags:[],readTime:0,published:!1}),v(""),j(!0)},className:"bg-accent text-bg-dark px-4 py-2 rounded hover:bg-accent/90 transition-colors",children:"Create New Post"})]})}),(0,s.jsx)("main",{className:"max-w-7xl mx-auto px-6 py-8",children:(0,s.jsx)("div",{className:"space-y-4",children:0===o.length?(0,s.jsx)("div",{className:"text-center py-12 text-text-muted",children:"No blog posts yet. Create your first post!"}):o.sort((e,t)=>new Date(t.date).getTime()-new Date(e.date).getTime()).map(e=>{var t;return(0,s.jsx)("div",{className:"bg-bg-light rounded-lg p-6",children:(0,s.jsxs)("div",{className:"flex items-start justify-between",children:[(0,s.jsxs)("div",{className:"flex-grow",children:[(0,s.jsx)("h3",{className:"text-lg font-semibold text-white",children:e.title}),(0,s.jsx)("p",{className:"text-text-muted text-sm mt-1",children:e.excerpt}),(0,s.jsxs)("div",{className:"flex items-center space-x-4 mt-2 text-sm text-text-muted",children:[(0,s.jsx)("span",{children:(null==(t=e.author)?void 0:t.name)||e.author}),(0,s.jsx)("span",{children:"•"}),(0,s.jsx)("span",{children:new Date(e.date).toLocaleDateString()}),(0,s.jsx)("span",{children:"•"}),(0,s.jsxs)("span",{children:[e.readTime," min read"]}),(0,s.jsx)("span",{children:"•"}),(0,s.jsx)("span",{className:e.published?"text-green-400":"text-yellow-400",children:e.published?"Published":"Draft"})]}),(0,s.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:e.tags.map(e=>(0,s.jsx)("span",{className:"px-2 py-1 bg-bg-dark text-xs rounded",children:e},e))})]}),(0,s.jsxs)("div",{className:"flex items-center space-x-2 ml-4",children:[(0,s.jsx)("button",{onClick:()=>S(e.id),className:"px-3 py-1 rounded text-white ".concat(e.published?"bg-yellow-500 hover:bg-yellow-600":"bg-green-500 hover:bg-green-600"),children:e.published?"Unpublish":"Publish"}),(0,s.jsx)("button",{onClick:()=>{x(e),v(e.tags.join(", ")),j(!0)},className:"px-3 py-1 bg-blue-500 text-white rounded hover:bg-blue-600",children:"Edit"}),(0,s.jsx)("button",{onClick:()=>w(e.id),className:"px-3 py-1 bg-red-500 text-white rounded hover:bg-red-600",children:"Delete"})]})]})},e.id)})})}),g&&b&&(0,s.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-6",onClick:e=>{e.target===e.currentTarget&&(j(!1),x(null),v(""))},children:(0,s.jsxs)("div",{className:"bg-bg-light rounded-lg p-6 max-w-4xl w-full max-h-[90vh] overflow-y-auto",children:[(0,s.jsx)("h2",{className:"text-2xl font-bold mb-6",children:b.id?"Edit Post":"Create New Post"}),(0,s.jsxs)("form",{onSubmit:N,className:"space-y-4",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Title"}),(0,s.jsx)("input",{type:"text",value:b.title,onChange:e=>x({...b,title:e.target.value}),className:"w-full px-3 py-2 bg-bg-dark border border-bg-light rounded focus:border-accent focus:outline-none",required:!0})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Excerpt"}),(0,s.jsx)("textarea",{value:b.excerpt,onChange:e=>x({...b,excerpt:e.target.value}),className:"w-full px-3 py-2 bg-bg-dark border border-bg-light rounded focus:border-accent focus:outline-none",rows:2,required:!0})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Featured Image"}),b.featuredImage&&(0,s.jsx)("div",{className:"relative w-full h-48 mb-2",children:(0,s.jsx)(u.default,{src:b.featuredImage,alt:"Featured image preview",fill:!0,className:"object-cover rounded"})}),(0,s.jsx)(p.A,{endpoint:"imageUploader",onUploadComplete:e=>x({...b,featuredImage:e}),className:"mb-2"}),(0,s.jsx)("input",{type:"text",value:b.featuredImage,onChange:e=>x({...b,featuredImage:e.target.value}),className:"w-full px-3 py-2 bg-bg-dark border border-bg-light rounded focus:border-accent focus:outline-none",placeholder:"Or enter URL manually"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Author"}),(0,s.jsx)("input",{type:"text",value:b.author,onChange:e=>x({...b,author:e.target.value}),className:"w-full px-3 py-2 bg-bg-dark border border-bg-light rounded focus:border-accent focus:outline-none",required:!0})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Date"}),(0,s.jsx)("input",{type:"date",value:b.date,onChange:e=>x({...b,date:e.target.value}),className:"w-full px-3 py-2 bg-bg-dark border border-bg-light rounded focus:border-accent focus:outline-none",required:!0})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Tags (comma separated)"}),(0,s.jsx)("input",{type:"text",value:y,onChange:e=>v(e.target.value),className:"w-full px-3 py-2 bg-bg-dark border border-bg-light rounded focus:border-accent focus:outline-none",placeholder:"VFX, Animation, Tutorial"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Content (Markdown)"}),(0,s.jsx)("div",{className:"bg-bg-dark rounded","data-color-mode":"dark",children:(0,s.jsx)(f,{value:b.content,onChange:e=>x({...b,content:e||""}),height:400,preview:"edit"})})]}),(0,s.jsxs)("div",{className:"flex justify-end space-x-4 pt-4",children:[(0,s.jsx)("button",{type:"button",onClick:()=>{j(!1),x(null),v("")},className:"px-4 py-2 text-text-muted hover:text-white",children:"Cancel"}),(0,s.jsx)("button",{type:"submit",className:"px-4 py-2 bg-accent text-bg-dark rounded hover:bg-accent/90",children:"Save Post"})]})]})]})})]})}}},e=>{e.O(0,[874,63,454,441,964,120],()=>e(e.s=51689)),_N_E=e.O()}]); |