PageSourceSearch

https://trybrain.io/assets/_authenticated.organic-comment-mining-DzqrWbU1.js

js trybrain.io collected 2026-10-02 02:00:14 UTC 6,825 bytes, 1 lines download raw bytes

1import{ad as l,ae as u,af as x,c as o,z as T,d as _,r as k,j as e,a as p,L as M,F as P,B as N,y as E,D as v,t as c,l as b,S as O}from"./index-DQ05VIVn.js";import{D as $}from"./download-Cmw24rd8.js";import{W as L}from"./wand-sparkles-CZzb_5MJ.js";const Q=l({method:"POST"}).middleware([u]).handler(x("src_lib_organic-comments_functions_ts--listCommentableWinners_createServerFn_handler")),z=l({method:"POST"}).middleware([u]).handler(x("src_lib_organic-comments_functions_ts--fetchPostComments_createServerFn_handler")),K=l({method:"POST"}).middleware([u]).handler(x("src_lib_organic-comments_functions_ts--minePostThemes_createServerFn_handler")),W=l({method:"POST"}).middleware([u]).handler(x("src_lib_organic-comments_functions_ts--getPostThemes_createServerFn_handler")),A=l({method:"POST"}).middleware([u]).handler(x("src_lib_organic-comments_functions_ts--spinScriptFromCommentTheme_createServerFn_handler")),F={objection:"bg-destructive/15 text-destructive",desire:"bg-emerald-500/15 text-emerald-700 dark:text-emerald-300",question:"bg-blue-500/15 text-blue-700 dark:text-blue-300",praise:"bg-violet-500/15 text-violet-700 dark:text-violet-300",other:"bg-muted text-muted-foreground"};function I(){const r=o(T),i=o(Q),{data:h}=_({queryKey:["workspaces"],queryFn:()=>r({})}),n=h?.[0],m=_({queryKey:["commentable-posts",n?.id],queryFn:()=>i({data:{workspaceId:n.id,days:30}}),enabled:!!n?.id}),[d,g]=k.useState(null);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight",children:"Comment Mining"}),e.jsx("p",{className:"text-sm text-muted-foreground max-w-2xl",children:"Pull comments from your recent Instagram posts and let AI tag each one as an objection, desire, question, or praise. Feed those insights back into future scripts."})]}),e.jsx(p,{asChild:!0,variant:"outline",size:"sm",children:e.jsx(M,{to:"/organic",children:"← Back to Matrix"})})]}),!n||m.isLoading?e.jsx(P,{className:"h-64 w-full"}):m.error?e.jsx("div",{className:"rounded-lg border border-destructive/30 bg-destructive/5 p-6 text-sm text-destructive",children:m.error.message}):m.data?.posts.length?e.jsxs("div",{className:"grid gap-4 md:grid-cols-[minmax(0,340px)_1fr]",children:[e.jsx("div",{className:"space-y-2",children:m.data.posts.map(t=>e.jsxs("button",{onClick:()=>g(t.publish_id),className:`w-full text-left rounded-lg border p-3 hover:bg-accent/40 ${d===t.publish_id?"border-primary bg-accent/30":""}`,children:[e.jsx("div",{className:"text-sm line-clamp-2",children:t.caption||"(no caption)"}),e.jsxs("div",{className:"mt-2 flex items-center gap-2 text-[10px] text-muted-foreground",children:[e.jsxs("span",{children:[t.comment_count," comments"]}),t.mined_count>0&&e.jsxs("span",{children:["· ",t.mined_count," mined"]}),t.theme_count>0&&e.jsxs(N,{className:"bg-primary/15 text-primary text-[9px]",children:[t.theme_count," themes"]})]})]},t.publish_id))}),e.jsx("div",{children:d&&n?e.jsx(B,{workspaceId:n.id,publishId:d}):e.jsx("div",{className:"rounded-lg border p-8 text-center text-sm text-muted-foreground",children:"Pick a post to fetch its comments."})})]}):e.jsx("div",{className:"rounded-lg border p-8 text-center text-sm text-muted-foreground",children:"No published posts in the last 30 days."})]})}function B({workspaceId:r,publishId:i}){const h=E(),n=o(W),m=o(z),d=o(K),g=o(A),[t,y]=k.useState(null),a=_({queryKey:["post-themes",i],queryFn:()=>n({data:{workspaceId:r,publishId:i}})}),S=()=>{h.invalidateQueries({queryKey:["post-themes",i]}),h.invalidateQueries({queryKey:["commentable-posts",r]})},j=v({mutationFn:()=>m({data:{workspaceId:r,publishId:i}}),onSuccess:s=>{c.success(`Fetched ${s.fetched} comments`),S()},onError:s=>c.error(s.message)}),f=v({mutationFn:()=>d({data:{workspaceId:r,publishId:i}}),onSuccess:s=>{c.success(`Tagged ${s.mined} comments, ${s.themes} themes`),S()},onError:s=>c.error(s.message)}),w=v({mutationFn:s=>g({data:{workspaceId:r,themeId:s}}),onMutate:s=>y(s),onSuccess:s=>{c.success(`Spun ${s.angle} × ${s.format} script — check the Matrix`)},onError:s=>c.error(s.message),onSettled:()=>y(null)});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs(p,{size:"sm",variant:"outline",onClick:()=>j.mutate(),disabled:j.isPending,children:[j.isPending?e.jsx(b,{className:"h-3.5 w-3.5 animate-spin mr-1.5"}):e.jsx($,{className:"h-3.5 w-3.5 mr-1.5"}),"Fetch comments from Instagram"]}),e.jsxs(p,{size:"sm",onClick:()=>f.mutate(),disabled:f.isPending||!a.data?.comments.length,children:[f.isPending?e.jsx(b,{className:"h-3.5 w-3.5 animate-spin mr-1.5"}):e.jsx(O,{className:"h-3.5 w-3.5 mr-1.5"}),"Mine themes"]})]}),a.isLoading?e.jsx(P,{className:"h-40 w-full"}):e.jsxs(e.Fragment,{children:[a.data&&a.data.themes.length>0&&e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:a.data.themes.map(s=>e.jsxs("div",{className:"rounded-lg border p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(N,{className:F[s.theme]??"",children:s.theme}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:[s.comment_count," comments"]})]}),e.jsx("div",{className:"text-sm font-medium",children:s.summary}),Array.isArray(s.sample_quotes)&&s.sample_quotes.length>0&&e.jsx("ul",{className:"text-xs text-muted-foreground space-y-1",children:s.sample_quotes.slice(0,3).map((C,q)=>e.jsxs("li",{className:"italic",children:['"',C,'"']},q))}),e.jsxs(p,{size:"sm",variant:"outline",className:"w-full mt-1",disabled:w.isPending,onClick:()=>w.mutate(s.id),children:[t===s.id?e.jsx(b,{className:"h-3.5 w-3.5 animate-spin mr-1.5"}):e.jsx(L,{className:"h-3.5 w-3.5 mr-1.5"}),"Spin script from this theme"]})]},s.id))}),e.jsxs("div",{className:"rounded-lg border",children:[e.jsxs("div",{className:"p-3 border-b text-xs font-medium text-muted-foreground uppercase tracking-wide",children:["Raw comments (",a.data?.comments.length??0,")"]}),e.jsxs("div",{className:"divide-y max-h-[420px] overflow-y-auto",children:[(a.data?.comments??[]).map(s=>e.jsxs("div",{className:"p-3 text-sm",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1 flex-wrap",children:[e.jsxs("span",{className:"font-medium text-xs",children:["@",s.username??"anon"]}),s.theme&&e.jsx(N,{className:`${F[s.theme]??""} text-[10px]`,children:s.theme}),s.like_count>0&&e.jsxs("span",{className:"text-[10px] text-muted-foreground",children:["♥ ",s.like_count]})]}),e.jsx("div",{children:s.text})]},s.id)),!a.data?.comments.length&&e.jsx("div",{className:"p-6 text-center text-sm text-muted-foreground",children:'No comments cached yet — hit "Fetch comments from Instagram" above.'})]})]})]})]})}export{I as component};

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.