PageSourceSearch

https://teachmo.ai/assets/Notifications-CQ3mc53Z.js

js teachmo.ai collected 2026-10-05 17:08:19 UTC 7,146 bytes, 1 lines download raw bytes

1import{r as l,j as t,L as P}from"./vendor-react-BDlPBQ8H.js";import{l as M,m as F}from"./notifications-C4Q5yFQu.js";import{t as U}from"./messages-D5l_qsZ3.js";import{L as W}from"./index-C9I8CK0-.js";import{u as D}from"./useAuth-uXggdIqN.js";import{c as g}from"./cn-2dOUpm6k.js";import{t as G}from"./vendor-ui-helpers-BA9Ou6yF.js";import"./http-BKZdOg30.js";import"./vendor-nhost-yQ8TKvUP.js";import"./vendor-misc-BcNut0Sq.js";import"./vendor-radix-CoZ84gME.js";import"./vendor-interactions-B-90v6Vt.js";import"./vendor-sentry-B_mZGnMZ.js";const v={es:"Spanish",fr:"French",de:"German",it:"Italian",pt:"Portuguese",zh:"Chinese","zh-cn":"Chinese (Simplified)","zh-tw":"Chinese (Traditional)",ja:"Japanese"};function z(s){const o=(s||"").trim().toLowerCase();if(!o||o==="en"||o.startsWith("en-"))return null;const u=o.split("-")[0]??"",i=v[o]?o:v[u]?u:null;if(!i)return null;const d=v[i];return d?{code:i,label:d}:null}function E(s,o){return`${s}:${o}`}const T={info:"bg-blue-50 text-blue-700 border-blue-100",warning:"bg-amber-50 text-amber-800 border-amber-100",critical:"bg-red-50 text-red-700 border-red-100"},I={source:"Related update",preview:"Preview",job:"Details",run:"More details"},$="We could not load notifications right now. Please refresh or try again later.",J="We could not update that notification. Please try again.";function K(s){if(!s)return"Just now";try{return G(new Date(s),{addSuffix:!0})}catch{return s}}function B({metadata:s}){const o=s!=null&&s.links&&typeof s.links=="object"?s.links:{},u=Object.entries(o).filter(i=>{const[,d]=i;return typeof d=="string"&&!!d});return u.length?t.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:u.map(([i,d])=>t.jsxs("a",{href:d,className:"inline-flex items-center text-sm font-medium text-emerald-700 hover:text-emerald-800",target:"_blank",rel:"noreferrer",children:[I[i]||"Open"," →"]},i))}):null}function le(){const[s,o]=l.useState([]),[u,i]=l.useState(!0),[d,p]=l.useState(""),[x,A]=l.useState(!1),[_,S]=l.useState({}),[c,y]=l.useState(null),[b,N]=l.useState({}),[R,j]=l.useState({}),[k,f]=l.useState(""),{user:m}=D(),L=l.useMemo(()=>s.filter(e=>!e.read_at).length,[s]);l.useEffect(()=>{let e=!0;const r=m==null?void 0:m.id;if(y(null),!!r)return W(r).then(a=>{e&&y(z(a==null?void 0:a.language))}).catch(()=>{e&&y(null)}),()=>{e=!1}},[m==null?void 0:m.id]),l.useEffect(()=>{N({}),j({}),f("")},[c==null?void 0:c.code,m==null?void 0:m.id]);const O=async e=>{if(!c)return;const r=E(e.id,c.code);if(Object.prototype.hasOwnProperty.call(b,r)){N(a=>{const n={...a};return delete n[r],n});return}j(a=>({...a,[r]:!0})),f("");try{const{translatedText:a}=await U({text:e.body,targetLanguage:c.code}),n=(a??"").trim();if(!n){f("We could not translate that notification. Please try again.");return}N(h=>({...h,[r]:n}))}catch(a){console.error("[Notifications] Failed to translate notification:",a),f("We could not translate that notification. Please try again.")}finally{j(a=>{const n={...a};return delete n[r],n})}},w=l.useCallback(async()=>{i(!0);try{const e=await M({limit:50,unreadOnly:x});o(Array.isArray(e)?e:[]),p("")}catch(e){console.error("[Notifications] Failed to load notifications:",e),p($)}finally{i(!1)}},[x]);l.useEffect(()=>{w()},[w]);const C=async e=>{if(e){S(r=>({...r,[e]:!0}));try{await F(e);const r=new Date().toISOString();o(a=>a.map(n=>n.id===e?{...n,read_at:r}:n))}catch(r){console.error("[Notifications] Failed to mark notification as read:",r),p(J)}finally{S(r=>({...r,[e]:!1}))}}};return t.jsxs("div",{className:"p-6 space-y-4",children:[t.jsxs("header",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-sm text-gray-500",children:"Updates from your school, family account, events, and reminders"}),t.jsx("h1",{className:"text-3xl font-semibold text-gray-900",children:"Notifications"}),t.jsxs("p",{className:"text-sm text-gray-600",children:["Showing the latest alerts",x?" (unread only)":"",". Unread: ",L]})]}),t.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.jsx(P,{to:"/notification-preferences",className:"inline-flex items-center rounded-lg border border-gray-200 bg-white px-3 py-2 text-sm font-medium text-gray-800 shadow-sm hover:bg-gray-50",children:"Preferences"}),t.jsx("button",{type:"button",onClick:()=>A(e=>!e),className:g("inline-flex items-center rounded-lg border px-3 py-2 text-sm font-medium shadow-sm transition-colors",x?"border-emerald-200 bg-emerald-50 text-emerald-800":"border-gray-200 bg-white text-gray-800"),children:x?"Show all notifications":"Filter unread"}),t.jsx("button",{type:"button",onClick:()=>void w(),className:"inline-flex items-center rounded-lg border border-gray-200 bg-white px-3 py-2 text-sm font-medium text-gray-800 shadow-sm hover:bg-gray-50",children:"Refresh"})]})]}),d&&!u&&t.jsx("div",{className:"rounded-lg border border-red-100 bg-red-50 p-4 text-sm text-red-700",role:"alert",children:d}),k&&t.jsx("div",{className:"rounded-lg border border-red-100 bg-red-50 p-4 text-sm text-red-700",role:"alert",children:k}),u?t.jsx("p",{className:"text-gray-600",children:"Loading notifications…"}):d?null:s.length===0?t.jsxs("div",{className:"rounded-lg border border-gray-100 bg-white p-6 shadow-sm",children:[t.jsx("p",{className:"font-semibold text-gray-900",children:"No notifications yet"}),t.jsx("p",{className:"text-sm text-gray-600",children:"We will alert you here when there are school updates, reminders, or family account changes."})]}):t.jsx("ul",{className:"space-y-3",children:s.map(e=>t.jsxs("li",{className:g("rounded-lg border bg-white p-4 shadow-sm transition-colors",e.read_at?"border-gray-100":"border-emerald-100"),children:[t.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:g("inline-flex items-center rounded-full border px-2 py-0.5 text-xs font-semibold",T[e.severity||"info"]||T.info),children:e.severity||"info"}),t.jsx("p",{className:"text-sm text-gray-500",children:K(e.created_at)})]}),t.jsx("button",{type:"button",disabled:!!e.read_at||_[e.id],onClick:()=>void C(e.id),className:g("text-sm font-medium",e.read_at?"text-gray-400 cursor-not-allowed":"text-emerald-700 hover:text-emerald-800"),children:e.read_at?"Read":"Mark as read"})]}),t.jsxs("div",{className:"mt-2 space-y-1",children:[t.jsx("h3",{className:"text-lg font-semibold text-gray-900",children:e.title}),t.jsx("p",{className:"text-sm text-gray-700 whitespace-pre-line",children:e.body}),c&&(()=>{var h;const r=E(e.id,c.code),a=Object.prototype.hasOwnProperty.call(b,r),n=!!R[r];return t.jsxs(t.Fragment,{children:[a&&t.jsx("p",{className:"mt-1 rounded-md bg-gray-50 p-2 text-sm text-gray-800 whitespace-pre-line",lang:c.code,children:b[r]}),((h=e.body)==null?void 0:h.trim())&&t.jsx("button",{type:"button",onClick:()=>void O(e),disabled:n,className:"text-sm font-medium text-emerald-700 hover:text-emerald-800 disabled:text-gray-400",children:n?"Translating…":a?"Hide translation":`Translate to ${c.label}`})]})})(),t.jsx(B,{metadata:e.metadata})]})]},e.id))})]})}export{le 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.