Files
jiang13-forum/embed_static/static/spa/assets/HomePage-D-Yzai0_.js
freefire e1c1708715 初始提交:姜十三论坛 Jiang13 Forum
轻量自用论坛,Go 单二进制 + React SPA 内嵌 + SQLite。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-15 21:08:52 +08:00

2 lines
6.1 KiB
JavaScript

import{j as e,r as m,e as v,i as C,t as L}from"./react-vendor-CgzNJrV9.js";import{n as P}from"./notify-Zesh5czd.js";import{u as k,B as j,a as B}from"./index-474mTIgd.js";import{u as A}from"./virtual-vendor-05wd80F5.js";import{S as T}from"./spinner-DH1syOsQ.js";import{B as S}from"./badge-CsEfIQQ2.js";import{f as _}from"./content-CKr4Ur51.js";import{m as z,j as H,q as R,F}from"./ui-vendor-CdH1UOKW.js";function G({post:a,onClick:o}){var n,l,t,r;const s=((l=(n=a.user)==null?void 0:n.nickname)==null?void 0:l[0])||"?";return e.jsxs("div",{className:"post-row",onClick:o,children:[e.jsx("div",{className:"post-avatar",children:(t=a.user)!=null&&t.avatar?e.jsx("img",{src:a.user.avatar,alt:""}):s}),e.jsxs("div",{className:"post-body",children:[e.jsxs("div",{className:"post-title",children:[a.pinned&&e.jsx(S,{variant:"orange",className:"mr-1.5",children:"置顶"}),a.title]}),e.jsxs("div",{className:"post-meta",children:[a.board&&e.jsx(S,{variant:"green",children:a.board.name}),e.jsx("span",{children:((r=a.user)==null?void 0:r.nickname)||"匿名"}),e.jsx("span",{children:_(a.created_at)})]})]}),e.jsxs("div",{className:"post-stats",children:[e.jsxs("span",{children:["💬 ",a.comment_count??0]}),e.jsxs("span",{children:["👍 ",a.like_count??0]})]})]})}function V({posts:a,loading:o,hasMore:s,onLoadMore:n,onSelect:l}){const t=m.useRef(null),r=A({count:a.length,getScrollElement:()=>t.current,estimateSize:()=>72,overscan:8});return m.useEffect(()=>{const i=t.current;if(!i)return;const c=()=>{i.scrollTop+i.clientHeight>=i.scrollHeight-120&&s&&!o&&n()};return i.addEventListener("scroll",c),()=>i.removeEventListener("scroll",c)},[s,o,n]),e.jsxs("div",{className:"post-list-scroll",ref:t,children:[e.jsx("div",{className:"content-surface",style:{height:r.getTotalSize(),position:"relative"},children:r.getVirtualItems().map(i=>{const c=a[i.index];return e.jsx("div",{style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${i.start}px)`},children:e.jsx(G,{post:c,onClick:()=>l(c.id)})},c.id)})}),o&&e.jsx("div",{className:"flex justify-center py-4",children:e.jsx(T,{})}),!o&&!s&&a.length>0&&e.jsx("div",{style:{textAlign:"center",padding:6,fontSize:12,color:"var(--color-text-3)"},children:"— 已加载全部 —"})]})}function q({boardId:a,keyword:o,boards:s,stats:n,postTotal:l}){const t=v(),{user:r,loading:i}=k(),c=s.find(x=>x.id===a),p=o?`搜索:${o}`:a&&c?c.name:"全部帖子",f=o?`找到 ${l} 篇相关帖子`:a&&c?c.description||"欢迎在本板块交流讨论":"姜十三论坛 · 拾三一隅,自在交流";return e.jsxs("div",{className:"feed-banner",children:[e.jsxs("div",{className:"feed-banner-row",children:[e.jsxs("div",{className:"feed-banner-title",children:[e.jsx("h2",{children:p}),e.jsx("p",{children:f})]}),!o&&e.jsxs("div",{className:"feed-actions flex flex-wrap items-center gap-2",children:[i?e.jsx("span",{className:"feed-action-slot","aria-hidden":!0}):r?e.jsxs(j,{size:"sm",onClick:()=>t(a?`/compose?board=${a}`:"/compose"),children:[e.jsx(z,{}),a?"在此发帖":"发布帖子"]}):e.jsx(j,{size:"sm",onClick:()=>t("/login"),children:"登录参与"}),!i&&(r==null?void 0:r.role)==="admin"&&e.jsxs(j,{size:"sm",variant:"outline",onClick:()=>t("/boards"),children:[e.jsx(H,{}),"管理板块"]})]})]}),e.jsxs("div",{className:"feed-stats",children:[e.jsxs("span",{children:["会员 ",e.jsx("strong",{children:(n==null?void 0:n.users)??"—"})]}),e.jsxs("span",{children:["帖子 ",e.jsx("strong",{children:(n==null?void 0:n.posts)??"—"})]}),e.jsxs("span",{children:["板块 ",e.jsx("strong",{children:(n==null?void 0:n.boards)??"—"})]})]})]})}function O({boards:a,loading:o=!1,selectedId:s=0,onSelect:n}){const l=v(),{user:t}=k();return o?e.jsx("div",{className:"board-grid board-grid--skeleton","aria-hidden":!0,children:Array.from({length:4},(r,i)=>e.jsx("div",{className:"board-tab board-tab--skeleton"},i))}):a.length===0?e.jsxs("div",{className:"board-grid-empty",children:[e.jsx("p",{className:"text-sm text-muted-foreground py-4 text-center",children:(t==null?void 0:t.role)==="admin"?"还没有板块,请先创建":"管理员尚未创建板块"}),(t==null?void 0:t.role)==="admin"&&e.jsx("div",{style:{textAlign:"center",marginTop:12},children:e.jsxs(j,{onClick:()=>l("/boards"),children:[e.jsx(z,{}),"创建板块"]})})]}):e.jsxs("div",{className:"board-grid",children:[e.jsxs("button",{type:"button",className:`board-tab ${s===0?"active":""}`,onClick:()=>n(0),children:[e.jsx("span",{className:"board-tab-icon",children:e.jsx(R,{size:16})}),e.jsx("span",{className:"board-tab-name",children:"全部帖子"})]}),a.map(r=>e.jsxs("button",{type:"button",className:`board-tab ${s===r.id?"active":""}`,title:r.description?`${r.name}${r.description}`:r.name,onClick:()=>n(r.id),children:[e.jsx("span",{className:"board-tab-icon",children:e.jsx(F,{size:16})}),e.jsx("span",{className:"board-tab-name",children:r.name})]},r.id))]})}function W(){const a=v(),[o]=C(),s=L(),n=Number(o.get("board"))||(s==null?void 0:s.boardId)||0,l=o.get("keyword")||"",[t,r]=m.useState([]),[i,c]=m.useState(0),[p,f]=m.useState(1),[x,E]=m.useState(!0),[g,b]=m.useState(!0),h=m.useCallback(async(d,N=!1)=>{b(!0);try{const u=await B.posts({page:d,size:30,board_id:n||"",keyword:l}),y=Array.isArray(u.posts)?u.posts:[];r($=>N?y:[...$,...y]),c(u.total??0),E(!!u.has_more),f(d)}catch(u){P.error(u instanceof Error?u.message:"加载失败"),N&&r([])}finally{b(!1)}},[n,l]);m.useEffect(()=>{h(1,!0)},[n,l,h]),m.useEffect(()=>{const d=()=>h(1,!0);return window.addEventListener("posts-refresh",d),()=>window.removeEventListener("posts-refresh",d)},[h]);const w=!l;return e.jsxs("div",{className:"page-wrap",children:[e.jsx(q,{boardId:n,keyword:l,boards:(s==null?void 0:s.boards)??[],stats:(s==null?void 0:s.stats)??null,postTotal:i}),w&&e.jsx(O,{boards:(s==null?void 0:s.boards)??[],loading:!(s!=null&&s.layoutReady),selectedId:n,onSelect:d=>{s==null||s.setBoardId(d),a(d?`/?board=${d}`:"/")}}),e.jsxs("div",{className:"post-list-bar",children:[e.jsx("span",{children:l?"搜索结果":"帖子列表"}),e.jsxs("span",{children:["共 ",i," 条"]})]}),e.jsx(V,{posts:t,loading:g,hasMore:x,onLoadMore:()=>!g&&x&&h(p+1),onSelect:d=>a(`/post/${d}`)})]})}export{W as default};