PageSourceSearch

https://nguyentudo.me/assets/AdminMessagesPage-ToFnBbRM.js

js nguyentudo.me collected 2026-10-04 14:32:07 UTC 7,342 bytes, 1 lines download raw bytes

1import{a as w,c4 as q,r as d,cK as B,bd as F,be as z,bg as K,bh as Q,p as O,j as e,c as M,w as G,aU as v,U as y,ap as W,aR as J,q as V,bi as S,I as k,h as T,aI as X,W as Y,s as Z,cL as $,cM as ee,x as se,y as te,z as ae,F as ne,G as re,aS as ie}from"./index-CyZ-pQAp.js";import{M as le,I as ce}from"./ImageAttachButton-Cpm0jHzd.js";import{P as de}from"./plus-BJk86tdF.js";import"./popover-D-5oJHro.js";import"./smile-plus-OWxN6DY0.js";import"./image-njiNJf6s.js";function oe(c){const{user:a}=w();return Y({queryKey:["unread-per-conv",a==null?void 0:a.id,c.map(t=>t.id).join(",")],queryFn:async()=>{if(!c.length)return{};const{data:t}=await Z.from("direct_messages").select("conversation_id").eq("receiver_id",a.id).is("read_at",null),r={};return t==null||t.forEach(i=>{r[i.conversation_id]=(r[i.conversation_id]||0)+1}),r},enabled:!!a&&c.length>0})}function je(){var C;const{user:c}=w(),a=q(),[t,r]=d.useState(null),[i,x]=d.useState(""),[m,u]=d.useState(null),o=d.useRef(null),{data:l=[],isLoading:n}=B(),{data:g={}}=oe(l),h=l.find(s=>s.id===t),{data:j=[]}=F(t),b=z(),P=K(),{peerTyping:N,emitTyping:A,stopTyping:D}=Q(t),[U]=O(),f=U.get("conv");d.useEffect(()=>{if(f&&l.some(s=>s.id===f)){r(f);return}!a&&!t&&l.length>0&&r(l[0].id)},[l,t,a,f]),d.useEffect(()=>{t&&P.mutate(t)},[t,j.length]),d.useEffect(()=>{o.current&&(o.current.scrollTop=o.current.scrollHeight)},[j,N]);const E=()=>{!i.trim()&&!m||!h||(b.mutate({conversationId:h.id,receiverId:h.member_id,content:i.trim(),imageUrl:m}),x(""),u(null),D())};if(n)return e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("div",{className:"animate-spin h-8 w-8 border-4 border-primary border-t-transparent rounded-full"})});const H=a?!!t:!0,L=a?!t:!0;return e.jsx("div",{className:"flex flex-col h-[calc(100vh-5rem)] md:h-[calc(100vh-4.5rem)] overflow-hidden",children:e.jsxs("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:[L&&e.jsxs("div",{className:M("border-r border-border flex flex-col",a?"w-full":"w-72"),children:[e.jsxs("div",{className:"p-4 border-b border-border flex items-center justify-between gap-2",children:[e.jsxs("h2",{className:"font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"h-5 w-5 text-primary"}),"Tin nhắn"]}),e.jsx(me,{onCreated:s=>r(s)})]}),e.jsx(v,{className:"flex-1",children:l.length===0?e.jsx("p",{className:"text-muted-foreground text-sm text-center py-8",children:"Chưa có tin nhắn"}):l.map(s=>{var _,I;const p=g[s.id]||0,R=((_=s.member)==null?void 0:_.display_name)||((I=s.member)==null?void 0:I.email)||"Thành viên";return e.jsxs("button",{onClick:()=>r(s.id),className:M("w-full text-left p-3 border-b border-border flex items-center gap-3 transition-colors",t===s.id&&!a?"bg-primary/10":"hover:bg-muted"),children:[e.jsx("div",{className:"h-9 w-9 rounded-full bg-muted flex items-center justify-center shrink-0",children:e.jsx(y,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:R}),p>0&&e.jsx(W,{variant:"default",className:"text-[10px] h-5 min-w-5 flex items-center justify-center shrink-0",children:p})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:J(new Date(s.last_message_at),"dd/MM HH:mm")})]})]},s.id)})})]}),H&&e.jsx("div",{className:"flex-1 flex flex-col min-w-0",children:t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"border-b border-border p-3 md:p-4 flex items-center gap-2",children:[a&&e.jsx("button",{onClick:()=>r(null),className:"p-1.5 -ml-1 rounded-lg hover:bg-muted transition-colors shrink-0","aria-label":"Quay lại danh sách",children:e.jsx(V,{className:"h-5 w-5"})}),e.jsx("div",{className:"h-9 w-9 rounded-full bg-muted flex items-center justify-center shrink-0",children:e.jsx(y,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h3",{className:"font-medium truncate",children:((C=h==null?void 0:h.member)==null?void 0:C.display_name)||"Thành viên"}),e.jsx("p",{className:"text-xs text-muted-foreground flex items-center gap-1.5 min-h-[16px]",children:N?e.jsxs(e.Fragment,{children:[e.jsx(S,{}),e.jsx("span",{children:"đang soạn tin…"})]}):e.jsx("span",{className:"opacity-60",children:"Hoạt động"})})]})]}),e.jsx(v,{className:"flex-1 p-3 md:p-4",ref:o,children:e.jsxs("div",{className:"space-y-3 pb-2",children:[j.map(s=>e.jsx(le,{msg:s,isMe:s.sender_id===(c==null?void 0:c.id),onImageClick:p=>window.open(p,"_blank")},s.id)),N&&e.jsx("div",{className:"flex justify-start",children:e.jsx("div",{className:"bg-muted text-muted-foreground rounded-2xl px-4 py-2",children:e.jsx(S,{})})})]})}),e.jsx("div",{className:"border-t border-border p-3 shrink-0",children:e.jsxs("form",{onSubmit:s=>{s.preventDefault(),E()},className:"flex items-center gap-2",children:[e.jsx(ce,{pendingUrl:m,onUploaded:u,onClear:()=>u(null),disabled:b.isPending}),e.jsx(k,{value:i,onChange:s=>{x(s.target.value),s.target.value.trim()&&A()},placeholder:m?"Thêm chú thích (tuỳ chọn)...":"Nhập tin nhắn...",className:"flex-1",autoComplete:"off"}),e.jsx(T,{type:"submit",size:"icon",disabled:!i.trim()&&!m||b.isPending,children:e.jsx(X,{className:"h-4 w-4"})})]})})]}):e.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:"Chọn cuộc hội thoại"})})]})})}function me({onCreated:c}
1){const[a,t]=d.useState(!1),[r,i]=d.useState(""),{data:x=[],isLoading:m}=$(r),u=ee(),{user:o}=w(),l=async n=>{const g=await u.mutateAsync(n);c(g.id),t(!1),i("")};return e.jsxs(se,{open:a,onOpenChange:t,children:[e.jsx(te,{asChild:!0,children:e.jsx(T,{size:"icon",variant:"ghost","aria-label":"Tin nhắn mới",children:e.jsx(de,{className:"h-4 w-4"})})}),e.jsxs(ae,{className:"max-w-md",children:[e.jsx(ne,{children:e.jsx(re,{children:"Nhắn tin cho học viên"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ie,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(k,{autoFocus:!0,value:r,onChange:n=>i(n.target.value),placeholder:"Tìm theo tên hoặc email...",className:"pl-9"})]}),e.jsx(v,{className:"h-72",children:m?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"Đang tải..."}):x.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-6",children:"Không tìm thấy học viên"}):e.jsx("div",{className:"space-y-1",children:x.filter(n=>n.user_id!==(o==null?void 0:o.id)).map(n=>e.jsxs("button",{onClick:()=>l(n.user_id),disabled:u.isPending,className:"w-full text-left p-2 rounded-lg hover:bg-muted transition-colors flex items-center gap-3",children:[e.jsx("div",{className:"h-9 w-9 rounded-full bg-muted flex items-center justify-center shrink-0 overflow-hidden",children:n.avatar_url?e.jsx("img",{src:n.avatar_url,alt:"",className:"h-full w-full object-cover"}):e.jsx(y,{className:"h-4 w-4 text-muted-foreground"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:n.display_name||"Học viên"}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:n.email})]})]},n.user_id))})})]})]})]})}export{je 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.