PageSourceSearch

https://agentorion.ai/assets/UnreadLeadsContext-HCzNNGvR.js

js agentorion.ai collected 2026-10-05 15:13:37 UTC 2,924 bytes, 1 lines download raw bytes

1import{r as a,j as x}from"./vendor-ui-NatVVUt6.js";import{s as _}from"./client-ClH0Aa2d.js";import{useAuth as R}from"./AuthContext-BgCTybtx.js";import{u as T}from"./index-DeQi2Bsp.js";import"./vendor-react-CtUlU_Ct.js";const U="agentorion-leads-last-visit",I=a.createContext({unreadCount:0,clearUnread:()=>{},addUnread:()=>{}}),k=()=>a.useContext(I),h=f=>Array.isArray(f)&&f.includes("partial");function D({children:f}){const{user:o}=R(),{toast:b}=T(),[v,m]=a.useState(0),c=a.useRef(new Map),d=a.useRef(new Set),l=a.useRef(new Set),w=a.useCallback((n,s)=>{const r=n.name,e=n.temperature,t=r?`New lead — ${r}`:"New lead captured";let i;e&&s?i=`${e.charAt(0).toUpperCase()+e.slice(1)} lead from ${s}`:s?i=`New lead from ${s}`:i="A new lead just submitted your funnel.",b({title:t,description:i,duration:6e3})},[b]),A=a.useCallback(()=>{m(0);try{localStorage.setItem(U,new Date().toISOString())}catch{}},[]),p=a.useCallback(n=>{m(s=>s+1),w(n,n.funnel_name??c.current.get(n.funnel_id)??null)},[w]);return a.useEffect(()=>{if(!o){m(0),c.current.clear(),d.current.clear(),l.current.clear();return}let n=!0;(async()=>{const{data:r}=await _.from("funnels").select("id, name, notifications_enabled").eq("user_id",o.id);if(!n)return;const e=[],t=new Map,i=new Set;(r||[]).forEach(u=>{e.push(u.id),t.set(u.id,u.name),u.notifications_enabled!==!1&&i.add(u.id)}),c.current=t,d.current=i;const C=(()=>{try{return localStorage.getItem(U)}catch{return null}})();if(e.length>0){const u=Array.from(i);if(u.length>0){const{data:E}=await _.from("funnel_leads").select("id, tags, funnel_id").in("funnel_id",u).gt("created_at",C||"1970-01-01").limit(500);if(!n)return;const S=(E||[]).filter(g=>!h(g.tags));m(S.length),S.forEach(g=>l.current.add(g.id))}}})();const s=_.channel(`unread-leads-${o.id}`).on("postgres_changes",{event:"INSERT",schema:"public",table:"funnel_leads"},r=>{if(!n)return;const e=r.new;c.current.has(e.funnel_id)&&d.current.has(e.funnel_id)&&(h(e.tags)||l.current.has(e.id)||(l.current.add(e.id),p({id:e.id,name:e.name,email:e.email,temperature:e.temperature,funnel_id:e.funnel_id,created_at:e.created_at})))}).on("postgres_changes",{event:"UPDATE",schema:"public",table:"funnel_leads"},r=>{if(!n)return;const e=r.old,t=r.new;c.current.has(t.funnel_id)&&d.current.has(t.funnel_id)&&(!h(e==null?void 0:e.tags)||h(t.tags)||l.current.has(t.id)||(l.current.add(t.id),p({id:t.id,name:t.name,email:t.email,temperature:t.temperature,funnel_id:t.funnel_id,created_at:t.created_at})))}).on("postgres_changes",{event:"UPDATE",schema:"public",table:"funnels",filter:`user_id=eq.${o.id}`},r=>{if(!n)return;const e=r.new;e!=null&&e.id&&(e.notifications_enabled===!1?d.current.delete(e.id):d.current.add(e.id),e.name&&c.current.set(e.id,e.name))}).subscribe();return()=>{n=!1,_.removeChannel(s)}},[o,p]),x.jsx(I.Provider,{value:{unreadCount:v,clearUnread:A,addUnread:p},children:f})}export{D as UnreadLeadsProvider,k as useUnreadLeads};

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.