PageSourceSearch

https://ihatereading.in/_next/static/chunks/pages/admin/notifications-b99d078aabca7fab.js

js ihatereading.in collected 2026-10-03 22:51:25 UTC 10,371 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[744],{64553:function(e,t,s){(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/notifications",function(){return s(98619)}])},98619:function(e,t,s){"use strict";s.r(t),s.d(t,{default:function(){return v}});var a=s(85893),r=s(67294),i=s(88767),n=s(15313),l=s(9008),o=s.n(l),d=s(38623),c=s(72132),x=s(4270),m=s(82606),h=s(37864),b=s(21932),u=s(72874);let g=async()=>(await u.Z.firestore().collection("notifications").orderBy("createdAt","desc").get()).docs.map(e=>({id:e.id,...e.data()})),p=async e=>{let{title:t,description:s,link:a,banner:r}=e,i={title:t.trim(),description:(s||"").trim(),link:(a||"").trim(),banner:(r||"").trim()||null,createdAt:u.Z.firestore.FieldValue.serverTimestamp()};return{id:(await u.Z.firestore().collection("notifications").add(i)).id,...i}},y=async e=>{if(!e)throw Error("Notification id is required");return await u.Z.firestore().collection("notifications").doc(e).delete(),e};var f=s(96914);let j=["[email protected]","[email protected]"],N={title:"",description:"",link:"",banner:""};var v=()=>{var e,t;let s=(0,i.useQueryClient)(),{userReducer:{isUserLoggedIn:l,loggedInUserData:u}}=(0,n.v9)(e=>e),[v,w]=(0,r.useState)(!1),[k,A]=(0,r.useState)(N),[C,_]=(0,r.useState)(null),S=(null==u?void 0:null===(t=u.userEmail)||void 0===t?void 0:null===(e=t.toLowerCase)||void 0===e?void 0:e.call(t))||"",D=j.includes(S),{data:E=[],isLoading:F,isError:T,error:Z,refetch:L}=(0,i.useQuery)(["admin-notifications"],g,{enabled:l&&D,staleTime:3e4,cacheTime:6e5}),R=(0,i.useMutation)(p,{onSuccess:()=>{c.Am.success("Notification created"),A(N),s.invalidateQueries(["admin-notifications"]),s.invalidateQueries(["notifications"])},onError:e=>{c.Am.error((null==e?void 0:e.message)||"Failed to create notification")}}),Q=(0,i.useMutation)(y,{onMutate:e=>_(e),onSuccess:()=>{c.Am.success("Notification deleted"),s.invalidateQueries(["admin-notifications"]),s.invalidateQueries(["notifications"])},onError:e=>{c.Am.error((null==e?void 0:e.message)||"Failed to delete notification")},onSettled:()=>_(null)}),z=(0,r.useMemo)(()=>k.title.trim().length>0&&!R.isLoading,[k.title,R.isLoading]),M=e=>t=>{A(s=>({...s,[e]:t.target.value}))},O=(e,t)=>{window.confirm('Delete notification "'.concat(t||e,'"? This cannot be undone.'))&&Q.mutate(e)};return l?D?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(o(),{children:[(0,a.jsx)("title",{children:"Admin Notifications | iHateReading"}),(0,a.jsx)("meta",{name:"robots",content:"noindex, nofollow"},"robots")]}),(0,a.jsxs)("main",{className:"min-h-screen bg-white text-gray-900",children:[(0,a.jsx)("section",{className:"border-b border-dashed border-gray-200",children:(0,a.jsxs)("div",{className:"mx-auto max-w-8xl px-6 py-12",children:[(0,a.jsx)("p",{className:"text-xs uppercase tracking-wider text-gray-400",children:"Admin"}),(0,a.jsx)("h1",{className:"mt-2 text-3xl font-semibold tracking-tight md:text-4xl",children:"Notifications"}),(0,a.jsxs)("p",{className:"mt-3 max-w-2xl text-sm leading-6 text-gray-600",children:["Create Firestore notifications shown on"," ",(0,a.jsx)("code",{className:"bg-gray-100 px-1.5 py-0.5 text-xs",children:"/notifications"}),". Signed in as ",null==u?void 0:u.userEmail,"."]})]})}),(0,a.jsx)("section",{className:"mx-auto max-w-8xl px-6 py-8 md:py-10",children:(0,a.jsxs)("div",{className:"grid gap-8 lg:grid-cols-[360px_1fr]",children:[(0,a.jsxs)("form",{onSubmit:e=>{e.preventDefault(),z&&R.mutate({title:k.title,description:k.description,link:k.link||"/cursor-rules",banner:k.banner})},className:"h-fit border border-dashed border-gray-200 bg-white p-5",children:[(0,a.jsxs)("div",{className:"mb-4 flex items-center gap-2",children:[(0,a.jsx)(x.Z,{size:16,className:"text-gray-500"}),(0,a.jsx)("p",{className:"font-medium text-gray-900",children:"Add notification"})]}),(0,a.jsxs)("label",{className:"mb-4 block",children:[(0,a.jsx)("span",{className:"mb-1.5 block text-xs text-gray-500",children:"Title *"}),(0,a.jsx)("input",{required:!0,value:k.title,onChange:M("title"),placeholder:"Cursor Rules — new page",className:"h-10 w-full border border-dashed border-gray-300 px-3 text-sm outline-none hover:border-gray-400 focus:border-gray-600"})]}),(0,a.jsxs)("label",{className:"mb-4 block",children:[(0,a.jsx)("span",{className:"mb-1.5 block text-xs text-gray-500",children:"Description"}),(0,a.jsx)("textarea",{value:k.description,onChange:M("description"),rows:4,placeholder:"Short summary shown on the notifications page",className:"w-full border border-dashed border-gray-300 px-3 py-2 text-sm outline-none hover:border-gray-400 focus:border-gray-600"})]}),(0,a.jsxs)("label",{className:"mb-4 block",children:[(0,a.jsx)("span",{className:"mb-1.5 block text-xs text-gray-500",children:"Link"}),(0,a.jsx)("input",{value:k.link,onChange:M("link"),placeholder:"/cursor-rules",className:"h-10 w-full border border-dashed border-gray-300 px-3 text-sm outline-none hover:border-gray-400 focus:border-gray-600"})]}),(0,a.jsxs)("label",{className:"mb-5 block",children:[(0,a.jsx)("span",{className:"mb-1.5 block text-xs text-gray-500",children:"Banner image URL (optional)"}),(0,a.jsx)("input",{value:k.banner,onChange:M("banner"),placeholder:"https://...",className:"h-10 w-full border border-dashed border-gray-300 px-3 text-sm outline-none hover:border-gray-400 focus:border-gray-600"})]}),(0,a.jsx)("button",{type:"submit",disabled:!z,className:"inline-flex h-10 w-full items-center justify-center gap-2 border border-dashed border-gray-800 bg-gray-900 text-sm text-white hover:bg-black disabled:cursor-not-allowed disabled:opacity-50",children:R.isLoading?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(m.Z,{size:15,className:"animate-spin"}),"Creating…"]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(x.Z,{size:15}),"Create notification"]})})]}),(0,a.jsxs)("div",{className:"border border-dashed border-gray-200 bg-white",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between border-b border-dashed border-gray-200 px-5 py-3",children:[(0,a.jsxs)("p",{className:"text-sm font-medium text-gray-900",children:["All notifications (",E.length,")"]}),(0,a.jsx)("button",{type:"button",onClick:()=>L(),className:"text-xs text-gray-500 hover:text-gray-900",children:"Refresh"})]}),F?(0,a.jsx)("div",{className:"space-y-3 p-5",children:[1,2,3,4].map(e=>(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)(d.O,{height:16,width:"55%"}),(0,a.jsx)(d.O,{height:12,width:"90%"})]},e))}):T?(0,a.jsxs)("div",{className:"p-5 text-sm text-red-600",children:["Failed to load: ",(null==Z?void 0:Z.message)||"Unknown error"]}):0===E.length?(0,a.jsx)("div",{className:"p-8 text-center text-sm text-gray-500",children:"No notifications yet. Create one on the left."}):(0,a.jsx)("div",{className:"overflow-x-auto",children:(0,a.jsxs)("table",{className:"w-full min-w-[720px] border-collapse text-left",children:[(0,a.jsx)("thead",{className:"border-b border-dashed border-gray-200 bg-gray-50",children:(0,a.jsxs)("tr",{className:"text-xs uppercase tracking-wider text-gray-500",children:[(0,a.jsx)("th",{className:"px-4 py-3",children:"Title"}),(0,a.jsx)("th",{className:"px-4 py-3",children:"Link"}),(0,a.jsx)("th",{className:"px-4 py-3",children:"Date"}),(0,a.jsx)("th",{className:"w-24 px-4 py-3 text-right",children:"Action"})]})}),(0,a.jsx)("tbody",{children:E.map(e=>{let t=(0,f.fV)(e.createdAt);return(0,a.jsxs)("tr",{className:"border-b border-dashed border-gray-200 align-top last:border-b-0 hover:bg-gray-50/70",children:[(0,a.jsxs)("td",{className:"px-4 py-3",children:[(0,a.jsx)("p",{className:"font-medium text-gray-900",children:e.title}),e.description&&(0,a.jsx)("p",{className:"mt-1 max-w-md text-xs leading-5 text-gray-500 line-clamp-2",children:e.description})]}),(0,a.jsx)("td",{className:"px-4 py-3",children:(0,a.jsx)("code",{className:"break-all text-xs text-gray-600",children:e.link||"—"})}),(0,a.jsx)("td",{className:"px-4 py-3 text-xs text-gray-500",children:t?"".concat(t.date," ").concat(t.month," ").concat(t.year):"—"}),(0,a.jsx)("td",{className:"px-4 py-3 text-right",children:(0,a.jsxs)("button",{type:"button",onClick:()=>O(e.id,e.title),disabled:C===e.id,className:"inline-flex items-center gap-1.5 border border-dashed border-red-200 px-2.5 py-1.5 text-xs text-red-600 hover:bg-red-50 disabled:opacity-50",children:[C===e.id?(0,a.jsx)(m.Z,{size:13,className:"animate-spin"}):(0,a.jsx)(h.Z,{size:13}),"Delete"]})})]},e.id)})})]})})]})]})})]})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(o(),{children:[(0,a.jsx)("title",{children:"Admin Notifications | iHateReading"}),(0,a.jsx)("meta",{name:"robots",content:"noindex, nofollow"},"robots")]}),(0,a.jsx)("div",{className:"mx-auto min-h-screen max-w-xl px-6 py-20",children:(0,a.jsxs)("div",{className:"border border-dashed border-red-200 bg-red-50 p-8 text-red-700",children:[(0,a.jsx)("p",{className:"text-xl font-semibold",children:"Access denied"}),(0,a.jsx)("p",{className:"mt-2 text-sm",children:"This page is restricted to admin accounts."})]})})]}):(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(o(),{children:[(0,a.jsx)("title",{children:"Admin Notifications | iHateReading"}),(0,a.jsx)("meta",{name:"robots",content:"noindex, nofollow"},"robots")]}),(0,a.jsx)("div",{className:"mx-auto min-h-screen max-w-xl px-6 py-20",children:(0,a.jsxs)("div",{className:"border border-dashed border-gray-200 bg-white p-8",children:[(0,a.jsx)("p",{className:"text-xl font-semibold text-gray-900",children:"Admin only"}),(0,a.jsx)("p",{className:"mt-2 text-sm text-gray-600",children:"Sign in with your admin account to manage notifications."}),(0,a.jsx)("button",{type:"button",onClick:()=>w(!0),className:"mt-6 border border-dashed border-gray-300 bg-gray-900 px-4 py-2 text-sm text-white hover:bg-black",children:"Login"})]})}),(0,a.jsx)(b.Z,{open:v,setOpen:w,isUserLoggedIn:l})]})}},96914:function(e,t,s){"use strict";s.d(t,{fV:function(){return a}}),s(45843);let a=e=>{if(!e)return null;try{let t;if("function"==typeof e.toDate)t=e.toDate();else if("number"==typeof e.seconds){let s=e.nanoseconds||0;t=new Date(1e3*e.seconds+Math.floor(s/1e6))}else t=e instanceof Date?e:new Date(e);if(Number.isNaN(t.getTime()))return null;let s=t.toString().split(" ");return{day:s[0],date:s[2],month:s[1],year:s[3]}}catch(e){return null}}}},function(e){e.O(0,[5843,2888,9774,179],function(){return e(e.s=64553)}),_N_E=e.O()}]);

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.