paperswithcode / assets /FeedView-BqrFUUTv.js
nielsr's picture
nielsr HF Staff
Sync paperswithcode.co frontend
14aee29 verified
Raw
History Blame Contribute Delete
7.21 kB
import{u as O,r as p,j as e,a as H,L as _,i as F,b as E}from"./index-Dq4RFSP6.js";import{P as I}from"./components-DBbWeY7C.js";import{P as q}from"./PaperFeedFilters-BTKWN703.js";import{D as U,M as $,F as K,A as B,q as W}from"./chatSessions-DWxbbxRV.js";import{S as g}from"./chatPrompts-CDY3UGU1.js";import{t as G,d as k}from"./transform-CS_gDjup.js";import{u as z}from"./usePapers-DFmW9Gpm.js";import{u as Q}from"./useIntersectionObserver-IFiQEVhu.js";import{P as V}from"./usePeriodFilter-B8XcbYlT.js";import{S as f}from"./skeleton-sJ8QzNCc.js";import{A as X,a as Y}from"./alert-DkYT-uGd.js";import{u as L}from"./useQuery-CeQZ3vLa.js";import"./LatexTitle-B7lMgvUc.js";import"./katex.min-BSBacQyE.js";import"./useInfiniteQuery-C2PLDxSB.js";import"./useBaseQuery-BPHJ2Zjo.js";const J=[["trending","trending"],["date_published","newest"],["citation_count","most cited"]],Z={Today:"today","This Week":"week","This Month":"month","All Time":"all_time"},ee={today:"Today",week:"This Week",month:"This Month",all_time:"All Time"},S=45,se=1800,te=25,ae=350,re=a=>{const[i,d]=p.useState(g[0].slice(0,1));return p.useEffect(()=>{var r,u;if(!a)return;if((u=(r=window.matchMedia)==null?void 0:r.call(window,"(prefers-reduced-motion: reduce)"))!=null&&u.matches){d(g[0]);return}let m=0,n=1,h=!1,o;d(g[0].slice(0,n));const l=()=>{const x=g[m];if(!h){if(n+=1,d(x.slice(0,n)),n===x.length){h=!0,o=window.setTimeout(l,se);return}o=window.setTimeout(l,S);return}if(n-=1,d(x.slice(0,n)),n===0){h=!1,m=(m+1)%g.length,o=window.setTimeout(l,ae);return}o=window.setTimeout(l,te)};return o=window.setTimeout(l,S),()=>window.clearTimeout(o)},[a]),i},ie=a=>a==="trending"||a==="date_published"||a==="citation_count"?a:"trending",ne=a=>a==="today"||a==="week"||a==="month"||a==="all_time"?a:"all_time",oe=()=>{const a=O(),[i,d]=p.useState(""),[m,n]=p.useState(U),h=re(!i),o=p.useRef(null);p.useEffect(()=>{const r=o.current;r&&(r.style.height="auto",r.style.height=`${Math.min(r.scrollHeight,160)}px`)},[i]);const l=(r=i)=>{const u=r.trim();u&&(W(u,m),a("/chat"))};return e.jsxs("div",{className:"ask-home",children:[e.jsx("textarea",{ref:o,rows:1,value:i,placeholder:h,"aria-label":"Ask the assistant",onChange:r=>d(r.target.value),onKeyDown:r=>{r.key==="Enter"&&!r.shiftKey&&(r.preventDefault(),l())}}),e.jsxs("div",{className:"ask-home-foot",children:[e.jsxs("div",{className:"ask-home-provider-tools",children:[e.jsx($,{models:K,selectedModel:m,onModelChange:n}),e.jsxs("span",{className:"ask-home-hint",children:["Via 🤗"," ",e.jsx("a",{href:"https://huggingface.co/docs/inference-providers/en/index",target:"_blank",rel:"noreferrer",children:"Inference Providers"})]})]}),e.jsx("button",{type:"button",className:`chat-send${i.trim()?" chat-send-on":""}`,onClick:()=>l(),disabled:!i.trim(),"aria-label":"Ask the assistant",children:e.jsx(B,{})})]})]})},we=()=>{var b,w,v,P,A;const[a,i]=H(),d=ie(a.get("order_by")),m=ne(a.get("time")),n=a.get("has_code")==="true",h=a.get("has_hf_artifacts")==="true",o=ee[m],l=s=>{const t=new URLSearchParams(a);t.set("order_by",s),i(t)},r=s=>{const t=new URLSearchParams(a);t.set("time",Z[s]),i(t)},u=s=>{const t=new URLSearchParams(a);s?t.set("has_code","true"):t.delete("has_code"),i(t)},x=s=>{const t=new URLSearchParams(a);s?t.set("has_hf_artifacts","true"):t.delete("has_hf_artifacts"),i(t)},N=L({queryKey:["top-tasks-sidebar"],queryFn:()=>E.getTopTasks({limit:8}),staleTime:10*60*1e3}),j=L({queryKey:["trending-tasks-sidebar"],queryFn:()=>E.getTrendingTasks({limit:8,level:0}),staleTime:10*60*1e3}),c=z({page_size:30,order_by:d,order_dir:"desc",time:m,include_resources:!0,has_code:n,has_hf_artifacts:h}),y=p.useMemo(()=>{var t;return(((t=c.data)==null?void 0:t.pages.flatMap(R=>R.results))||[]).map(G)},[c.data]),{targetRef:C,isIntersecting:T}=Q({rootMargin:"400px"});p.useEffect(()=>{T&&c.hasNextPage&&!c.isFetchingNextPage&&c.fetchNextPage()},[T,c.hasNextPage,c.isFetchingNextPage]);const M=c.isLoading,D=c.error;return e.jsxs("div",{className:"page",children:[e.jsx("div",{className:"feed-header",children:e.jsxs("div",{children:[e.jsxs("h1",{className:"feed-title",children:["Trending ",e.jsx("em",{children:"Research"})]}),e.jsx("div",{className:"feed-subtitle",children:"Curated daily from arXiv and Hugging Face"})]})}),e.jsxs("div",{className:"layout-with-sidebar",children:[e.jsxs("aside",{className:"sidebar",children:[e.jsxs("div",{className:"sidebar-section",children:[e.jsx("div",{className:"sidebar-label",children:"Top Domains"}),N.isLoading&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:Array.from({length:6}).map((s,t)=>e.jsx(f,{className:"h-5 w-full"},t))}),(b=N.data)==null?void 0:b.map(s=>e.jsxs(_,{to:`/tasks/${s.slug}`,className:"sidebar-link",children:[k(s.name,s.slug),s.paper_count!=null&&e.jsx("span",{className:"count",children:s.paper_count})]},s.id)),e.jsx(_,{to:"/tasks",className:"sidebar-link",style:{marginTop:8,fontStyle:"italic"},children:"all domains →"})]}),e.jsxs("div",{className:"sidebar-section",children:[e.jsx("div",{className:"sidebar-label",children:"Trending Domains"}),j.isLoading&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:8},children:Array.from({length:6}).map((s,t)=>e.jsx(f,{className:"h-5 w-full"},t))}),((v=(w=j.data)==null?void 0:w.results)==null?void 0:v.length)===0&&!j.isLoading&&e.jsx("div",{style:{fontSize:12,color:"var(--ink-faint)"},children:"No domains gaining momentum right now."}),(A=(P=j.data)==null?void 0:P.results)==null?void 0:A.map(s=>e.jsxs(_,{to:`/tasks/${s.slug}`,className:"sidebar-link",children:[k(s.name,s.slug),e.jsxs("span",{className:"count",children:[s.share_lift.toFixed(1),"x"]})]},s.id))]})]}),e.jsxs("div",{children:[F()&&e.jsx(oe,{}),e.jsxs("div",{className:"sort-bar home-feed-sort-bar",children:[e.jsxs("div",{className:"paper-feed-toolbar-controls",children:[e.jsx("div",{className:"sort-options",children:J.map(([s,t])=>e.jsx("button",{className:`sort-btn ${d===s?"active":""}`,onClick:()=>l(s),children:t},s))}),e.jsx(q,{hasCode:n,hasHfArtifacts:h,onHasCodeChange:u,onHasHfArtifactsChange:x})]}),e.jsx("div",{className:"sort-options sort-options-time",children:V.map(s=>e.jsx("button",{className:`sort-btn sort-btn-time ${o===s?"active":""}`,onClick:()=>r(s),children:s},s))})]}),D&&e.jsx(X,{variant:"destructive",className:"mb-4",children:e.jsx(Y,{children:"Failed to load papers. Please try again."})}),M?e.jsx("div",{className:"paper-list",children:Array.from({length:6}).map((s,t)=>e.jsxs("div",{className:"paper-card",children:[e.jsx("div",{className:"paper-thumb-wrap",children:e.jsx(f,{className:"paper-thumb-skeleton"})}),e.jsxs("div",{className:"paper-body",style:{flex:1,gap:12},children:[e.jsx(f,{className:"h-6 w-3/4"}),e.jsx(f,{className:"h-4 w-1/2"}),e.jsx(f,{className:"h-12 w-full"})]})]},t))}):y.length===0?e.jsx("div",{className:"no-results",children:"No papers in this window."}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"paper-list",children:y.map((s,t)=>e.jsx(I,{paper:s,rank:t+1},s.id))}),e.jsx("div",{ref:C,style:{height:1}}),c.isFetchingNextPage&&e.jsx("div",{style:{padding:"20px 0",textAlign:"center",color:"var(--ink-faint)"},children:"Loading more…"})]})]})]})]})};export{oe as AskAssistant,we as default};