Files
links/static/dist/search.js
T
2026-07-30 13:25:36 +10:00

1 line
12 KiB
JavaScript

import{i as e,n as t,r as n,t as r}from"./jsx-runtime-COXMab3W.js";var i=e(n()),a=e(t()),o=r(),s=({children:e,variant:t=`default`,className:n=``})=>(0,o.jsx)(`span`,{className:`inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${{default:`bg-gray-100 text-gray-800`,link:`bg-blue-100 text-blue-800`,page:`bg-green-100 text-green-800`,post:`bg-purple-100 text-purple-800`,bookmark:`bg-sky-100 text-sky-800`}[t]} ${n}`,children:e}),c=({children:e,className:t=``,hover:n=!1})=>(0,o.jsx)(`div`,{className:`bg-white rounded-lg shadow-sm border border-gray-200 ${n?`hover:shadow-md transition-shadow duration-200`:``} ${t}`,children:e}),l=({className:e=``,...t})=>(0,o.jsx)(`input`,{className:`flex h-10 w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm ring-offset-white file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-gray-500 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:cursor-not-allowed disabled:opacity-50 ${e}`,...t}),u=({children:e,className:t=``,...n})=>(0,o.jsx)(`select`,{className:`flex h-10 w-full rounded-md border border-gray-300 bg-white px-3 py-2 text-sm ring-offset-white focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent disabled:cursor-not-allowed disabled:opacity-50 ${t}`,...n,children:e}),d=({children:e,variant:t=`default`,className:n=``,...r})=>(0,o.jsx)(`button`,{className:`inline-flex items-center justify-center rounded-md px-4 py-2 text-sm font-medium ring-offset-white transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 ${{default:`bg-blue-600 text-white hover:bg-blue-700`,outline:`border-2 border-gray-300 bg-white hover:bg-gray-50`,ghost:`hover:bg-gray-100`}[t]} ${n}`,...r,children:e}),f=({className:e=``})=>(0,o.jsx)(`div`,{className:`shimmer rounded ${e}`}),p=({result:e})=>{let t={link:`fa-link`,page:`fa-file-alt`,post:`fa-newspaper`,bookmark:`fa-bookmark`},n=e=>new Date(e).toLocaleDateString(`en-US`,{year:`numeric`,month:`short`,day:`numeric`}),r=e.type===`bookmark`,i=e.type===`link`?`bg-blue-100 text-blue-600`:e.type===`page`?`bg-green-100 text-green-600`:e.type===`post`?`bg-purple-100 text-purple-600`:e.type===`bookmark`?`bg-sky-100 text-sky-600`:`bg-gray-100 text-gray-600`,a=r?e.detail_url||e.url:e.type===`link`?e.url:e.detail_url||e.url,l=e.type===`link`||r?`_blank`:`_self`,u=e.type===`link`||r?`noopener noreferrer`:``;return(0,o.jsx)(c,{hover:!0,className:`p-4`,children:(0,o.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,o.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:r&&e.author_profile_image_url?(0,o.jsx)(`img`,{src:e.author_profile_image_url,alt:``,className:`w-10 h-10 rounded-full object-cover border border-gray-200`,loading:`lazy`}):(0,o.jsx)(`div`,{className:`w-10 h-10 rounded-full flex items-center justify-center ${i}`,children:(0,o.jsx)(`i`,{className:`fas ${t[e.type]||`fa-circle`}`})})}),(0,o.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,o.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,o.jsx)(`a`,{href:a,className:`text-lg font-semibold text-gray-900 hover:text-blue-600 transition-colors truncate`,target:l,rel:u,children:r?`@${e.author_screen_name}`:e.title}),(0,o.jsx)(s,{variant:e.type,children:e.type})]}),r?(0,o.jsxs)(o.Fragment,{children:[(e.text||e.summary||e.title)&&(0,o.jsx)(`p`,{className:`text-sm text-gray-700 line-clamp-3 mb-2 whitespace-pre-wrap`,children:e.summary?e.summary:e.text||e.title}),e.has_photo&&(0,o.jsxs)(`span`,{className:`inline-flex items-center text-xs text-gray-500 mr-3`,children:[(0,o.jsx)(`i`,{className:`fas fa-image mr-1`}),`photo`]}),e.has_video&&(0,o.jsxs)(`span`,{className:`inline-flex items-center text-xs text-gray-500 mr-3`,children:[(0,o.jsx)(`i`,{className:`fas fa-video mr-1`}),`video`]}),(0,o.jsxs)(`a`,{href:e.url||e.detail_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center text-xs text-blue-600 hover:underline mr-3`,children:[(0,o.jsx)(`i`,{className:`fas fa-external-link-alt mr-1`}),`Open on X`]}),(0,o.jsxs)(`a`,{href:e.detail_url,className:`inline-flex items-center text-xs text-gray-500 hover:text-gray-800`,children:[(0,o.jsx)(`i`,{className:`fas fa-list mr-1`}),`Detail`]})]}):(0,o.jsxs)(o.Fragment,{children:[e.type===`link`&&e.original_url&&(0,o.jsxs)(`a`,{href:e.original_url,className:`text-sm text-gray-600 hover:text-gray-900 truncate block mb-2`,target:`_blank`,rel:`noopener noreferrer`,children:[(0,o.jsx)(`i`,{className:`fas fa-external-link-alt mr-1`}),e.original_url]}),(e.description||e.summary)&&(0,o.jsx)(`p`,{className:`text-sm text-gray-600 line-clamp-2 mb-2`,children:e.description||e.summary}),(0,o.jsxs)(`div`,{className:`flex items-center gap-4 text-xs text-gray-500`,children:[(0,o.jsxs)(`span`,{children:[(0,o.jsx)(`i`,{className:`fas fa-calendar mr-1`}),n(e.created_at)]}),e.click_count!==void 0&&(0,o.jsxs)(`span`,{children:[(0,o.jsx)(`i`,{className:`fas fa-mouse-pointer mr-1`}),e.click_count,` clicks`]})]}),e.tags&&e.tags.length>0&&(0,o.jsx)(`div`,{className:`flex flex-wrap gap-1 mt-2`,children:e.tags.map(e=>(0,o.jsxs)(s,{variant:`default`,className:`text-xs`,children:[(0,o.jsx)(`i`,{className:`fas fa-tag mr-1`}),e.name]},e.id))})]})]}),!r&&(0,o.jsx)(`div`,{className:`flex-shrink-0`,children:(0,o.jsx)(`a`,{href:e.type===`link`?`/link/${e.id}/edit/`:e.type===`page`?`/ui/pages/${e.id}/edit/`:`/ui/posts/${e.id}/edit/`,className:`text-gray-400 hover:text-blue-600 transition-colors`,title:`Edit`,children:(0,o.jsx)(`i`,{className:`fas fa-edit`})})})]})})};a.createRoot(document.getElementById(`root`)).render((0,o.jsx)(()=>{let[e,t]=(0,i.useState)(``),[n,r]=(0,i.useState)(``),[a,s]=(0,i.useState)(`relevance`),[m,h]=(0,i.useState)(!1),[g,_]=(0,i.useState)([]),[v,y]=(0,i.useState)(!1),[b,x]=(0,i.useState)(0),[S,C]=(0,i.useState)(1),[w,T]=(0,i.useState)(null),E=(0,i.useCallback)(async(e,t,n,r)=>{if(!e.trim()){_([]),x(0);return}y(!0),T(null);try{let i=new URLSearchParams({q:e,type:t,sort:n,page:r,per_page:20}),a=await fetch(`${m?`/search/api/vector/`:`/search/api/v2/`}?${i}`),o=await a.json();a.ok?(_(o.results),x(o.total)):(T(o.error||`Search failed`),_([]))}catch{T(`Network error. Please try again.`),_([])}finally{y(!1)}},[m]),D=(0,i.useCallback)(t=>{t.preventDefault(),C(1),E(e,n,a,1)},[e,n,a,E]);(0,i.useEffect)(()=>{let e=new URLSearchParams(window.location.search),n=e.get(`q`)||``,i=e.get(`type`)||``,a=e.get(`sort`)||`relevance`;t(n),r(i),s(a),n&&E(n,i,a,1)},[E]),(0,i.useEffect)(()=>{if(e){let t=new URLSearchParams({q:e,...n&&{type:n},...a!==`relevance`&&{sort:a}});window.history.replaceState({},``,`?${t}`)}},[e,n,a]);let O=t=>{C(t),E(e,n,a,t),window.scrollTo({top:0,behavior:`smooth`})},k=Math.ceil(b/20);return(0,o.jsx)(`div`,{className:`min-h-screen py-8 px-4 sm:px-6 lg:px-8`,children:(0,o.jsxs)(`div`,{className:`max-w-5xl mx-auto`,children:[(0,o.jsxs)(`div`,{className:`mb-8 text-center`,children:[(0,o.jsx)(`a`,{href:`/`,className:`inline-block hover:opacity-80 transition-opacity`,children:(0,o.jsxs)(`h1`,{className:`text-4xl font-bold text-gray-900 mb-2 flex items-center justify-center gap-3`,children:[(0,o.jsx)(`i`,{className:`fas fa-search text-blue-600`}),`Advanced Search`]})}),(0,o.jsx)(`p`,{className:`text-gray-600`,children:`Search through all Links, Pages, Posts and Bookmarks`})]}),(0,o.jsx)(c,{className:`p-6 mb-8 glass`,children:(0,o.jsxs)(`form`,{onSubmit:D,className:`space-y-4`,children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 mb-2`,children:`Search Query`}),(0,o.jsxs)(`div`,{className:`relative`,children:[(0,o.jsx)(`i`,{className:`fas fa-search absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400`}),(0,o.jsx)(l,{type:`text`,value:e,onChange:e=>t(e.target.value),placeholder:`Enter keywords to search...`,className:`pl-10`})]})]}),(0,o.jsxs)(`div`,{className:`grid grid-cols-1 md:grid-cols-2 gap-4`,children:[(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 mb-2`,children:`Filter by Type`}),(0,o.jsxs)(u,{value:n,onChange:e=>r(e.target.value),children:[(0,o.jsx)(`option`,{value:``,children:`All Types`}),(0,o.jsx)(`option`,{value:`link`,children:`Links`}),(0,o.jsx)(`option`,{value:`page`,children:`Pages`}),(0,o.jsx)(`option`,{value:`post`,children:`Posts`}),(0,o.jsx)(`option`,{value:`bookmark`,children:`Bookmarks`})]})]}),(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 mb-2`,children:`Sort By`}),(0,o.jsxs)(`div`,{className:`flex items-center gap-2 mb-2`,children:[(0,o.jsx)(`label`,{className:`text-sm font-medium text-gray-700`,children:`AI Vector Search`}),(0,o.jsx)(`input`,{type:`checkbox`,checked:m,onChange:e=>h(e.target.checked),className:`h-4 w-4 text-blue-600 focus:ring-blue-500 border-gray-300 rounded`})]}),(0,o.jsxs)(u,{value:a,onChange:e=>s(e.target.value),disabled:m,children:[(0,o.jsx)(`option`,{value:`relevance`,children:`Most Relevant`}),(0,o.jsx)(`option`,{value:`newest`,children:`Newest First`}),(0,o.jsx)(`option`,{value:`oldest`,children:`Oldest First`})]})]})]}),(0,o.jsx)(d,{type:`submit`,className:`w-full`,disabled:v,children:v?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`i`,{className:`fas fa-spinner fa-spin mr-2`}),`Searching...`]}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)(`i`,{className:`fas fa-search mr-2`}),`Search`]})})]})}),e&&(0,o.jsxs)(`div`,{children:[(0,o.jsx)(`div`,{className:`mb-4 flex items-center justify-between`,children:(0,o.jsx)(`h2`,{className:`text-lg font-semibold text-gray-900`,children:v?`Searching...`:w?(0,o.jsxs)(`span`,{className:`text-red-600`,children:[(0,o.jsx)(`i`,{className:`fas fa-exclamation-circle mr-2`}),w]}):(0,o.jsxs)(o.Fragment,{children:[`Search results for: `,(0,o.jsxs)(`span`,{className:`text-blue-600`,children:[`"`,e,`"`]}),b>0&&(0,o.jsxs)(`span`,{className:`text-gray-500 text-sm ml-2`,children:[`(`,b,` `,b===1?`result`:`results`,`)`]})]})})}),v&&(0,o.jsx)(`div`,{className:`space-y-4`,children:[1,2,3].map(e=>(0,o.jsx)(c,{className:`p-4`,children:(0,o.jsxs)(`div`,{className:`flex items-start gap-4`,children:[(0,o.jsx)(f,{className:`w-10 h-10 rounded-full`}),(0,o.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,o.jsx)(f,{className:`h-5 w-3/4`}),(0,o.jsx)(f,{className:`h-4 w-full`}),(0,o.jsx)(f,{className:`h-4 w-1/2`})]})]})},e))}),!v&&!w&&g.length>0&&(0,o.jsx)(`div`,{className:`space-y-4`,children:g.map(e=>(0,o.jsx)(p,{result:e},`${e.type}-${e.id}`))}),!v&&!w&&g.length===0&&e&&(0,o.jsxs)(c,{className:`p-12 text-center`,children:[(0,o.jsx)(`i`,{className:`fas fa-search text-6xl text-gray-300 mb-4`}),(0,o.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 mb-2`,children:`No results found`}),(0,o.jsx)(`p`,{className:`text-gray-500`,children:`Try adjusting your search terms or filters`})]}),!v&&k>1&&(0,o.jsxs)(`div`,{className:`mt-8 flex items-center justify-center gap-2`,children:[(0,o.jsxs)(d,{variant:`outline`,onClick:()=>O(S-1),disabled:S===1,children:[(0,o.jsx)(`i`,{className:`fas fa-chevron-left mr-2`}),`Previous`]}),(0,o.jsx)(`div`,{className:`flex items-center gap-2`,children:[...Array(Math.min(5,k))].map((e,t)=>{let n;return n=k<=5||S<=3?t+1:S>=k-2?k-4+t:S-2+t,(0,o.jsx)(d,{variant:S===n?`default`:`outline`,onClick:()=>O(n),className:`w-10 h-10 p-0`,children:n},n)})}),(0,o.jsxs)(d,{variant:`outline`,onClick:()=>O(S+1),disabled:S===k,children:[`Next`,(0,o.jsx)(`i`,{className:`fas fa-chevron-right ml-2`})]})]})]}),!e&&(0,o.jsxs)(c,{className:`p-12 text-center glass`,children:[(0,o.jsx)(`i`,{className:`fas fa-search text-6xl text-blue-200 mb-4`}),(0,o.jsx)(`h3`,{className:`text-xl font-medium text-gray-900 mb-2`,children:`Start Searching`}),(0,o.jsx)(`p`,{className:`text-gray-600 max-w-md mx-auto`,children:`Enter a search query to find links, pages, posts, and bookmarks. You can search by title, content, URL, or tags.`})]})]})})},{}));