PageSourceSearch

https://fyra.life/assets/XAskResults-_hfOr07y.js

js fyra.life collected 2026-10-02 02:00:58 UTC 7,314 bytes, 1 lines download raw bytes

1import{u as z,a as F,b as O,r as l,s as E,j as e,C as _,B as j}from"./index-CEISlULX.js";import{f as Y}from"./friendlyError-UL1BAfr1.js";import{S as G}from"./sparkles-BpeD-uNo.js";function W(){const h=z(),{toast:N}=F(),[q]=O(),d=q.get("ask_id")||"",p=E,[M,u]=l.useState(!0),[T,D]=l.useState(null),[r,k]=l.useState(null),[v,L]=l.useState([]),[w,$]=l.useState([]),[U,S]=l.useState(!1);l.useEffect(()=>{let t=!0;return(async()=>{var c;u(!0),S(!1);try{const{data:i}=await E.auth.getUser(),y=((c=i==null?void 0:i.user)==null?void 0:c.id)??null;if(!t)return;if(D(y),!d){N({description:"Missing ask_id",variant:"destructive"}),u(!1);return}if(!y){u(!1);return}const{data:m,error:A}=await p.from("x_asks").select("id, creator_user_id, ask_type, status, prompt, context_text, deadline_at, ai_summary, response_mode").eq("id",d).maybeSingle();if(A)throw A;if(!m){k(null),u(!1);return}k(m);let b=m.creator_user_id===y;if(!b){const{count:o}=await p.from("x_ask_recipients").select("id",{count:"exact",head:!0}).eq("ask_id",d).eq("recipient_user_id",y);o&&o>0&&(b=!0)}if(!b){S(!0),u(!1);return}if(m.ask_type==="text"||m.response_mode==="text"){const{data:o}=await p.from("x_ask_text_responses").select("respondent_user_id, response_text").eq("ask_id",d);if(o!=null&&o.length){const g=o.map(n=>n.respondent_user_id),{data:x}=await p.from("profiles").select("id, first_name, last_name, username").in("id",g),f={};for(const n of x||[])f[n.id]=[n.first_name,n.last_name].filter(Boolean).join(" ")||n.username||"Someone";t&&$(o.map(n=>({respondent_name:f[n.respondent_user_id]||"Someone",response_text:n.response_text})))}}else{const{data:o,error:g}=await p.from("x_ask_results_favorites").select("entity_type, entity_id, pick_count, avg_position").eq("ask_id",d);if(g)throw g;const x=o||[],f=x.filter(s=>s.entity_type==="place").map(s=>parseInt(s.entity_id,10)).filter(s=>!isNaN(s));let n={};if(f.length>0){const{data:s}=await p.from("corpus_places").select("id, name, city, state").in("id",f);for(const a of s||[])n[a.id]={name:a.name,city:a.city,state:a.state}}const R=x.filter(s=>s.entity_type==="product").map(s=>parseInt(s.entity_id,10)).filter(s=>!isNaN(s));let C={};if(R.length>0){const{data:s}=await p.from("corpus_products_wine_spirits").select("lwin, display_name, producer_name, region").in("lwin",R);for(const a of s||[])C[a.lwin]={display_name:a.display_name,producer_name:a.producer_name,region:a.region}}const B=x.map(s=>{if(s.entity_type==="place"){const a=n[parseInt(s.entity_id,10)];if(a)return{...s,place_name:a.name,place_city:a.city??void 0,place_state:a.state??void 0}}if(s.entity_type==="product"){const a=C[parseInt(s.entity_id,10)];if(a)return{...s,product_name:a.display_name??void 0,product_producer:a.producer_name??void 0,product_region:a.region??void 0}}return s});B.sort((s,a)=>a.pick_count!==s.pick_count?a.pick_count-s.pick_count:s.avg_position-a.avg_position),L(B)}u(!1)}catch(i){console.error("XAskResults load error:",i),N({description:Y(i,"Failed to load results"),variant:"destructive"}),u(!1)}})(),()=>{t=!1}},[d,N]);const P=l.useMemo(()=>(r==null?void 0:r.status)==="open",[r]),I=(r==null?void 0:r.ask_type)==="text"||(r==null?void 0:r.response_mode)==="text",X=t=>{if(t.entity_type==="place"&&t.place_name)return{title:t.place_name,subtitle:[t.place_city,t.place_state].filter(Boolean).join(", ")||void 0};if(t.entity_type==="product"){const c=t.product_name||(t.product_producer?`${t.product_producer}`:t.entity_id),i=t.product_name?[t.product_producer,t.product_region].filter(Boolean).join(" • ")||void 0:t.product_region||void 0;return{title:c,subtitle:i}}return{title:t.entity_id}};return M?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx("p",{className:"text-muted-foreground",children:"Loading results…"})}):T?U?e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-6",children:e.jsxs(_,{className:"max-w-lg w-full p-6 space-y-4",children:[e.jsx("h1",{className:"text-xl font-bold",children:"Access Denied"}),e.jsx("p",{className:"text-muted-foreground",children:"You don't have permission to view these results."}),e.jsx(j,{variant:"outline",onClick:()=>h(-1),children:"Back"})]})}):r?e.jsx("div",{className:"min-h-screen w-full bg-gradient-to-b from-accent/5 via-background to-background",children:e.jsxs("div",{className:"max-w-2xl mx-auto px-4 py-8 space-y-5",children:[e.jsxs("header",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"space-y-1 min-w-0",children:[e.jsx("p",{className:"text-xs text-muted-foreground uppercase tracking-wide",children:"Results"}),e.jsx("h1",{className:"text-xl font-bold leading-tight",children:r.prompt})]}),e.jsx(j,{variant:"outline",size:"sm",onClick:()=>h(`/x-ask?ask_id=${encodeURIComponent(d)}`),children:"Back"})]}),P&&e.jsx("div",{className:"bg-amber-500/10 border border-amber-500/30 rounded-lg px-4 py-3",children:e.jsx("p",{className:"text-sm text-amber-700 dark:text-amber-300",children:"Still open — results may change as more people respond."})}),r.ai_summary&&e.jsxs("div",{className:"rounded-lg border border-primary/20 bg-primary/5 p-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(G,{className:"h-4 w-4 text-primary"}),e.jsx("p",{className:"text-xs font-semibold text-primary",children:"AI Summary"})]}),e.jsx("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:r.ai_summary})]}),I&&(w.length===0?e.jsx(_,{className:"p-6",children:e.jsx("p",{className:"text-muted-foreground text-center",children:"No responses yet."})}):e.jsx("div",{className:"space-y-2",children:w.map((t,c)=>e.jsxs("div",{className:"rounded-lg border border-border bg-card p-3 space-y-1",children:[e.jsx("p",{className:"text-xs font-medium text-foreground",children:t.respondent_name}),e.jsx("p",{className:"text-sm text-muted-foreground whitespace-pre-wrap",children:t.response_text})]},c))})),!I&&(v.length===0?e.jsx(_,{className:"p-6",children:e.jsx("p",{className:"text-muted-foreground text-center",children:"No responses yet."})}):e.jsx("div",{className:"space-y-2",children:v.map(t=>{const{title:c,subtitle:i}=X(t);return e.jsxs("div",{className:"bg-card border border-border rounded-lg px-3 py-2.5 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-foreground leading-snug",children:c}),i&&e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:i})]}),t.pick_count>1&&e.jsxs("div",{className:"flex-shrink-0 text-sm text-muted-foreground",children:["×",t.pick_count]})]},`${t.entity_type}-${t.entity_id}`)})}))]})}):e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-6",children:e.jsxs(_,{className:"max-w-lg w-full p-6 space-y-3",children:[e.jsx("h1",{className:"text-xl font-bold",children:"Ask not found"}),e.jsx(j,{variant:"outline",onClick:()=>h(-1),children:"Back"})]})}):e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center p-6",children:e.jsxs(_,{className:"max-w-lg w-full p-6 space-y-4",children:[e.jsx("h1",{className:"text-xl font-bold",children:"Log in to view results"}),e.jsx(j,{className:"w-full",onClick:()=>h("/auth"),children:"Log in"})]})})}export{W 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.