PageSourceSearch

https://founder-spark-63.lovable.app/assets/Discovery-DZiITOFY.js

js founder-spark-63.lovable.app collected 2026-10-03 03:31:57 UTC 13,524 bytes, 1 lines download raw bytes

1import{b as W,u as k,j as e}from"./query-_koPiPsI.js";import{f as V,r as m}from"./react-vendor-h1rQ_Bae.js";import{f as J,s as f,W as X,B as g,C as h,S as T,a0 as v,e as G,T as Y,a as Z,b as _,k as C,d as A,L as N,E as ee,H as se,g as L}from"./index-Dq2zLArw.js";import{u as te,b as ae}from"./useAICitations-Bre4xwoH.js";import{H as ie}from"./HumansFromAICard-C3UZofTK.js";import{c as I,g as P}from"./geoScore-CmpoRK6f.js";import{u as ne}from"./usePublishedPosts-COsWyTJL.js";import{T as re}from"./trending-down-DhyNl6tg.js";import{A as M}from"./arrow-up-right-DgLfBzug.js";import"./ui-radix-CKwvnS8F.js";import"./supabase-DL6nu9mS.js";import"./charts-Xu79y1bN.js";import"./motion-nVmI7L5T.js";import"./users-B5SvTFTu.js";function ke(){const{user:i}=J(),d=V(),r=W(),[l,n]=m.useState(30),[a,p]=m.useState("unseen"),{data:x}=k({queryKey:["discovery-profile",i?.id],enabled:!!i,queryFn:async()=>{const{data:s}=await f.from("profiles").select("username").eq("id",i.id).single();return s}}),u=x?.username??void 0,{data:j=[],isLoading:F}=te(u,l),{data:E=[],isLoading:S}=ae(u,l,10),{data:y=[],isLoading:$}=ne(),{data:c=[],isLoading:z}=k({queryKey:["ranking-alerts-list",i?.id],enabled:!!i,queryFn:async()=>{const{data:s,error:t}=await f.from("ranking_alerts").select("id, query, alert_type, previous_position, current_position, change_amount, seen, created_at, article_id").eq("user_id",i.id).order("created_at",{ascending:!1}).limit(100);if(t)throw t;return s||[]}}),w=Array.from(new Set(c.map(s=>s.article_id).filter(Boolean))),{data:K={}}=k({queryKey:["ranking-article-lookup",w.sort().join(",")],enabled:w.length>0,queryFn:async()=>{const{data:s}=await f.from("posts").select("id, title, slug").in("id",w),t={};return(s||[]).forEach(o=>{t[o.id]={title:o.title,slug:o.slug}}),t}}),R=m.useMemo(()=>j.reduce((s,t)=>s+t.count,0),[j]),b=m.useMemo(()=>c.filter(s=>!s.seen).length,[c]),Q=m.useMemo(()=>c.filter(s=>(s.change_amount??0)>0||s.alert_type==="page_one").length,[c]),B=m.useMemo(()=>c.filter(s=>(s.change_amount??0)<0).length,[c]),H=async s=>{const{error:t}=await f.from("ranking_alerts").update({seen:!0}).eq("id",s);if(t){L.error("Could not mark seen");return}r.invalidateQueries({queryKey:["ranking-alerts-list"]}),r.invalidateQueries({queryKey:["unseen-ranking-alerts"]})},D=async()=>{const s=c.filter(o=>!o.seen).map(o=>o.id);if(s.length===0)return;const{error:t}=await f.from("ranking_alerts").update({seen:!0}).in("id",s);if(t)return L.error("Could not mark all seen");L.success(`Marked ${s.length} as seen`),r.invalidateQueries({queryKey:["ranking-alerts-list"]}),r.invalidateQueries({queryKey:["unseen-ranking-alerts"]})},O=m.useMemo(()=>c.filter(s=>{switch(a){case"unseen":return!s.seen;case"wins":return(s.change_amount??0)>0;case"drops":return(s.change_amount??0)<0;case"page1":return s.alert_type==="page_one"||(s.current_position??99)<=10;default:return!0}}),[c,a]);return e.jsxs("div",{className:"container mx-auto max-w-6xl p-6 space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-light tracking-tight flex items-center gap-2",children:[e.jsx(X,{className:"h-5 w-5"})," Discovery"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"How the world — humans and AI — is finding your work."})]}),e.jsx("div",{className:"flex items-center gap-1 text-xs",children:[7,30,90].map(s=>e.jsxs(g,{size:"sm",variant:l===s?"secondary":"ghost",onClick:()=>n(s),className:"h-7 px-2.5",children:[s,"d"]},s))})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs(h,{className:"p-4 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>d("/agent?topic=trending"),children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wider text-muted-foreground",children:[e.jsx(T,{className:"h-3.5 w-3.5"})," Trending Now"]}),e.jsx("div",{className:"text-sm font-medium mt-1",children:"What's the internet talking about?"}),e.jsx("div",{className:"text-xs text-muted-foreground mt-1",children:"Live web research → ride the wave with timely posts."})]}),e.jsxs(h,{className:"p-4 cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>d("/content-plan?mode=generate"),children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs uppercase tracking-wider text-muted-foreground",children:[e.jsx(v,{className:"h-3.5 w-3.5"})," Rank For This"]}
1),e.jsx("div",{className:"text-sm font-medium mt-1",children:"What keywords should I own?"}),e.jsx("div",{className:"text-xs text-muted-foreground mt-1",children:"Keyword research → a 30/60/90-day plan you can publish from."})]})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-4",children:[e.jsx(q,{icon:e.jsx(T,{className:"h-4 w-4"}),label:"AI visibility",primary:`${R}`,sub:j.length===0?`No AI bots in the last ${l} days`:j.slice(0,3).map(s=>`${s.label} ${s.count}`).join(" · ")}),e.jsx(q,{icon:e.jsx(G,{className:"h-4 w-4"}),label:"Search visibility",primary:`${c.length}`,sub:`▲ ${Q} wins · ▼ ${B} drops`}),e.jsx(le,{posts:y,loading:$})]}),e.jsxs(Y,{defaultValue:"ai",className:"w-full",children:[e.jsxs(Z,{children:[e.jsx(_,{value:"ai",children:"AI Citations"}),e.jsxs(_,{value:"rankings",children:["Rankings",b>0&&e.jsx(C,{variant:"secondary",className:"ml-2 h-4 px-1.5 text-[10px]",children:b})]}),e.jsx(_,{value:"geo",children:"GEO Health"})]}),e.jsxs(A,{value:"ai",className:"space-y-4 mt-4",children:[e.jsxs(h,{className:"p-4",children:[e.jsxs("h3",{className:"text-sm font-medium mb-3",children:["By AI engine · last ",l," days"]}),F?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(N,{className:"h-3.5 w-3.5 animate-spin"})," Loading…"]}):j.length===0?e.jsx(oe,{}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:j.map(s=>e.jsxs("div",{className:"rounded border bg-card p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground",children:s.label}),e.jsx("div",{className:"text-2xl font-light mt-1",children:s.count})]},s.label))})]}),e.jsx(ie,{username:u,days:l}),e.jsxs(h,{className:"p-4",children:[e.jsx("h3",{className:"text-sm font-medium mb-3",children:"Most-cited articles"}),S?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(N,{className:"h-3.5 w-3.5 animate-spin"})," Loading…"]}):E.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No AI-cited articles yet. Improve GEO scores to start showing up."}):e.jsx("ul",{className:"divide-y divide-border",children:E.map(s=>e.jsxs("li",{className:"py-2.5 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium truncate",children:s.title}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:Object.entries(s.byBot).sort((t,o)=>o[1]-t[1]).slice(0,4).map(([t,o])=>`${t} ${o}`).join(" · ")})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs(C,{variant:"outline",className:"text-xs",children:[s.total," visits"]}),e.jsxs(g,{size:"sm",variant:"ghost",onClick:()=>u&&window.open(`/user/${u}/${s.slug}`,"_blank"),children:["Open ",e.jsx(ee,{className:"ml-1 h-3 w-3"})]})]})]},s.slug))})]})]}),e.jsx(A,{value:"rankings",className:"space-y-4 mt-4",children:e.jsxs(h,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap mb-3",children:[e.jsx("div",{className:"flex items-center gap-1 flex-wrap",children:["unseen","all","wins","drops","page1"].map(s=>e.jsx(g,{size:"sm",variant:a===s?"secondary":"ghost",onClick:()=>p(s),className:"h-7 px-2.5 text-xs capitalize",children:s==="page1"?"Page 1":s},s))}),b>0&&e.jsxs(g,{size:"sm",variant:"outline",onClick:D,className:"h-7",children:[e.jsx(se,{className:"h-3.5 w-3.5 mr-1"})," Mark all seen"]})]}),z?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(N,{className:"h-3.5 w-3.5 animate-spin"})," Loading…"]}):O.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-6 text-center",children:c.length===0?"No ranking changes yet. Connect Google Search Console in Profile to start tracking.":"Nothing matches this filter."}):e.jsx("ul",{className:"divide-y divide-border",children:O.map(s=>{const t=s.article_id?K[s.article_id]:null,U=(s.change_amount??0)>0||s.alert_type==="page_one";return e.jsxs("li",{className:"py-3 flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium truncate",children:s.query}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5 flex items-center gap-2 flex-wrap",children:[t&&e.jsx("span",{className:"truncate max-w-xs",children:t.title}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[U?e.jsx(G,{className:"h-3 w-3 text-emerald-600"}):e.jsx(re,{className:"h-3 w-3 text-rose-600"}),s.previous_position!=null&&s.current_position!=null&&e.jsxs("span",{children:["#",Number(s.previous_position).toFixed(0)," → #",Number(s.current_position).toFixed(0)]}),s.alert_type==="page_one"&&e.jsxs(C,{variant:"secondary",className:"h-4 px-1.5 text-[10px]",children:[e.jsx(v,{className:"h-2.5 w-2.5 mr-0.5"})," Page 1"]})]}),e.jsx("span",{children:new Date(s.created_at).toLocaleDateString()})]})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[!s.seen&&e.jsx(g,{size:"sm",variant:"ghost",onClick:()=>H(s.id),className:"h-7",children:"Mark seen"}),e.jsx(g,{size:"sm",variant:"ghost",onClick:()=>d(`/content-plan?mode=generate&seedTopic=${encodeURIComponent(s.query)}`),className:"h-7",title:"Plan more content for this query",children:"Plan"}),t&&e.jsxs(g,{size:"sm",variant:"ghost",onClick:()=>d(`/editor/${s.article_id}`),className:"h-7",children:["Open ",e.jsx(M,{className:"ml-1 h-3 w-3"})]})]})]},s.id)})})]})}
1),e.jsx(A,{value:"geo",className:"space-y-4 mt-4",children:e.jsxs(h,{className:"p-4",children:[e.jsx("h3",{className:"text-sm font-medium mb-1",children:"Portfolio GEO health"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-4",children:"Articles ranked lowest-first. Fix the lowest-scoring articles to start being cited."}),$?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(N,{className:"h-3.5 w-3.5 animate-spin"})," Loading…"]}):y.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"No published articles yet. Publish an article to see GEO health."}):e.jsx(ce,{posts:y,onOpen:s=>d(`/editor/${s}`)})]})})]})]})}function q({icon:i,label:d,primary:r,sub:l}){return e.jsxs(h,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[i," ",d]}),e.jsx("div",{className:"text-3xl font-light mt-2",children:r}),e.jsx("div",{className:"text-xs text-muted-foreground mt-1 truncate",children:l})]})}function le({posts:i,loading:d}){const r=m.useMemo(()=>{if(i.length===0)return null;let l=0,n=0;for(const a of i){const p=I(a.title||"",a.content||"",a.meta_description||""),x=P(p);l+=x,x<70&&n++}return{avg:Math.round(l/i.length),belowGood:n}},[i]);return d?e.jsx(h,{className:"p-4",children:e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(N,{className:"h-3.5 w-3.5 animate-spin"})," GEO health"]})}):r?e.jsxs(h,{className:"p-4 relative",children:[e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsx(v,{className:"h-4 w-4"})," GEO health"]}),e.jsx("div",{className:"text-3xl font-light mt-2",children:r.avg}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-1",children:["Avg score · ",r.belowGood," need work"]})]}):e.jsx(q,{icon:e.jsx(v,{className:"h-4 w-4"}),label:"GEO health",primary:"—",sub:"Publish an article to score"})}function ce({posts:i,onOpen:d}){const r=m.useMemo(()=>i.map(n=>{const a=I(n.title||"",n.content||"",n.meta_description||""),p=P(a),x=a.checks.find(u=>!u.passed)?.label||null;return{post:n,pct:p,grade:a.grade,topFix:x}}),[i]),l=m.useMemo(()=>[...r].sort((n,a)=>n.pct-a.pct),[r]);return e.jsx("ul",{className:"divide-y divide-border",children:l.map(({post:n,pct:a,grade:p,topFix:x})=>{const u=a>=85?"bg-emerald-100 text-emerald-900":a>=70?"bg-blue-100 text-blue-900":a>=50?"bg-amber-100 text-amber-900":"bg-rose-100 text-rose-900";return e.jsxs("li",{className:"py-3 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium truncate",children:n.title}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5 truncate",children:x?`Fix: ${x}`:"All checks passing"})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full ${u}`,children:[p," · ",a]}),e.jsxs(g,{size:"sm",variant:"ghost",onClick:()=>d(n.id),className:"h-7",children:["Optimize ",e.jsx(M,{className:"ml-1 h-3 w-3"})]})]})]},n.id)})})}function oe(){return e.jsxs("div",{className:"text-sm text-muted-foreground space-y-2",children:[e.jsx("p",{children:"No AI bots have visited your articles in this range yet."}),e.jsxs("p",{className:"text-xs",children:["Tip: improve ",e.jsx("strong",{children:"GEO Health"})," on the next tab — articles with FAQ sections, statistics, and question-format headings get cited 3–5× more often by ChatGPT, Claude, and Perplexity."]})]})}export{ke 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.