PageSourceSearch

https://cryptonary.com/assets/AdminSearchAnalytics-CdSGCmkZ.js

js cryptonary.com collected 2026-10-02 10:24:58 UTC 13,819 bytes, 1 lines download raw bytes

1import{aj as V,W as K,j as e,O as G,B as D,J as M,am as N,b5 as J,V as Z}from"./index-CSBsxxXo.js";import{r as d,L as v,e as X}from"./ui-icons-CK9lrQxE.js";import{A as Y,a as ee,b as te}from"./avatar-B6zxV-eR.js";import{A as se}from"./AdminPageHeader-DGYUwrtk.js";import{S as F,a as I,b as O,c as E,d as R}from"./select-ByUdccAe.js";import{T as re,a as ae,b as S,c as f,d as ne,e as m}from"./table-DhxAyyMD.js";import{s as Q}from"./home-startup-core-Dtjb9Klo.js";import{w as le,h as oe,t as ie}from"./ui-icons-deferred-Bu5t7E0l.js";import"./index-BZuCPabT.js";import"./index-BbLuf0Sh.js";import"./index-Bg46vq2q.js";import"./index-CtKn_Q1M.js";(function(){try{var r=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},a=new r.Error().stack;a&&(r._sentryDebugIds=r._sentryDebugIds||{},r._sentryDebugIds[a]="b2ee7cb9-dc8e-4e76-994f-e707e320295c",r._sentryDebugIdIdentifier="sentry-dbid-b2ee7cb9-dc8e-4e76-994f-e707e320295c")}catch{}})();const k=[{label:"24 hours",shortLabel:"24h",value:"1",days:1},{label:"7 days",shortLabel:"7d",value:"7",days:7},{label:"30 days",shortLabel:"30d",value:"30",days:30},{label:"90 days",shortLabel:"90d",value:"90",days:90},{label:"All time",shortLabel:"All time",value:"all",days:3650}],U=[{label:"All surfaces",value:"all"},{label:"Global",value:"global"},{label:"Content",value:"content"},{label:"Community",value:"community"},{label:"Markets",value:"market"},{label:"Research",value:"research"},{label:"Intel",value:"intel"}];function x(r){return N(r??0)}function z(r){if(!r)return"Not seen";const a=new Date(r);return Number.isNaN(a.getTime())?"Not seen":a.toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function ce(r){var a;return((a=U.find(t=>t.value===r))==null?void 0:a.label.replace("All surfaces","All"))??r}function j({label:r,value:a,sublabel:t}){return e.jsxs("div",{className:"min-h-[66px] min-w-0 border-b border-r border-border/40 bg-muted/10 px-3 py-2.5",children:[e.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[e.jsx("p",{className:"text-base font-semibold text-foreground tabular-nums",children:a}),e.jsx("p",{className:"truncate text-[12px] font-medium text-muted-foreground",children:r})]}),e.jsx("p",{className:"mt-0.5 truncate text-[11px] text-muted-foreground",children:t})]})}function q({label:r,sortKey:a,activeKey:t,direction:o,onSort:l,className:u}){const n=t===a;return e.jsxs("button",{type:"button",onClick:()=>l(a),className:M("inline-flex items-center gap-1 rounded-sm text-[11px] font-medium uppercase tracking-wide text-muted-foreground transition-colors hover:text-foreground",n&&"text-foreground",u),children:[r,e.jsx("span",{className:"text-[10px] normal-case text-muted-foreground",children:n?o==="asc"?"Asc":"Desc":"Sort"})]})}function ue(r){return Array.isArray(r)?r.map(a=>{if(!a||typeof a!="object")return null;const t=a,o=t.user_id;return typeof o!="string"?null:{user_id:o,display_name:t.display_name==null||typeof t.display_name=="string"?t.display_name:null,username:t.username==null||typeof t.username=="string"?t.username:null,avatar_url:t.avatar_url==null||typeof t.avatar_url=="string"?t.avatar_url:null,event_count:typeof t.event_count=="number"&&Number.isFinite(t.event_count)?t.event_count:0,submit_count:typeof t.submit_count=="number"&&Number.isFinite(t.submit_count)?t.submit_count:0,click_count:typeof t.click_count=="number"&&Number.isFinite(t.click_count)?t.click_count:0,last_at:typeof t.last_at=="string"?t.last_at:""}}).filter(a=>a!==null):[]}function de(r){var o,l;const a=(o=r.display_name)==null?void 0:o.trim();if(a)return a;const t=(l=r.username)==null?void 0:l.trim();return t?`@${t}`:"Member"}function me(r){var o,l;const a=(o=r.display_name)==null?void 0:o.trim();if(a){const u=a.split(/\s+/).filter(Boolean);return u.length>=2?(u[0][0]+u[1][0]).toUpperCase():a.slice(0,2).toUpperCase()}const t=(l=r.username)==null?void 0:l.trim();return t?t.slice(0,2).toUpperCase():"?"}function xe({queryHash:r,windowDays:a,surface:t,isOpen:o}){const l=K({queryKey:["admin-search-opportunity-contributors",r,a,t],enabled:o,queryFn:async()=>{const{data:n,error:g}=await Q.rpc("admin_search_opportunity_contributors",{p_query_hash:r,p_days:a,p_
1surface:t,p_limit:12});if(g)throw g;return ue(n)},staleTime:6e4});if(!o)return null;if(l.isLoading)return e.jsxs("div",{className:"mt-3 flex items-center gap-2 rounded-lg border border-border/50 bg-muted/10 px-3 py-2.5 text-[12px] text-muted-foreground",children:[e.jsx(v,{className:"h-3.5 w-3.5 shrink-0 animate-spin","aria-hidden":!0}),"Loading members…"]});if(l.isError)return e.jsx("p",{className:"mt-3 rounded-lg border border-destructive/20 bg-destructive/5 px-3 py-2 text-[12px] text-destructive",children:J(l.error,"Could not load members for this search.")});const u=l.data??[];return u.length===0?e.jsx("p",{className:"mt-3 text-[12px] text-muted-foreground",children:"No members in this window for the selected surface filter."}):e.jsx("ul",{className:"mt-3 space-y-1.5 rounded-lg border border-border/50 bg-muted/10 p-2",children:u.map(n=>e.jsx("li",{children:e.jsxs(Z,{to:`/admin/profiles/${n.user_id}`,className:"flex min-w-0 items-center gap-2.5 rounded-md px-1.5 py-1.5 text-left transition-colors hover:bg-muted/40",children:[e.jsxs(Y,{className:"h-7 w-7 shrink-0 border border-border/40",children:[n.avatar_url?e.jsx(ee,{src:n.avatar_url,alt:"",className:"object-cover"}):null,e.jsx(te,{className:"text-[10px] font-medium",children:me(n)})]}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[13px] font-medium text-foreground",children:de(n)}),n.username?e.jsxs("span",{className:"block truncate text-[12px] text-muted-foreground",children:["@",n.username]}):null]}),e.jsxs("span",{className:"shrink-0 text-right text-[11px] leading-tight text-muted-foreground",children:[e.jsx("span",{className:"tabular-nums text-foreground",children:N(n.event_count)})," ","events",e.jsxs("span",{className:"mt-0.5 block text-[10px]",children:[N(n.submit_count)," submit ·"," ",N(n.click_count)," click"]}),n.last_at?e.jsxs("span",{className:"mt-0.5 block text-[10px]",children:["Last ",z(n.last_at)]}):null]})]})},n.user_id))})}function ke(){const[r,a]=d.useState("30"),[t,o]=d.useState("all"),[l,u]=d.useState(null),[n,g]=d.useState("search_count"),[p,L]=d.useState("desc"),{isFullAdmin:T,isLoading:H}=V(),A=k.find(s=>s.value===r)??k[2],_=A.days,C=t==="all"?null:t;d.useEffect(()=>{u(null)},[t,r]);const h=K({queryKey:["admin-search-opportunities",r,t],enabled:T,queryFn:async()=>{const{data:s,error:c}=await Q.rpc("admin_search_opportunities",{p_days:_,p_limit:80,p_surface:C});if(c)throw c;return s??{generated_at:new Date().toISOString(),window_days:_,totals:{searches:0,zero_result_searches:0,unique_queries:0,spikes:0},opportunities:[]}}}),i=h.data,b=(i==null?void 0:i.opportunities)??[],P=d.useMemo(()=>b.filter(s=>s.zero_result_count>0).length,[b]),$=d.useMemo(()=>{const s=p==="asc"?1:-1;return[...b].sort((c,y)=>{if(n==="query")return c.query.localeCompare(y.query,void 0,{sensitivity:"base"})*s;if(n==="search_count")return(c.search_count-y.search_count)*s;const B=c.last_seen?new Date(c.last_seen).getTime():0,W=y.last_seen?new Date(y.last_seen).getTime():0;return(B-W)*s})},[b,p,n]),w=s=>{if(s===n){L(c=>c==="asc"?"desc":"asc");return}g(s),L(s==="query"?"asc":"desc")};return H?e.jsx("div",{className:"flex min-h-[50vh] items-center justify-center text-muted-foreground",children:e.jsx(v,{className:"h-6 w-6 animate-spin","aria-label":"Loading search analytics"})}):T?e.jsxs("div",{className:"mx-auto max-w-7xl space-y-5 px-3 pb-8 pt-4 sm:px-4 sm:pt-5 md:px-6 md:pt-6",children:[e.jsx(se,{icon:X,title:"Search trends",description:"Search demand from member queries and result opens."}),e.jsx("div",{className:"border-b border-border/60 pb-4",children:e.jsx("div",{className:"-mx-3 overflow-x-auto px-3 [scrollbar-width:none] sm:mx-0 sm:px-0 [&::-webkit-scrollbar]:hidden",children:e.jsxs("div",{className:"flex min-w-max items-center gap-2",children:[e.jsxs(F,{value:r,onValueChange:s=>a(s),children:[e.jsx(I,{className:"h-8 w-[140px] bg-muted/20 px-2.5 text-[12px]",children:e.jsx(O,{placeholder:"Time frame"})}),e.jsx(E,{align:"start",children:k.map(s=>e.jsx(R,{value:s.value,children:s.label},s.value))})]}),e.jsxs(F,{value:t,onValueChange:s=>o(s),children:[e.jsx(I,{className:"h-8 w-[160px] bg-muted/20 px-2.5 text-[12px]",children:e.jsx(O,{placeholder:"Surface"})}),e.jsx(E,{align:"start",children:U.map(s=>e.jsx(R,{value:s.value,children:s.label},s.value))})]}),e.jsxs(D,{type:"button",variant:"outline",size:"sm",className:"h-8 shrink-0 rounded-md text-[12px]",onClick:()=>void h.refetch(),disabled:h.isFetching,children:[h.isFetching?e.jsx(v,{className:"mr-1.5 h-3.5 w-3.5 animate-spin"}):null,"Refresh"]})]})})}),e.jsxs("div",{className:"grid grid-cols-2 overflow-hidden border-y border-l border-border/40 xl:grid-cols-4",children:[e.jsx(j,{label:"Searches",value:x((i==null?void 0:i.totals.searches)??0),sublabel:r==="all"?"All time":`Last ${A.shortLabel}`}),e.jsx(j,{label:"Unique Queries",value:x((i==null?void 0:i.totals.unique_queries)??0),sublabel:"Grouped phrases"}
1),e.jsx(j,{label:"Zero Results",value:x((i==null?void 0:i.totals.zero_result_searches)??0),sublabel:`${x(P)} affected`}),e.jsx(j,{label:"Spikes",value:x((i==null?void 0:i.totals.spikes)??0),sublabel:"Detected"})]}),e.jsxs("section",{className:"space-y-3",children:[e.jsx("div",{className:"flex flex-col gap-2 border-b border-border/60 pb-3 sm:flex-row sm:items-center sm:justify-between",children:e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-medium text-foreground",children:"Search Phrase Queue"}),e.jsx("p",{className:"text-[12px] text-muted-foreground",children:"Compact view sorted by search demand."})]})}),h.isLoading?e.jsx("div",{className:"flex min-h-48 items-center justify-center text-muted-foreground",children:e.jsx(v,{className:"h-6 w-6 animate-spin","aria-label":"Loading opportunities"})}):b.length===0?e.jsxs("div",{className:"flex min-h-48 flex-col items-center justify-center px-6 text-center",children:[e.jsx(le,{className:"mb-3 h-8 w-8 text-muted-foreground/40","aria-hidden":!0}),e.jsx("p",{className:"text-sm font-medium text-foreground",children:"No search opportunities yet"}),e.jsx("p",{className:"mt-1 max-w-md text-sm text-muted-foreground",children:"Submitted searches will appear here once users search from global, research, community, intel, or market surfaces."})]}):e.jsx("div",{className:"overflow-x-auto border-y border-border/50",children:e.jsxs(re,{className:"min-w-[860px] text-[13px]",children:[e.jsx(ae,{children:e.jsxs(S,{className:"border-border/60 bg-muted/20 hover:bg-muted/20",children:[e.jsx(f,{className:"min-w-[320px] px-4 py-2.5 text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:e.jsx(q,{label:"Phrase",sortKey:"query",activeKey:n,direction:p,onSort:w})}),e.jsx(f,{className:"w-28 px-3 py-2.5 text-center text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:e.jsx(q,{label:"Searches",sortKey:"search_count",activeKey:n,direction:p,onSort:w,className:"justify-center"})}),e.jsx(f,{className:"min-w-[150px] px-3 py-2.5 text-center text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:e.jsx(q,{label:"Last Seen",sortKey:"last_seen",activeKey:n,direction:p,onSort:w,className:"justify-center"})}),e.jsx(f,{className:"min-w-[160px] px-3 py-2.5 text-center text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Surface"}),e.jsx(f,{className:"w-20 px-3 py-2.5 text-center text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Detail"})]})}),e.jsx(ne,{children:$.map(s=>e.jsxs(d.Fragment,{children:[e.jsxs(S,{className:"border-border/40 hover:bg-muted/20",children:[e.jsx(m,{className:"max-w-[420px] px-4 py-2.5 align-middle",children:e.jsx("span",{className:"block truncate text-sm font-medium text-foreground",children:s.query})}),e.jsx(m,{className:"px-3 py-2.5 text-center text-sm font-medium tabular-nums text-foreground",children:x(s.search_count)}),e.jsx(m,{className:"px-3 py-2.5 text-center text-[12px] text-muted-foreground",children:z(s.last_seen)}),e.jsx(m,{className:"px-3 py-2.5",children:e.jsxs("div",{className:"flex justify-center gap-1",children:[s.surfaces.length>0?s.surfaces.slice(0,2).map(c=>e.jsx("span",{className:"rounded border border-border/50 bg-muted/20 px-1.5 py-0.5 text-[11px] text-muted-foreground",children:ce(c)},c)):e.jsx("span",{className:"text-[12px] text-muted-foreground",children:"Unknown"}),s.surfaces.length>2?e.jsxs("span",{className:"rounded border border-border/50 bg-muted/20 px-1.5 py-0.5 text-[11px] text-muted-foreground",children:["+",s.surfaces.length-2]}):null]})}),e.jsx(m,{className:"px-3 py-2.5 text-center",children:e.jsx(D,{type:"button",variant:"ghost",size:"sm",className:"h-8 w-8 rounded-md p-0 text-muted-foreground/90 hover:text-foreground",onClick:()=>u(c=>c===s.query_hash?null:s.query_hash),"aria-label":`${l===s.query_hash?"Hide":"Show"} top members for ${s.query}`,children:e.jsx(oe,{className:M("h-4 w-4 opacity-70 transition-transform",l===s.query_hash&&"rotate-180"),"aria-hidden":!0})})})]}),l===s.query_hash?e.jsx(S,{className:"border-border/40 bg-muted/10 hover:bg-muted/10",children:e.jsx(m,{colSpan:5,className:"px-4 py-3",children:e.jsxs("div",{className:"max-w-3xl",children:[e.jsxs("div",{className:"mb-1 flex items-center gap-2 text-[12px] font-medium text-muted-foreground",children:[e.jsx(ie,{className:"h-3.5 w-3.5","aria-hidden":!0}),'Top members for "',s.query,'"']}),e.jsx(xe,{queryHash:s.query_hash,windowDays:_,surface:C,isOpen:!0})]})})}):null]},s.query_hash))})]})})]})]}):e.jsx(G,{to:"/admin/studio",replace:!0})}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.