PageSourceSearch

https://app.peerx.ai/assets/community-I4kbiOhe.js

js peerx.ai collected 2026-10-05 12:26:31 UTC 11,624 bytes, 6 lines download raw bytes

1import{D as pe,H as u,r as s,a0 as ge,j as e,e as d,F as x,I as P,p,a3 as ye,A as fe,U as ve,X as be,S as K,K as je,M as Z,a1 as J,C as we,g as _,V as Ne}from"./index-CxO6BPM2.js";import{P as Ce,a as Se,b as ke,S as Ae,U as Pe,M as _e}from"./PortalLayout-vfu0ia6x.js";import{b as ee,a as Te}from"./format-BZR8EWyr.js";import{C as Ee}from"./check-circle-2-B-9PYNqu.js";import"./shield-check-DXFWcWX1.js";/**
2 * @license lucide-react v0.344.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const $e=pe("ThumbsUp",[["path",{d:"M7 10v12",key:"1qc93n"}],["path",{d:"M15 5.88 14 10h5.83a2 2 0 0 1 1.92 2.56l-2.33 8A2 2 0 0 1 17.5 22H4a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h2.76a2 2 0 0 0 1.79-1.11L12 2h0a3.13 3.13 0 0 1 3 3.88Z",key:"y3tblf"}]]),h="/developer/community",g={listPosts:async a=>{const{data:l}=await u.get(`${h}/posts`,{params:a});return l.data},getPost:async a=>{const{data:l}=await u.get(`${h}/posts/${a}`);return l.data},createPost:async a=>{const{data:l}=await u.post(`${h}/posts`,a);return l.data},addComment:async(a,l)=>{const{data:o}=await u.post(`${h}/posts/${a}/replies`,{content:l});return o.data},votePost:async(a,l)=>{const{data:o}=await u.post(`${h}/posts/${a}/upvote`,{direction:l});return o.data},getShowcases:async()=>{const{data:a}=await u.get(`${h}/showcases`);return a.data}},Be="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8",T=[{value:"question",label:"Question"},{value:"discussion",label:"Discussion"},{value:"show_and_tell",label:"Show and tell"},{value:"feature_request",label:"Feature request"},{value:"bug_report",label:"Bug report"}];function te(a){var l;return a?((l=T.find(o=>o.value===a))==null?void 0:l.label)??Ne(a):""}function ae(a){return a?a.displayName??a.display_name??([a.first_name,a.last_name].filter(Boolean).join(" ")||"A developer"):"A developer"}function se(a){var o;const l=Array.isArray(a.replies)?a.replies:Array.isArray(a.comments)?a.comments:[];return{id:String(a.id),title:a.title??"Untitled post",content:a.content??"",category:a.category??void 0,votes:Number(a.upvote_count??a.votes??0),replies:Number(((o=a._count)==null?void 0:o.replies)??a.commentCount??l.length??0),answered:!!(a.is_answered??a.isAnswered),author:ae(a.user??a.author),createdAt:a.created_at??a.createdAt,comments:l.map((i,j)=>({id:String(i.id??j),content:String(i.content??""),author:ae(i.user??i.author),accepted:!!(i.is_accepted??i.isAccepted),at:i.created_at??i.createdAt}))}}function Ie(){const[a,l]=s.useState([]),[o,i]=s.useState(!0),[j,E]=s.useState(!1),[re,y]=s.useState(!1),[w,$]=s.useState(""),[N,B]=s.useState(""),[L,ne]=s.useState("question"),[R,F]=s.useState({}),[q,C]=s.useState(null),[S,D]=s.useState(!1),[I,U]=s.useState(""),[k,M]=s.useState(""),[m,H]=s.useState(""),[r,Q]=s.useState(null),[f,V]=s.useState(""),[le,z]=s.useState(!1),[G,ie]=s.useState(new Set),A=s.useRef(null),W=s.useRef(null),v=ge(),c=async(t=k,n=m)=>{i(!0),E(!1);try{const b=await g.listPosts({search:t||void 0,category:n||void 0});l((Array.isArray(b)?b:[]).map(se))}catch{E(!0)}finally{i(!1)}};s.useEffect(()=>{c()},[]);const oe=()=>{const t=I.trim();M(t),c(t,m)},ce=t=>{H(t),c(k,t)},de=()=>{U(""),M(""),H(""),c("","")},X=()=>{F({}),C(null),y(!0)},O=async()=>{var n;const t={};if(w.trim().length<3&&(t.title="Give the post a title (at least 3 characters)."),N.trim().length<10&&(t.content="Write a little more so others can help (at least 10 characters)."),F(t),t.title||t.content){t.title&&((n=A.current)==null||n.focus());return}D(!0),C(null);try{await g.createPost({title:w.trim(),content:N.trim(),category:L}),$(""),B(""),y(!1),v.show({title:"Post published.",tone:"success"}),c()}catch(b){C(_(b,"Couldn't publish the post. Try again."))}finally{D(!1)}},ue=async t=>{try{await g.votePost(t.id,"up"),ie(n=>new Set(n).add(t.id)),c()}catch(n){v.show({title:"Couldn't record your upvote.",body:_(n,"Try again."),tone:"danger"})}},Y=async t=>{const n=await g.getPost(t);Q(se(n))},he=async t=>{try{await Y(t),window.setTimeout(()=>{var n;return(n=W.current)==null?void 0:n.focus()},0)}catch{v.show({title:"Couldn't open that post.",body:"Try again in a moment.",tone
6:"danger"})}},me=async()=>{if(!(!r||!f.trim())){z(!0);try{await g.addComment(r.id,f.trim()),V(""),await Y(r.id),c()}catch(t){v.show({title:"Couldn't post your reply.",body:_(t,"Your text is still in the box. Try again."),tone:"danger"})}finally{z(!1)}}},xe=!!(k||m);return e.jsx(Ce,{children:e.jsxs("div",{className:Be,children:[e.jsx(Se,{title:"Developer Community",description:"Questions, answers and things other developers have built on PeerX.",actions:e.jsx(d,{variant:"primary",leadingIcon:e.jsx(ke,{className:"h-4 w-4","aria-hidden":"true"}),onClick:X,children:"New post"})}),e.jsxs("div",{className:"mb-6 space-y-3",children:[e.jsxs("form",{role:"search",className:"flex gap-2",onSubmit:t=>{t.preventDefault(),oe()},children:[e.jsx(x,{label:"Search posts",hideLabel:!0,className:"min-w-0 flex-1",children:e.jsx(P,{type:"search",placeholder:"Search posts",value:I,onChange:t=>U(t.target.value)})}),e.jsx(d,{type:"submit",leadingIcon:e.jsx(Ae,{className:"h-4 w-4","aria-hidden":"true"}),children:"Search"})]}),e.jsx("div",{className:"-mx-4 overflow-x-auto px-4 sm:mx-0 sm:px-0",role:"group","aria-label":"Filter by category",children:e.jsx("div",{className:"flex w-max gap-1.5 sm:w-auto sm:flex-wrap",children:[{value:"",label:"All"},...T].map(t=>e.jsx("button",{type:"button","aria-pressed":m===t.value,onClick:()=>ce(t.value),className:p("h-8 whitespace-nowrap rounded-full px-3 text-small font-semibold transition-colors duration-fast",m===t.value?"bg-ink-900 text-white":"bg-white text-ink-700 shadow-field hover:bg-ink-50"),children:t.label},t.value||"all"))})})]}),e.jsx(ye,{open:re,onClose:()=>!S&&y(!1),title:"New post",description:"Posts are visible to every developer on PeerX. Leave out keys, secrets and customer data.",initialFocusRef:A,size:"lg",footer:e.jsxs(e.Fragment,{children:[e.jsx(d,{onClick:()=>y(!1),disabled:S,children:"Cancel"}),e.jsx(d,{variant:"primary",onClick:O,loading:S,children:"Publish post"})]}),children:e.jsxs("form",{noValidate:!0,className:"flex flex-col gap-5",onSubmit:t=>{t.preventDefault(),O()},children:[q&&e.jsx(fe,{tone:"danger",role:"alert",title:"The post was not published.",children:q}),e.jsx(x,{label:"Title",error:R.title,children:e.jsx(P,{ref:A,value:w,onChange:t=>$(t.target.value),maxLength:200})}),e.jsx(x,{label:"Category",children:e.jsx(ve,{value:L,onChange:t=>ne(t.target.value),children:T.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))})}),e.jsx(x,{label:"Post",error:R.content,children:e.jsx(be,{value:N,onChange:t=>B(t.target.value),rows:6})})]})}),e.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-3",children:[e.jsx("div",{className:p("min-w-0",r?"lg:col-span-2":"lg:col-span-3"),children:o?e.jsx("div",{className:"space-y-3","aria-busy":"true","aria-label":"Loading posts",children:Array.from({length:4}).map((t,n)=>e.jsxs("div",{className:"rounded-sheet bg-white p-5 shadow-sheet",children:[e.jsx(K,{className:"mb-3 h-5 w-64"}),e.jsx(K,{className:"h-4 w-48"})]},n))}):j?e.jsx(je,{title:"Couldn't load posts.",description:"Check your connection, then try again.",onRetry:()=>c()}):a.length===0?xe?e.jsx(Z,{kind:"no-match",title:"No posts match",description:"Try other words, or look in every category.",action:e.jsx(d,{onClick:de,children:"Clear filters"})}):e.jsx(Z,{icon:e.jsx(Pe,{"aria-hidden":"true"}),title:"No posts yet",description:"Ask a question or show something you built. Other developers can reply and upvote.",action:e.jsx(d,{variant:"primary",onClick:X,children:"Write the first post"})}):e.jsx("ul",{className:"space-y-3",children:a.map(t=>{const n=(r==null?void 0:r.id)===t.id;return e.jsxs("li",{className:p("flex gap-3 rounded-sheet bg-white p-4 shadow-sheet sm:p-5",n&&"shadow-[inset_3px_0_0_rgb(var(--prussian-600)),var(--shadow-sheet)]"),children:[e.jsx("div",{className:"flex shrink-0 flex-col items-center",children:e.jsxs("button",{type:"button",onClick:()=>ue(t),"aria-pressed":G.has(t.id),"aria-label":`Upvote "${t.title}", ${t.votes} ${t.votes===1?"vote":"votes"}`,className:p("flex min-h-[44px] w-11 flex-col items-center justify-center rounded-control text-small tabular-nums transition-colors duration-fast",G.has(t.id)?"bg-prussian-50 text-prussian-700":"text-ink-600 hover:bg-ink-100"),children:[e.jsx($e,{className:"h-4 w-4","aria-hidden":"true"}),e.jsx("span",{className:"font-semibold",children:t.votes})]})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"mb-1 flex flex-wrap items-center gap-2",children:[t.category&&e.jsx(J,{children:te(t.category)}),t.answered&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-small font-semibold text-success-700",children:[e.jsx(Ee,{className:"h-3.5 w-3.5","aria-hidden":"true"})," Answered"]})]}),e.jsx("h2",{className:"text-h4 text-ink-900",children:e.jsx("button",{type:"button",onClick:()=>he(t.id),"aria-current":n?"true":void 0,className:"text-left hover:text-prussian-700 hover:underline",children:t.title})}),e.jsx("p",{className:"mt-1 line-clamp-2 text-body-ui text-ink-600",children:t.content}),e.jsxs("p",{className:"mt-2 flex flex-wrap items-center gap-x-1 text-small text-ink-500",children:[e.jsxs("span",{children:[[t.author,t.createdAt&&ee(t.createdAt)].filter(
6Boolean).join(", "),","]}),e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(_e,{className:"h-3 w-3","aria-hidden":"true"}),t.replies," ",t.replies===1?"reply":"replies"]})]})]})]},t.id)})})}),r&&e.jsx("div",{className:"min-w-0 lg:col-span-1",children:e.jsxs(we,{as:"section","aria-labelledby":"post-detail-title",className:"lg:sticky lg:top-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-ink-200 px-[18px] py-3.5",children:[e.jsxs("div",{className:"min-w-0",children:[r.category&&e.jsx(J,{className:"mb-1.5",children:te(r.category)}),e.jsx("h2",{id:"post-detail-title",ref:W,tabIndex:-1,className:"text-h3 text-ink-900 outline-none",children:r.title}),e.jsx("p",{className:"mt-1 text-small text-ink-500",children:[r.author,r.createdAt&&ee(r.createdAt)].filter(Boolean).join(", ")})]}),e.jsx(d,{variant:"quiet",size:"sm",onClick:()=>Q(null),children:"Hide"})]}),e.jsxs("div",{className:"space-y-4 p-[18px]",children:[e.jsx("p",{className:"whitespace-pre-wrap text-body-ui text-ink-800",children:r.content}),e.jsxs("div",{className:"border-t border-ink-200 pt-3",children:[e.jsxs("h3",{className:"mb-2 text-label text-ink-900",children:["Replies ",e.jsx("span",{className:"font-normal text-ink-500",children:r.comments.length})]}),r.comments.length>0?e.jsx("ul",{className:"mb-3 max-h-72 space-y-2 overflow-y-auto",children:r.comments.map(t=>e.jsxs("li",{className:p("rounded-control p-2.5 text-body-ui",t.accepted?"bg-success-50":"bg-ink-100"),children:[e.jsx("p",{className:"whitespace-pre-wrap text-ink-800",children:t.content}),e.jsx("p",{className:"mt-1 text-small text-ink-500",children:[t.author,t.at&&Te(t.at),t.accepted&&"accepted answer"].filter(Boolean).join(", ")})]},t.id))}):e.jsx("p",{className:"mb-3 text-small text-ink-600",children:"No replies yet. If you know the answer, add it below."}),e.jsxs("form",{className:"flex items-end gap-2",onSubmit:t=>{t.preventDefault(),me()},children:[e.jsx(x,{label:"Your reply",hideLabel:!0,className:"min-w-0 flex-1",children:e.jsx(P,{value:f,onChange:t=>V(t.target.value),placeholder:"Write a reply"})}),e.jsx(d,{type:"submit",variant:"primary",loading:le,disabled:!f.trim(),children:"Reply"})]})]})]})]})})]})]})})}export{Ie as DeveloperCommunity};

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.