PageSourceSearch

https://zetta10.com/assets/TalentMessages-D6bOzWg2.js

js zetta10.com collected 2026-10-07 20:16:38 UTC 9,663 bytes, 10 lines download raw bytes

1import{j as s}from"./vendor-query-CDWquNOr.js";import{r as i,k as Y}from"./vendor-react-kb4SOhqU.js";import{u as U,m as W,j as G,s as m,I as J,A,g as K,h as R,B as P,t as Q}from"./index-Dal2VKqF.js";import{aK as X,ay as Z,aL as ee,b as se,N as L}from"./vendor-icons-DPyBaExq.js";import{i as te,a as ae}from"./isYesterday-xsEuJuUo.js";import{f as H}from"./format-DRU-A12X.js";import"./vendor-supabase-D0XKNO17.js";import"./vendor-radix-CqRzJ76P.js";import"./vendor-charts-CSz2-Rta.js";import"./vendor-stripe-BKT3e942.js";import"./vendor-media-BBVX24IF.js";import"./vendor-markdown-DwPMj3Qf.js";import"./vendor-motion-DW9K_eHB.js";import"./isSameDay-B0tUYu9s.js";import"./subDays-G0W4NvQ8.js";const re=d=>{const w=/(https?:\/\/[^\s]+)/g;return d.split(w).map((u,y)=>u.match(w)?s.jsx("a",{href:u,target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-blue-400 transition-colors",children:u},y):u)};function ne(){const{language:d}=U(),{toast:w}=W(),[p,u]=i.useState([]),[y,z]=Y(),[l,b]=i.useState(null),[N,S]=i.useState([]),[g,v]=i.useState(""),{user:t}=G(),[_,B]=i.useState(!0),C=i.useRef(null),E=i.useRef(null),M=e=>
1{b(e),e&&u(a=>a.map(r=>r.id===e?{...r,unread_count:0}:r))};i.useEffect(()=>{if(!t)return;(async()=>{const{data:a,error:r}=await m.from("conversations").select(`
2          *,
3          messages (
4            content,
5            created_at,
6            sender_id,
7            read_at
8          )
9        `).or(`participant_1_id.eq.${t.id},participant_2_id.eq.${t.id}`).order("updated_at",{ascending:!1});if(r){console.error("Error loading conversations:",r);return}const x=await Promise.all((a||[]).map(async o=>{var q;const h=o.participant_1_id===t.id?o.participant_2_id:o.participant_1_id,{data:n}=await m.from("profiles").select("id, name, avatar_url, user_type").eq("id",h).maybeSingle();let D=n==null?void 0:n.avatar_url,I=(n==null?void 0:n.name)||"Unknown User";if((n==null?void 0:n.user_type)==="company"){const{data:f}=await m.from("company_users").select("company_id").eq("user_id",h).maybeSingle();if(f){const{data:c}=await m.from("companies").select("name, logo_url").eq("id",f.company_id).maybeSingle();c!=null&&c.logo_url&&(D=c.logo_url),c!=null&&c.name&&(I=c.name)}}const O=(q=o.messages)==null?void 0:q.sort((f,c)=>new Date(c.created_at).getTime()-new Date(f.created_at).getTime())[0],V=(o.messages||[]).filter(f=>f.sender_id!==t.id&&!f.read_at).length;return{...o,other_user:{id:(n==null?void 0:n.id)||h,name:I,avatar_url:D},last_message:O,unread_count:V}}));u(x),B(!1)})()},[t]),i.useEffect(()=>{const e=y.get("conversation");!e||_||p.some(a=>a.id===e)&&(M(e),y.delete("conversation"),z(y,{replace:!0}))},[y,p,_]),i.useEffect(()=>{if(!l||!t)return;(async()=>{const{data:r,error:x}=await m.from("messages").select("*").eq("conversation_id",l).order("created_at",{ascending:!0});if(x){console.error("Error loading messages:",x);return}S(r||[]);const o=(r||[]).filter(h=>h.sender_id!==t.id&&!h.read_at);if(o.length>0){const h=o.map(n=>n.id);await m.from("messages").update({read_at:new Date().toISOString()}).in("id",h)}})();const a=m.channel("messages").on("postgres_changes",{event:"INSERT",schema:"public",table:"messages",filter:`conversation_id=eq.${l}`},r=>{S(x=>[...x,r.new])}).subscribe();return()=>{m.removeChannel(a)}},[l,t]),i.useEffect(()=>{var e;(e=C.current)==null||e.scrollIntoView({behavior:"smooth",block:"end"})},[N]),i.useEffect(()=>{const e=E.current;if(e){e.style.height="42px";const a=e.scrollHeight;e.style.height=Math.min(a,128)+"px"}},[g]);const k=async()=>{if(!(!g.trim()||!l||!t))try{const{error:e}=await m.from("messages").insert({conversation_id:l,sender_id:t.id,content:g.trim()});if(e){console.error("Error sending message:",e),w({title:"Error",description:d==="es"?"No se pudo enviar el mensaje":"Could not send message",variant:"destructive"});return}await m.from("conversations").update({updated_at:new Date().toISOString()}).eq("id",l),v("")}catch(e){console.error("Error sending message:",e)}},F=e=>{if(e.key==="Enter"&&(e.ctrlKey||e.metaKey||e.altKey)){e.preventDefault();const a=e.target,r=a.selectionStart,x=a.selectionEnd,o=g.substring(0,r)+`
10`+g.substring(x);v(o),setTimeout(()=>{a.selectionStart=a.selectionEnd=r+1},0)}else e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),k())},$=e=>{const a=new Date(e);return te(a)?H(a,"HH:mm"):ae(a)?d==="es"?"Ayer":"Yesterday":H(a,"dd/MM/yy")},T=e=>e.split(" ").map(a=>a[0]).join("").toUpperCase().slice(0,2),j=p.find(e=>e.id===l);return _?s.jsx("div",{className:"flex items-center justify-center h-96",children:s.jsxs("div",{className:"text-center",children:[s.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-elegant-yellow mx-auto mb-4"}),s.jsx("p",{className:"text-gray-400",children:d==="es"?"Cargando mensajes...":"Loading messages..."})]})}):s.jsxs("div",{className:"h-[calc(100vh-200px)] flex rounded-lg overflow-hidden border border-white/10",children:[s.jsxs("div",{className:`${l?"hidden lg:flex":"flex"} flex-col w-full lg:w-1/3 bg-navy-900/50 border-r border-white/10`,children:[s.jsxs("div",{className:"p-4 border-b border-white/10",children:[s.jsx("div",{className:"flex items-center gap-3 mb-4",children:s.jsx("h1",{className:"text-xl font-semibold text-white",children:d==="es"?"Mensajes":"Messages"})}),s.jsxs("div",{className:"relative",children:[s.jsx(X,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 h-4 w-4"}),s.jsx(J,{placeholder:d==="es"?"Buscar conversaciones...":"Search conversations...",className:"pl-10 bg-navy-800/50 border-white/20 text-white placeholder-gray-400"})]})]}),s.jsx("div",{className:"flex-1 overflow-y-auto",children:p.length===0?s.jsx("div",{className:"p-4 text-center text-gray-400",children:d==="es"?"No tienes conversaciones aún":"No conversations yet"}):p.map(e=>s.jsx("div",{onClick:()=>M(e.id),className:`p-4 border-b border-white/5 cursor-pointer hover:bg-navy-800/30 transition-colors ${l===e.id?"bg-navy-800/50":""} ${e.unread_count>0?"bg-elegant-yellow/5 border-l-2 border-l-elegant-yellow":""}`,children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsxs("div",{className:"relative",children:[s.jsxs(A,{className:"h-12 w-12",children:[s.jsx(K,{src:e.other_user.avatar_url}),s.jsx(R,{className:"bg-elegant-yellow/20 text-white",children:T(e.other_user.n
10ame)})]}),e.unread_count>0&&s.jsx("span",{className:"absolute -top-1 -right-1 bg-elegant-yellow text-navy-950 text-xs font-bold rounded-full h-5 w-5 flex items-center justify-center",children:e.unread_count>9?"9+":e.unread_count})]}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("h3",{className:`text-sm truncate ${e.unread_count>0?"font-bold text-white":"font-medium text-white"}`,children:e.other_user.name}),e.last_message&&s.jsx("p",{className:`text-sm truncate ${e.unread_count>0?"text-gray-300 font-medium":"text-gray-400"}`,children:e.last_message.content})]}),s.jsx("div",{className:"flex flex-col items-end gap-1",children:e.last_message&&s.jsx("div",{className:`text-xs ${e.unread_count>0?"text-elegant-yellow font-medium":"text-gray-500"}`,children:$(e.last_message.created_at)})})]})},e.id))})]}),s.jsx("div",{className:`${l?"flex":"hidden lg:flex"} flex-col flex-1`,children:l&&j?s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"p-4 border-b border-white/10 bg-navy-900/30",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(P,{variant:"ghost",size:"sm",onClick:()=>b(null),className:"lg:hidden text-gray-300 hover:text-white",children:s.jsx(Z,{className:"h-4 w-4"})}),s.jsxs(A,{className:"h-10 w-10",children:[s.jsx(K,{src:j.other_user.avatar_url}),s.jsx(R,{className:"bg-elegant-yellow/20 text-white",children:T(j.other_user.name)})]}),s.jsx("div",{children:s.jsx("h2",{className:"text-lg font-medium text-white",children:j.other_user.name})})]})}),s.jsxs("div",{className:"flex-1 overflow-y-auto p-4 space-y-4 bg-navy-950/30",children:[N.map(e=>s.jsx("div",{className:`flex ${e.sender_id===(t==null?void 0:t.id)?"justify-end":"justify-start"}`,children:s.jsxs("div",{className:`max-w-xs lg:max-w-md px-4 py-2 rounded-lg ${e.sender_id===(t==null?void 0:t.id)?"bg-elegant-yellow text-navy-900":"bg-navy-800 text-white"}`,children:[s.jsx("p",{className:"text-sm whitespace-pre-wrap break-words",children:re(e.content)}),s.jsxs("div",{className:`flex items-center justify-between mt-1 ${e.sender_id===(t==null?void 0:t.id)?"text-navy-700":"text-gray-400"}`,children:[s.jsx("span",{className:"text-xs",children:$(e.created_at)}),e.sender_id===(t==null?void 0:t.id)&&s.jsx("span",{className:"ml-2",children:e.read_at?s.jsx(ee,{className:"h-3 w-3"}):s.jsx(se,{className:"h-3 w-3"})})]})]})},e.id)),s.jsx("div",{ref:C})]}),s.jsx("div",{className:"p-4 border-t border-white/10 bg-navy-900/30",children:s.jsxs("div",{className:"flex items-end gap-2",children:[s.jsx(Q,{ref:E,value:g,onChange:e=>v(e.target.value),onKeyDown:F,placeholder:d==="es"?"Escribe un mensaje...":"Type a message...",className:"flex-1 bg-navy-800/50 border-white/20 text-white placeholder-gray-400 resize-none min-h-[42px] max-h-32 overflow-y-auto",rows:1}),s.jsx(P,{onClick:k,disabled:!g.trim(),className:"bg-elegant-yellow text-navy-900 hover:bg-elegant-yellow-600 h-[42px]",children:s.jsx(L,{className:"h-4 w-4"})})]})})]}):s.jsx("div",{className:"flex-1 flex items-center justify-center text-gray-400",children:s.jsxs("div",{className:"text-center",children:[s.jsx(L,{className:"h-12 w-12 mx-auto mb-4 opacity-50"}),s.jsx("p",{children:d==="es"?"Selecciona una conversación para comenzar":"Select a conversation to start"})]})})})]})}const ve=()=>s.jsx("div",{className:"p-4 md:p-6",children:s.jsx(ne,{})});export{ve 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.