PageSourceSearch

https://story-os.ai/assets/NicheReports-B66cxMLa.js

js story-os.ai collected 2026-10-05 15:11:33 UTC 11,827 bytes, 8 lines download raw bytes

1import{j as e}from"./ui-vendor-sd9EibYn.js";import{r as x}from"./react-vendor-CHx29PyI.js";import{g as B,k as y,m as $,D as w,al as T,aa as C,ah as E,aH as L,az as F,E as U}from"./index-Dk_EdvrQ.js";import{P as G}from"./PageHeader-CQok72LF.js";import{P as W}from"./PageContainer-BoQN3ZrA.js";import{C as l,b as o,c as d,a as r,d as b}from"./card-D5QUQiSF.js";import{S as K,a as X,b as J,c as Q,d as A}from"./select-p-iRORxZ.js";import{D as Y}from"./download-xCZ9aHP_.js";import{E as Z}from"./external-link-D3PpyxhL.js";import{f as M}from"./utils-vendor-Cchy62ty.js";import"./supabase-vendor-DQD4jYU5.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const V=B("ChartNoAxesColumnIncreasing",[["line",{x1:"12",x2:"12",y1:"20",y2:"10",key:"1vz5eb"}],["line",{x1:"18",x2:"18",y1:"20",y2:"4",key:"cun8e5"}],["line",{x1:"6",x2:"6",y1:"20",y2:"16",key:"hq0ia6"}]]);function he(){const[R,D]=x.useState([]),[f,z]=x.useState([]),[N,I]=x.useState([]),[g,O]=x.useState("all"),[S,k]=x.useState(!0);x.useEffect(()=>{P()},[]);async function P(){k(!0);try{const[s,h,a]=await Promise.all([y.from("niche_categories").select("*").order("name"),y.from("channel_registry").select("*"),y.from("channel_outliers").select("id, title, thumbnail_url, view_count, performance_score, youtube_channel_name, youtube_channel_id, video_id").eq("is_outlier",!0).order("performance_score",{ascending:!1}).limit(500)]);if(s.error)throw s.error;if(h.error)throw h.error;if(a.error)throw a.error;D(s.data||[]),z(h.data||[]),I(a.data||[])}catch(s){console.error("Error fetching data:",s),$.error("Failed to load niche data")}finally{k(!1)}}const u=x.useMemo(()=>{const s=[];return R.forEach(h=>{const a=f.filter(t=>t.niche_id===h.id);if(a.length===0)return;const _=new Set(a.map(t=>t.youtube_channel_id)),p=N.filter(t=>_.has(t.youtube_channel_id)),m=new Map;p.forEach(t=>{t.title.toLowerCase().replace(/[^\w\s]/g,"").split(/\s+/).filter(v=>v.length>3).forEach(v=>{m.set(v,(m.get(v)||0)+1)})});const c=Array.from(m.entries()).filter(([t,n])=>n>=2).sort((t,n)=>n[1]-t[1]).slice(0,10).map(([t])=>t);s.push({niche:h,channels:a.sort((t,n)=>(n.total_outliers||0)-(t.total_outliers||0)),topOutliers:p.slice(0,10),titlePatterns:c,stats:{totalChannels:a.length,totalVideos:a.reduce((t,n)=>t+n.total_videos_analyzed,0),totalOutliers:a.reduce((t,n)=>t+n.total_outliers,0),avgPerformance:a.length>0?a.reduce((t,n)=>t+(n.avg_performance_score||0),0)/a.filter(t=>t.avg_performance_score).length:0}})}),s.sort((h,a)=>a.stats.totalChannels-h.stats.totalChannels)},[R,f,N]),i=x.useMemo(()=>g==="all"?null:u.find(s=>s.niche.id===g)||null,[g,u]),j=x.useMemo(()=>({totalNiches:u.length,totalChannels:f.length,classifiedChannels:f.filter(s=>s.niche_id).length,totalOutliers:N.length}),[u,f,N]);function q(s){const a=[`# ${s.niche.name} Niche Report`,`Generated: ${M(new Date,"MMMM d, yyyy")}`,"","## Overview",`- Total Channels: ${s.stats.totalChannels}`,`- Total Videos Analyzed: ${s.stats.totalVideos}`,`- Total Outliers: ${s.stats.totalOutliers}`,`- Average Performance Score: ${s.stats.avgPerformance.toFixed(2)}x`,"","## Top Channels",...s.channels.slice(0,10).map((c,t)=>{var n;return`${t+1}. ${c.youtube_channel_name||"Unknown"} - ${c.total_outliers} outliers (${((n=c.avg_performance_score)==null?void 0:n.toFixed(2))||"-"}x avg)`}),"","## Common Title Patterns",s.titlePatterns.length>0?s.titlePatterns.map(c=>`- "${c}"`).join(`
7`):"- Not enough data","","## Top Outlier Videos",...s.topOutliers.slice(0,10).map((c,t)=>`${t+1}. "${c.title}" by ${c.youtube_channel_name||"Unknown"} - ${c.performance_score.toFixed(2)}x (${c.view_count.toLocaleString()} views)`)].join(`
8`),_=new Blob([a],{type:"text/markdown"}),p=URL.createObjectURL(_),m=document.createElement("a");m.href=p,m.download=`${s.niche.slug}-niche-report-${M(new Date,"yyyy-MM-dd")}.md`,m.click(),URL.revokeObjectURL(p),$.success("Report exported successfully")}function H(s){return s>=1e6?(s/1e6).toFixed(1)+"M":s>=1e3?(s/1e3).toFixed(1)+"K":s.toString()}return e.jsxs(W,{children:[e.jsx(G,{title:"Niche Reports",description:"Generate insights for each niche category",breadcrumbs:[{label:"Admin",to:"/admin"},{label:"Niche Reports"}],actions:e.jsx(w,{variant:"outline",icon:T,onClick:P,disabled:S,children:"Refresh"})}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-4 mb-6",children:[e.jsxs(l,{children:[e.jsx(o,{className:"pb-2",children:e.jsx(d,{className:"text-sm font-medium",children:"Active Niches"})}),e.jsxs(r,{children:[e.jsx("div",{className:"text-2xl font-bold",children:j.totalNiches}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"with at least 1 channel"})]})]}),e.jsxs(l,{children:[e.jsx(o,{className:"pb-2",children:e.jsx(d,{className:"text-sm font-medium",children:"Total Channels"})}),e.jsxs(r,{children:[e.jsx("div",{className:"text-2xl font-bold",children:j.totalChannels}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[j.classifiedChannels," classified"]})]})]}),e.jsxs(l,{children:[e.jsx(o,{className:"pb-2",children:e.jsx(d,{className:"text-sm font-medium",children:"Total Outliers"})}),e.jsx(r,{children:e.jsx("div",{className:"text-2xl font-bold",children:j.totalOutliers})})]}),e.jsxs(l,{children:[e.jsx(o,{className:"pb-2",children:e.jsx(d,{className:"text-sm font-medium",children:"Unclassified"})}),e.jsxs(r,{children:[e.jsx("div",{className:"text-2xl font-bold text-orange-500",children:j.totalChannels-j.
8classifiedChannels}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"channels need niche"})]})]})]}),e.jsx(l,{className:"mb-6",children:e.jsx(r,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(K,{value:g,onValueChange:O,children:[e.jsx(X,{className:"w-[300px]",children:e.jsx(J,{placeholder:"Select a niche to view report"})}),e.jsxs(Q,{children:[e.jsx(A,{value:"all",children:"Overview (All Niches)"}),u.map(s=>e.jsxs(A,{value:s.niche.id,children:[s.niche.name," (",s.stats.totalChannels," channels)"]},s.niche.id))]})]}),i&&e.jsx(w,{variant:"primary",icon:Y,onClick:()=>q(i),children:"Export Report"})]})})}),S?e.jsx(l,{children:e.jsxs(r,{className:"py-12 text-center",children:[e.jsx(T,{className:"h-8 w-8 animate-spin mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-muted-foreground",children:"Loading niche data..."})]})}):g==="all"?e.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:u.map(s=>e.jsxs(l,{className:"cursor-pointer hover:bg-muted/50 transition-colors",onClick:()=>O(s.niche.id),children:[e.jsxs(o,{children:[e.jsxs(d,{className:"flex items-center justify-between",children:[s.niche.name,e.jsx(C,{variant:"secondary",children:s.stats.totalChannels})]}),e.jsx(b,{children:s.niche.description})]}),e.jsx(r,{children:e.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("span",{children:[s.stats.totalVideos," videos"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(L,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("span",{children:[s.stats.totalOutliers," outliers"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(V,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("span",{children:[s.stats.avgPerformance.toFixed(2),"x avg"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{className:"h-4 w-4 text-muted-foreground"}),e.jsxs("span",{children:[s.stats.totalChannels," channels"]})]})]})})]},s.niche.id))}):i?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-4",children:[e.jsxs(l,{children:[e.jsx(o,{className:"pb-2",children:e.jsxs(d,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(F,{className:"h-4 w-4"}),"Channels"]})}),e.jsx(r,{children:e.jsx("div",{className:"text-2xl font-bold",children:i.stats.totalChannels})})]}),e.jsxs(l,{children:[e.jsx(o,{className:"pb-2",children:e.jsxs(d,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(E,{className:"h-4 w-4"}),"Videos Analyzed"]})}),e.jsx(r,{children:e.jsx("div",{className:"text-2xl font-bold",children:i.stats.totalVideos.toLocaleString()})})]}),e.jsxs(l,{children:[e.jsx(o,{className:"pb-2",children:e.jsxs(d,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(L,{className:"h-4 w-4"}),"Outliers Found"]})}),e.jsx(r,{children:e.jsx("div",{className:"text-2xl font-bold text-primary",children:i.stats.totalOutliers})})]}),e.jsxs(l,{children:[e.jsx(o,{className:"pb-2",children:e.jsxs(d,{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(V,{className:"h-4 w-4"}),"Avg Performance"]})}),e.jsx(r,{children:e.jsxs("div",{className:"text-2xl font-bold",children:[i.stats.avgPerformance.toFixed(2),"x"]})})]})]}),e.jsxs(l,{children:[e.jsxs(o,{children:[e.jsx(d,{children:"Common Title Patterns"}),e.jsx(b,{children:"Words that appear frequently in outlier titles"})]}),e.jsx(r,{children:i.titlePatterns.length>0?e.jsx("div",{className:"flex flex-wrap gap-2",children:i.titlePatterns.map(s=>e.jsx(C,{variant:"secondary",className:"text-sm",children:s},s))}):e.jsx("p",{className:"text-muted-foreground",children:"Not enough data to identify patterns"})})]}),e.jsxs(l,{children:[e.jsxs(o,{children:[e.jsxs(d,{children:["Top Channels in ",i.niche.name]}),e.jsx(b,{children:"Channels ranked by number of outliers"})]}),e.jsx(r,{children:e.jsx("div",{className:"space-y-3",children:i.channels.slice(0,10).map((s,h)=>{var a;return e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-lg font-bold text-muted-foreground w-6",children:h+1}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s.youtube_channel_name||"Unknown"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s.total_videos_analyzed," videos analyzed"]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:"font-bold text-primary",children:[s.total_outliers," outliers"]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[((a=s.avg_performance_score)==null?void 0:a.toFixed(2))||"-","x avg"]})]}),e.jsx("a",{href:s.youtube_channel_url||U.youtube.channel(s.youtube_channel_id),target:"_blank",rel:"noopener noreferrer",children:e.jsx(w,{variant:"icon-ghost",icon:Z})})]})]},s.id)})})})]}),e.jsxs(l,{children:[e.jsxs(o,{children:[e.jsx(d,{children:"Top Outlier Videos"}
8),e.jsx(b,{children:"Highest performing videos in this niche"})]}),e.jsx(r,{children:e.jsx("div",{className:"grid gap-4 md:grid-cols-2",children:i.topOutliers.slice(0,8).map(s=>e.jsxs("a",{href:U.youtube.watch(s.video_id),target:"_blank",rel:"noopener noreferrer",className:"flex gap-3 p-3 rounded-lg bg-muted/50 hover:bg-muted transition-colors",children:[e.jsx("img",{src:s.thumbnail_url,alt:s.title,className:"w-32 h-18 object-cover rounded flex-shrink-0"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium line-clamp-2 text-sm",children:s.title}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s.youtube_channel_name||"Unknown"}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsxs(C,{variant:"default",children:[s.performance_score.toFixed(2),"x"]}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[H(s.view_count)," views"]})]})]})]},s.id))})})]})]}):e.jsx(l,{children:e.jsx(r,{className:"py-12 text-center text-muted-foreground",children:"No report available for this niche"})})]})}export{he 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.