PageSourceSearch

https://wellnessand.me/assets/account.messages-C4HDfplC.js

js wellnessand.me collected 2026-10-09 21:48:39 UTC 5,211 bytes, 1 lines download raw bytes

1import{v as S,r as o,R as l,j as t,f as E,k as f,l as x,c9 as k,ca as D,cb as A,af as $,B as T,ak as I,a1 as p}from"./index-CWOAIT0E.js";import{D as M}from"./discover-rail-DFbDmmNL.js";import{C as O,d as R}from"./patterns-C0MK_RP_.js";import"./cross-recs-DEqGXu4_.js";import"./tabs-BC7zfWmi.js";import"./circle-user-round-DGpLdJY5.js";function F(){const{user:a}=S(),[d,m]=o.useState(null),[v,N]=o.useState({}),[c,h]=o.useState(null),[u,g]=o.useState(""),[y,_]=o.useState(!1),b=async()=>{if(!a)return;const{data:s}=await l.from("messages").select("id, sender_id, recipient_id, body, read_at, created_at").or(`sender_id.eq.${a.id},recipient_id.eq.${a.id}`).order("created_at",{ascending:!0}),e=s??[];m(e);const r=Array.from(new Set(e.map(i=>i.sender_id===a.id?i.recipient_id:i.sender_id)));if(r.length){const{data:i}=await l.from("profiles_public").select("id, display_name, avatar_url").in("id",r);N(Object.fromEntries((i??[]).map(n=>[n.id,n]))),h(n=>n??r[r.length-1])}};o.useEffect(()=>{b()},[a]),o.useEffect(()=>{if(!a)return;const s=l.channel(`msgs-${a.id}`).on("postgres_changes",{event:"INSERT",schema:"public",table:"messages",filter:`recipient_id=eq.${a.id}`},e=>m(r=>{const i=e.new;return r?.some(n=>n.id===i.id)?r:[...r??[],i]})).on("postgres_changes",{event:"INSERT",schema:"public",table:"messages",filter:`sender_id=eq.${a.id}`},e=>m(r=>{const i=e.new;return r?.some(n=>n.id===i.id)?r:[...r??[],i]})).subscribe();return()=>{l.removeChannel(s)}},[a]),o.useEffect(()=>{if(!a||!c||!d)return;const s=d.filter(e=>e.sender_id===c&&e.recipient_id===a.id&&!e.read_at).map(e=>e.id);s.length!==0&&l.from("messages").update({read_at:new Date().toISOString()}).in("id",s).then(()=>{m(e=>e?.map(r=>s.includes(r.id)?{...r,read_at:new Date().toISOString()}:r)??e)})},[c,d,a]);const C=async()=>{if(!a||!c||!u.trim())return;const s=R(u);if(!s.ok){p.error("Sharing contact info isn't allowed",{description:`Detected: ${s.reasons.join(", ")}. Codex covers on-platform bookings only.`});return}_(!0);const{error:e}=await l.from("messages").insert({sender_id:a.id,recipient_id:c,body:u.trim()});if(_(!1),e){const r=e.message||"";r.includes("CONTACT_LEAK_BLOCKED")?p.error("Message blocked",{description:"Sharing contact info violates our terms. Repeated attempts pause chat."}):r.includes("CHAT_SUSPENDED")?p.error("Chat paused",{description:"Your chat is currently paused due to prior policy violations."}):p.error(r);return}g("")},j=o.useMemo(()=>{if(!a||!d)return[];const s=new Map;return d.forEach(e=>{const r=e.sender_id===a.id?e.recipient_id:e.sender_id,i=s.get(r),n=e.recipient_id===a.id&&!e.read_at?1:0;i?(i.last=e,i.unread+=n):s.set(r,{peer:r,last:e,unread:n})}),Array.from(s.values()).sort((e,r)=>r.last.created_at.localeCompare(e.last.created_at))},[d,a]),w=o.useMemo(()=>!a||!d||!c?[]:d.filter(s=>s.sender_id===a.id&&s.recipient_id===c||s.recipient_id===a.id&&s.sender_id===c),[d,a,c]);return d===null?t.jsx("div",{className:"flex h-64 items-center justify-center",children:t.jsx(E,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):j.length===0?t.jsx(f,{className:"border-dashed",children:t.jsx(x,{className:"p-10 text-center text-sm text-muted-foreground",children:"No messages yet. Once you book a coach, your conversations will appear here."})}):t.jsxs("div",{className:"space-y-3",children:[t.jsx(O,{}),t.jsxs("div",{className:"grid gap-4 md:grid-cols-[260px_1fr]",children:[t.jsx(f,{children:t.jsx(x,{className:"p-0",children:t.jsx("ul",{className:"divide-y",children:j.map(s=>{const e=v[s.peer],r=e?.display_name??"Coach",i=c===s.peer;return t.jsx("li",{children:t.jsxs("button",{onClick:()=>h(s.peer),className:`flex w-full items-center gap-3 px-4 py-3 text-left transition-colors ${i?"bg-muted":"hover:bg-muted/50"}`,children:[t.jsxs(k,{className:"h-8 w-8",children:[e?.avatar_url?t.jsx(D,{src:e.avatar_url,alt:""}):null,t.jsx(A,{children:r.slice(0,1)})]}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("p",{className:"truncate text-sm font-medium",children:r}),t.jsx("p",{className:"truncate text-xs text-muted-foreground",children:s.last.body})]}),s.unread>0&&t.jsx("span",{className:"rounded-full bg-primary px-2 py-0.5 text-[10px] font-medium text-on-jade",children:s.unread})]})},s.peer)})})})}),t.jsx(f,{children:t.jsxs(x,{className:"flex h-[60vh] flex-col p-0",children:[t.jsx("div",{className:"flex-1 space-y-3 overflow-y-auto p-5",children:w.map(s=>{const e=s.sender_id===a?.id;return t.jsx("div",{className:`flex ${e?"justify-end":"justify-start"}`,children:t.jsxs("div",{className:`max-w-[75%] rounded-2xl px-4 py-2 text-sm ${e?"bg-primary text-on-jade":"bg-muted"}`,children:[s.body,t.jsx("p",{className:`mt-1 text-[10px] ${e?"text-on-jade/85":"text-muted-foreground"}`,children:new Date(s.created_at).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]})},s.id)})}),t.jsx("div",{className:"border-t p-3",children:t.jsxs("div",{className:"flex gap-2",children:[t.jsx($,{value:u,onChange:s=>g(s.target.value),placeholder:"Write a message…",rows:2,className:"resize-none"}),t.jsx(T,{onClick:C,disabled:y||!u.trim(),className:"shrink-0",children:t.jsx(I,{className:"h-4 w-4"})})]})})]})}),t.jsx(M,{title:"Discover more on Codex"})]})]})}export{F 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.