Files
Remote-Terminal-for-MeshCore/frontend/prebuilt/assets/SearchView-BFMnGDyJ.js
T
2026-03-15 15:47:09 -07:00

3 lines
5.0 KiB
JavaScript

import{r as n,k as _,A as w,j as t,I as H,l as I,m as Q,B}from"./index-D8to1fXL.js";const b=50,D=300,O=new RegExp('(?<!\\S)(user|channel):(?:"((?:[^"\\\\]|\\\\.)*)"|(\\S+))',"gi");function T(c,d){if(!d)return[c];const i=[],m=new RegExp(`(${d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")})`,"gi"),r=c.split(m);for(let l=0;l<r.length;l++)m.test(r[l])?i.push(t.jsx("mark",{className:"bg-primary/30 text-foreground rounded-sm px-0.5",children:r[l]},l)):i.push(r[l]),m.lastIndex=0;return i}function L(c){const d=[];let i=0,m=!1;for(const r of c.matchAll(O))m=!0,d.push(c.slice(i,r.index)),i=(r.index??0)+r[0].length;return m?(d.push(c.slice(i)),d.map(r=>r.trim()).filter(Boolean).join(" ")):c}function $({contacts:c,channels:d,visibilityVersion:i=0,onNavigateToMessage:m,prefillRequest:r=null}){const[l,v]=n.useState(""),[a,k]=n.useState(""),[C,h]=n.useState([]),[f,p]=n.useState(!1),[A,g]=n.useState(!1),[E,y]=n.useState(0),x=n.useRef(null),j=n.useRef(null),R=L(a);n.useEffect(()=>{const e=setTimeout(()=>{k(l.trim())},D);return()=>clearTimeout(e)},[l]),n.useEffect(()=>{h([]),y(0),g(!1)},[a,i]),n.useEffect(()=>{var o;if(!r)return;const e=r.query.trim();v(e),k(e),(o=j.current)==null||o.focus()},[r]),n.useEffect(()=>()=>{var e;(e=x.current)==null||e.abort()},[]),n.useEffect(()=>{var o;if(!a){h([]),g(!1);return}(o=x.current)==null||o.abort();const e=new AbortController;return x.current=e,p(!0),_.getMessages({q:a,limit:b,offset:0},e.signal).then(s=>{h(s),g(s.length>=b),y(s.length)}).catch(s=>{w(s)||console.error("Search failed:",s)}).finally(()=>{p(!1)}),()=>e.abort()},[a,i]);const M=n.useCallback(()=>{var o;if(!a||f)return;(o=x.current)==null||o.abort();const e=new AbortController;x.current=e,p(!0),_.getMessages({q:a,limit:b,offset:E},e.signal).then(s=>{h(u=>[...u,...s]),g(s.length>=b),y(u=>u+s.length)}).catch(s=>{w(s)||console.error("Search load more failed:",s)}).finally(()=>{p(!1)})},[a,f,E]),N=n.useCallback(e=>{if(e.type==="CHAN"){const s=d.find(u=>u.key.toUpperCase()===e.conversation_key.toUpperCase());return(s==null?void 0:s.name)||e.conversation_key.slice(0,8)}const o=c.find(s=>s.public_key.toLowerCase()===e.conversation_key.toLowerCase());return(o==null?void 0:o.name)||e.conversation_key.slice(0,12)},[c,d]),S=n.useCallback(e=>{m({id:e.id,type:e.type,conversation_key:e.conversation_key,conversation_name:N(e)})},[m,N]);return n.useEffect(()=>{var e;(e=j.current)==null||e.focus()},[]),t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsx("h2",{className:"flex justify-between items-center px-4 py-2.5 border-b border-border font-semibold text-base",children:"Message Search"}),t.jsx("div",{className:"px-4 py-3 border-b border-border",children:t.jsx(H,{ref:j,type:"text",placeholder:"Search all messages...",value:l,onChange:e=>v(e.target.value),className:"h-9 text-sm","aria-label":"Search messages"})}),t.jsxs("div",{className:"flex-1 overflow-y-auto",children:[!a&&t.jsxs("div",{className:"p-8 text-center text-muted-foreground text-sm",children:[t.jsx("p",{children:"Type to search across all messages"}),t.jsxs("p",{className:"mt-2 text-xs",children:["Tip: use ",t.jsx("code",{children:"user:"})," or ",t.jsx("code",{children:"channel:"})," for keys or names, and wrap names with spaces in them in quotes."]}),t.jsx("p",{className:"mt-2 text-xs",children:"Warning: User-key linkage for group messages is best-effort and based on correlation at advertise time. It does not account for multiple users with the same name, and should be considered unreliable."})]}),a&&C.length===0&&!f&&t.jsxs("div",{className:"p-8 text-center text-muted-foreground text-sm",children:["No messages found for “",a,"”"]}),C.map(e=>{const o=N(e),s=e.type==="CHAN"?"Channel":"DM";return t.jsxs("div",{className:"px-4 py-3 border-b border-border/50 cursor-pointer hover:bg-accent/50 transition-colors",role:"button",tabIndex:0,onClick:()=>S(e),onKeyDown:u=>{(u.key==="Enter"||u.key===" ")&&(u.preventDefault(),S(e))},children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[t.jsx("span",{className:I("text-[10px] font-medium px-1.5 py-0.5 rounded",e.type==="CHAN"?"bg-primary/20 text-primary":"bg-secondary text-secondary-foreground"),children:s}),t.jsx("span",{className:"text-[12px] font-medium text-foreground truncate",children:o}),t.jsx("span",{className:"text-[11px] text-muted-foreground ml-auto flex-shrink-0",children:Q(e.received_at)})]}),t.jsxs("div",{className:"text-[13px] text-foreground/80 line-clamp-2 break-words",children:[e.sender_name&&!e.outgoing&&t.jsxs("span",{className:"text-muted-foreground",children:[e.sender_name,": "]}),e.outgoing&&t.jsx("span",{className:"text-muted-foreground",children:"You: "}),T(e.sender_name&&e.text.startsWith(`${e.sender_name}: `)?e.text.slice(e.sender_name.length+2):e.text,R)]})]},e.id)}),f&&t.jsx("div",{className:"p-4 text-center text-muted-foreground text-sm",role:"status",children:"Searching..."}),A&&!f&&t.jsx("div",{className:"p-4 text-center",children:t.jsx(B,{variant:"outline",size:"sm",onClick:M,children:"Load more results"})})]})]})}export{$ as SearchView};
//# sourceMappingURL=SearchView-BFMnGDyJ.js.map