1 line
13 KiB
JavaScript
1 line
13 KiB
JavaScript
(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[321],{52155:(e,t,s)=>{Promise.resolve().then(s.bind(s,82399))},65581:(e,t,s)=>{"use strict";s.d(t,{A:()=>r});var l=s(95155);s(12115);var a=s(87481);function r(e){var t,s;let{endpoint:r,onUploadComplete:i,className:o}=e,[n,c]=useState(!1),{startUpload:d,permittedFileInfo:u}=useUploadThing(r,{onClientUploadComplete:e=>{c(!1),e&&e[0]&&(null==i||i(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,l.jsxs)("div",{className:o,children:[(0,l.jsx)("div",{className:"flex items-center justify-center w-full",children:(0,l.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,l.jsxs)("div",{className:"flex flex-col items-center justify-center pt-5 pb-6",children:[(0,l.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,l.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,l.jsxs)("p",{className:"mb-2 text-sm text-text-muted",children:[(0,l.jsx)("span",{className:"font-semibold",children:"Click to upload"})," or drag and drop"]}),(0,l.jsx)("p",{className:"text-xs text-text-muted",children:(null==u||null==(t=u.config.image)?void 0:t.maxFileSize)||(null==u||null==(s=u.config.video)?void 0:s.maxFileSize)||"Any file type"})]}),(0,l.jsx)("input",{type:"file",className:"hidden",onChange:e=>{var t;let s=null==(t=e.target.files)?void 0:t[0];s&&d([s]).catch(e=>{(0,a.o)({title:"Error",description:"Upload failed. Please try again.",status:"error"})})},disabled:n})]})}),n&&(0,l.jsx)("p",{className:"text-text-muted mt-2 text-center",children:"Uploading..."})]})}},66766:(e,t,s)=>{"use strict";s.d(t,{default:()=>a.a});var l=s(71469),a=s.n(l)},71469:(e,t,s)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),!function(e,t){for(var s in t)Object.defineProperty(e,s,{enumerable:!0,get:t[s]})}(t,{default:function(){return n},getImageProps:function(){return o}});let l=s(88229),a=s(38883),r=s(33063),i=l._(s(51193));function o(e){let{props:t}=(0,a.getImgProps)(e,{defaultLoader:i.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,s]of Object.entries(t))void 0===s&&delete t[e];return{props:t}}let n=r.Image},82399:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>m});var l=s(95155),a=s(12115),r=s(12108),i=s(35695),o=s(6874),n=s.n(o),c=s(66766),d=s(87481),u=s(65581);function m(){let{data:e,status:t}=(0,r.useSession)(),s=(0,i.useRouter)(),[o,m]=(0,a.useState)([]),[x,h]=(0,a.useState)(!0),[b,p]=(0,a.useState)(null),[f,g]=(0,a.useState)(!1);(0,a.useEffect)(()=>{"loading"!==t&&(e||s.push("/admin/login"))},[e,t,s]),(0,a.useEffect)(()=>{let t=async()=>{try{let e=await fetch("/api/projects");if(!e.ok)throw Error("Failed to fetch projects");let t=await e.json();m(t)}catch(e){(0,d.o)({title:"Error",description:"Failed to load projects",status:"error"})}finally{h(!1)}};e&&t()},[e]);let j=async e=>{if(confirm("Are you sure you want to delete this project?"))try{if(!(await fetch("/api/projects/".concat(e),{method:"DELETE"})).ok)throw Error("Failed to delete project");m(o.filter(t=>t.id!==e)),(0,d.o)({title:"Success",description:"Project deleted successfully",status:"success"})}catch(e){(0,d.o)({title:"Error",description:"Failed to delete project",status:"error"})}},v=async e=>{if(e.preventDefault(),b){console.log("Sending project data:",b);try{let e;if(!(e=b.id?await fetch("/api/projects/".concat(b.id),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)}):await fetch("/api/projects/create",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)})).ok){let t=await e.json();throw Error(t.error||"Failed to save project")}let t=await e.json();b.id?m(o.map(e=>e.id===t.id?t:e)):m([...o,t]),g(!1),p(null),(0,d.o)({title:"Success",description:"Project saved successfully",status:"success"})}catch(e){(0,d.o)({title:"Error",description:"Failed to save project",status:"error"})}}};return"loading"===t||x?(0,l.jsx)("div",{className:"min-h-screen bg-bg-dark flex items-center justify-center",children:(0,l.jsx)("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-accent"})}):(0,l.jsxs)("div",{className:"min-h-screen bg-bg-dark",children:[(0,l.jsx)("header",{className:"bg-bg-light border-b border-bg-light/50",children:(0,l.jsxs)("div",{className:"max-w-7xl mx-auto px-6 py-4 flex items-center justify-between",children:[(0,l.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,l.jsx)(n(),{href:"/admin",className:"text-text-muted hover:text-white",children:"← Back"}),(0,l.jsx)("h1",{className:"text-2xl font-bold text-white",children:"Manage Projects"})]}),(0,l.jsx)("button",{onClick:()=>{p({id:"",title:"",description:null,thumbnail:"",size:"SMALL",embed:null,video:null,credits:"",info:"",category:null,tags:null,featured:!1,published:!1,createdAt:new Date,updatedAt:new Date}),g(!0)},className:"bg-accent text-bg-dark px-4 py-2 rounded hover:bg-accent/90 transition-colors",children:"Add New Project"})]})}),(0,l.jsx)("main",{className:"max-w-7xl mx-auto px-6 py-8",children:(0,l.jsx)("div",{className:"space-y-4",children:o.map((e,t)=>(0,l.jsxs)("div",{className:"bg-bg-light rounded-lg p-6 flex items-center space-x-6",children:[(0,l.jsx)("div",{className:"relative w-32 h-20 flex-shrink-0",children:(0,l.jsx)(c.default,{src:e.thumbnail,alt:e.title,fill:!0,className:"object-cover rounded"})}),(0,l.jsxs)("div",{className:"flex-grow",children:[(0,l.jsx)("h3",{className:"text-lg font-semibold text-white",children:e.title}),(0,l.jsx)("p",{className:"text-text-muted text-sm",children:e.category||"No category"}),e.featured&&(0,l.jsx)("span",{className:"inline-block mt-1 px-2 py-1 bg-accent/20 text-accent text-xs rounded",children:"Featured"})]}),(0,l.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,l.jsx)("button",{onClick:()=>{p(e),g(!0)},className:"px-3 py-1 bg-blue-500 text-white rounded hover:bg-blue-600",children:"Edit"}),(0,l.jsx)("button",{onClick:()=>j(e.id),className:"px-3 py-1 bg-red-500 text-white rounded hover:bg-red-600",children:"Delete"})]})]},e.id))})}),f&&b&&(0,l.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-6",onClick:e=>{e.target===e.currentTarget&&(g(!1),p(null))},children:(0,l.jsxs)("div",{className:"bg-bg-light rounded-lg p-6 max-w-2xl w-full max-h-[90vh] overflow-y-auto",children:[(0,l.jsx)("h2",{className:"text-2xl font-bold mb-6",children:b.id?"Edit Project":"Add New Project"}),(0,l.jsxs)("form",{onSubmit:v,className:"space-y-4",children:[(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Title"}),(0,l.jsx)("input",{type:"text",value:b.title,onChange:e=>p({...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,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Description (optional)"}),(0,l.jsx)("textarea",{value:b.description||"",onChange:e=>p({...b,description: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:3})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Category (optional)"}),(0,l.jsx)("input",{type:"text",value:b.category||"",onChange:e=>p({...b,category:e.target.value}),className:"w-full px-3 py-2 bg-bg-dark border border-bg-light rounded focus:border-accent focus:outline-none"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Thumbnail"}),b.thumbnail&&(0,l.jsx)("div",{className:"relative w-32 h-20 mb-2",children:(0,l.jsx)(c.default,{src:b.thumbnail,alt:"Thumbnail preview",fill:!0,className:"object-cover rounded"})}),(0,l.jsx)(u.A,{endpoint:"imageUploader",onUploadComplete:e=>p({...b,thumbnail:e}),className:"mb-2"}),(0,l.jsx)("input",{type:"text",value:b.thumbnail,onChange:e=>p({...b,thumbnail: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,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Size"}),(0,l.jsxs)("select",{value:b.size,onChange:e=>p({...b,size:e.target.value}),className:"w-full px-3 py-2 bg-bg-dark border border-bg-light rounded focus:border-accent focus:outline-none",children:[(0,l.jsx)("option",{value:"SMALL",children:"Small"}),(0,l.jsx)("option",{value:"BIG",children:"Big"})]})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Video Upload (optional)"}),b.video&&(0,l.jsx)("div",{className:"relative w-full h-48 mb-2",children:(0,l.jsx)("video",{src:b.video,controls:!0,className:"w-full h-full object-cover rounded"})}),(0,l.jsx)(u.A,{endpoint:"videoUploader",onUploadComplete:e=>p({...b,video:e}),className:"mb-2"}),(0,l.jsx)("input",{type:"text",value:b.video||"",onChange:e=>p({...b,video: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,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Embed URL (YouTube/Vimeo) (optional)"}),(0,l.jsx)("input",{type:"text",value:b.embed||"",onChange:e=>p({...b,embed: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:"https://www.youtube.com/embed/..."})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Credits"}),(0,l.jsx)("textarea",{value:b.credits,onChange:e=>p({...b,credits: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:4,placeholder:"Enter project credits directly"})]}),(0,l.jsxs)("div",{children:[(0,l.jsx)("label",{className:"block text-sm font-medium mb-2",children:"Project Info"}),(0,l.jsx)("textarea",{value:b.info,onChange:e=>p({...b,info: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:4,placeholder:"Enter project information directly"})]}),(0,l.jsxs)("div",{className:"flex items-center",children:[(0,l.jsx)("input",{type:"checkbox",id:"featured",checked:b.featured,onChange:e=>p({...b,featured:e.target.checked}),className:"mr-2"}),(0,l.jsx)("label",{htmlFor:"featured",className:"text-sm",children:"Featured Project"})]}),(0,l.jsxs)("div",{className:"flex items-center",children:[(0,l.jsx)("input",{type:"checkbox",id:"published",checked:b.published,onChange:e=>p({...b,published:e.target.checked}),className:"mr-2"}),(0,l.jsx)("label",{htmlFor:"published",className:"text-sm",children:"Published"})]}),(0,l.jsxs)("div",{className:"flex justify-end space-x-4 pt-4",children:[(0,l.jsx)("button",{type:"button",onClick:()=>{g(!1),p(null)},className:"px-4 py-2 text-text-muted hover:text-white",children:"Cancel"}),(0,l.jsx)("button",{type:"submit",className:"px-4 py-2 bg-accent text-bg-dark rounded hover:bg-accent/90",children:"Save Project"})]})]})]})})]})}},87481:(e,t,s)=>{"use strict";s.d(t,{d:()=>d,o:()=>c});var l=s(12115);let a={ADD_TOAST:"ADD_TOAST",UPDATE_TOAST:"UPDATE_TOAST",DISMISS_TOAST:"DISMISS_TOAST",REMOVE_TOAST:"REMOVE_TOAST"},r=0,i=[],o={toasts:[]};function n(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:s}=t;return{...e,toasts:e.toasts.map(e=>e.id===s?{...e,status:"error"}:e)}}case a.REMOVE_TOAST:return{...e,toasts:e.toasts.filter(e=>e.id!==t.toastId)}}})(o,e),i.forEach(e=>{e(o)})}function c(e){var t;let{...s}=e,l=(r=(r+1)%Number.MAX_SAFE_INTEGER).toString();return n({type:a.ADD_TOAST,toast:{...s,id:l,status:null!=(t=s.status)?t:"info",title:s.title,description:s.description,action:s.action}}),{id:l,dismiss:()=>n({type:a.DISMISS_TOAST,toastId:l}),update:e=>n({type:a.UPDATE_TOAST,toast:{...e,id:l}})}}function d(){let[e,t]=l.useState(o);return l.useEffect(()=>(i.push(t),()=>{let e=i.indexOf(t);e>-1&&i.splice(e,1)}),[e]),{...e,toast:c,dismiss:e=>n({type:a.DISMISS_TOAST,toastId:e})}}}},e=>{e.O(0,[874,63,454,441,964,120],()=>e(e.s=52155)),_N_E=e.O()}]); |