You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2 lines
7.0 KiB
2 lines
7.0 KiB
import{j as t}from"./markdown-vendor-DnN-_XEd.js";import{u as le,r}from"./data-vendor-DOiUz3Tw.js";import{bd as ue,a as re,be as fe}from"./index-CcS3ZJ2N.js";import{D as de}from"./arco-vendor-Cm-ntj-q.js";import"./react-vendor-B8OyfHW2.js";const o={OFFICIAL:"official",COMMUNITY:"community"};function F(y){const m=y;return Array.isArray(m?.data?.list)?m.data.list:Array.isArray(m?.list)?m.list:[]}const x=120;function ye({onClose:y,onSelect:m}){const{t:i}=le(),E=r.useRef(null),T=r.useRef(null),B=r.useRef(null),[P,te]=r.useState(""),[u,ae]=r.useState(""),[ce,U]=r.useState([]),[D,H]=r.useState(1),[b,j]=r.useState(!0),[N,Y]=r.useState(!1),M=r.useRef(!1),L=r.useRef(new Set),[se,z]=r.useState([]),[G,q]=r.useState(1),[C,S]=r.useState(!0),[v,V]=r.useState(!1),O=r.useRef(!1),R=r.useRef(new Set),[ie,K]=r.useState([]),[n,Z]=r.useState(o.OFFICIAL),[w,J]=r.useState([]),[d,Q]=r.useState(null),[W,p]=r.useState(!1);r.useEffect(()=>{const e=window.setTimeout(()=>{ae(P.trim())},300);return()=>window.clearTimeout(e)},[P]),r.useEffect(()=>{ue().then(e=>{const a=e.data,s=Array.isArray(a)?a:[];s.sort((c,f)=>(c.sortNum??0)-(f.sortNum??0)),J(s)}).catch(()=>{J([])})},[]);const k=r.useCallback((e,a)=>{if(a&&(M.current||L.current.has(e)))return;a?(M.current=!0,Y(!0)):L.current.clear();const s={uploadCharacter:!0,page:e,pageSize:x};u&&(s.keyword=u);let c=!1;return re(s).then(f=>{if(c)return;const l=F(f);U(h=>{if(!a)return l;const A=new Set(h.map(g=>String(g.id??""))),_=l.filter(g=>!A.has(String(g.id??"")));return _.length===0?h:[...h,..._]}),H(e),j(l.length>=x),L.current.add(e)}).catch(()=>{!c&&!a&&U([]),j(!1)}).finally(()=>{c||a&&(M.current=!1,Y(!1))}),()=>{c=!0}},[u]),I=r.useCallback((e,a)=>{if(n!==o.OFFICIAL||a&&(O.current||R.current.has(e)))return;a?(O.current=!0,V(!0)):R.current.clear();const s={type:1,page:e,pageSize:x};d!=null&&(s.categoryId=d),u&&(s.keyword=u);let c=!1;return re(s).then(f=>{if(c)return;const l=F(f);z(h=>{if(!a)return l;const A=new Set(h.map(g=>String(g.id??""))),_=l.filter(g=>!A.has(String(g.id??"")));return _.length===0?h:[...h,..._]}),q(e),S(l.length>=x),R.current.add(e)}).catch(()=>{!c&&!a&&z([]),S(!1)}).finally(()=>{c||a&&(O.current=!1,V(!1))}),()=>{c=!0}},[n,u,d]);r.useEffect(()=>(H(1),j(!0),k(1,!1)),[k]),r.useEffect(()=>(q(1),S(!0),I(1,!1)),[I]);const X=r.useCallback(()=>{N||!b||k(D+1,!0)},[k,b,N,D]),$=r.useCallback(()=>{v||!C||I(G+1,!0)},[I,C,v,G]);r.useEffect(()=>{if(!b)return;const e=T.current;if(!e)return;const a=e.parentElement;if(!a)return;const s=new IntersectionObserver(f=>{f.some(l=>l.isIntersecting)&&X()},{root:a,rootMargin:"240px 0px",threshold:0}),c=document.createElement("div");return c.style.height="1px",e.appendChild(c),s.observe(c),()=>{s.disconnect(),c.parentNode&&c.parentNode.removeChild(c)}},[b,X]),r.useEffect(()=>{if(!C||n!==o.OFFICIAL)return;const e=B.current;if(!e)return;const a=e.parentElement;if(!a)return;const s=new IntersectionObserver(f=>{f.some(l=>l.isIntersecting)&&$()},{root:a,rootMargin:"240px 0px",threshold:0}),c=document.createElement("div");return c.style.height="1px",e.appendChild(c),s.observe(c),()=>{s.disconnect(),c.parentNode&&c.parentNode.removeChild(c)}},[C,n,$]),r.useEffect(()=>{if(n!==o.COMMUNITY)return;const e={};u&&(e.keyword=u);let a=!1;return fe(e).then(s=>{a||K(F(s))}).catch(()=>{a||K([])}),()=>{a=!0}},[n,u]);const ne=r.useMemo(()=>d==null?i("pages.characters.category_label"):w.find(a=>a.id===d)?.name??i("pages.characters.category_label"),[w,d,i]),oe=n===o.OFFICIAL?se:ie,ee=e=>{m?.(e),y?.()};return t.jsxs("div",{className:"characterPicker",children:[t.jsx("button",{type:"button",className:"characterPicker__close",onClick:()=>y?.(),"aria-label":i("dialog.common.closeAria"),children:t.jsx("img",{src:new URL("/assets/ic_close-C0Ltcj9g.png",import.meta.url).href,alt:""})}),t.jsxs("div",{className:"characterPicker__surface",children:[t.jsxs("div",{className:"characterPicker__topBar",children:[t.jsx("h3",{className:"characterPicker__title",children:i("pages.characters.my_section")}),t.jsxs("label",{className:"characterPicker__search",children:[t.jsx("img",{className:"characterPicker__searchIcon",src:new URL("/assets/ic_search-DREI2NzL.png",import.meta.url).href,alt:""}),t.jsx("input",{className:"characterPicker__searchInput",type:"search",value:P,onChange:e=>{te(e.target.value)},placeholder:i("pages.characters.search_placeholder")})]})]}),t.jsxs("div",{className:"characterPicker__grid",ref:T,children:[ce.map((e,a)=>t.jsxs("button",{type:"button",className:"characterPicker__card",onClick:()=>{ee(e)},children:[t.jsx("img",{className:"characterPicker__cardImage",src:e.avatar,alt:""}),t.jsx("span",{className:"characterPicker__cardTag",children:e.title})]},String(e.id??a))),N?t.jsx("p",{className:"characterPicker__loadingMore",children:i("pages.explore.feed.loadingMore")}):null]}),t.jsxs("div",{className:"characterPicker__sectionHeader",children:[t.jsxs("div",{className:"characterPicker__tabs",role:"tablist","aria-label":i("pages.characters.category_aria"),children:[t.jsx("button",{type:"button",role:"tab","aria-selected":n===o.OFFICIAL,className:["characterPicker__tab",n===o.OFFICIAL?"characterPicker__tab--active":""].filter(Boolean).join(" "),onClick:()=>{Z(o.OFFICIAL),p(!1)},children:i("pages.characters.official_section")}),t.jsx("button",{type:"button",role:"tab","aria-selected":n===o.COMMUNITY,className:["characterPicker__tab",n===o.COMMUNITY?"characterPicker__tab--active":""].filter(Boolean).join(" "),onClick:()=>{Z(o.COMMUNITY),p(!1)},children:i("pages.characters.community_section")})]}),n===o.OFFICIAL?t.jsx("div",{ref:E,children:t.jsx(de,{trigger:"click",position:"br",popupVisible:W,onVisibleChange:p,triggerProps:{style:{zIndex:3e3}},getPopupContainer:()=>E.current??document.body,droplist:t.jsxs("div",{className:"characterPicker__categoryDropdown",role:"menu","aria-label":i("pages.characters.category_label"),children:[t.jsx("button",{type:"button",className:["characterPicker__categoryItem",d===null?"characterPicker__categoryItem--active":""].filter(Boolean).join(" "),onClick:()=>{Q(null),p(!1)},children:i("pages.characters.category_label")}),w.map(e=>t.jsx("button",{type:"button",className:["characterPicker__categoryItem",d===e.id?"characterPicker__categoryItem--active":""].filter(Boolean).join(" "),onClick:()=>{Q(e.id),p(!1)},children:e.name},e.id))]}),children:t.jsxs("button",{type:"button",className:"characterPicker__categoryButton","aria-expanded":W,"aria-haspopup":"menu",children:[t.jsx("span",{children:ne}),t.jsx("img",{src:new URL("/assets/ic_arrow_right_gray-DM6GPP4g.png",import.meta.url).href,alt:""})]})})}):null]}),t.jsxs("div",{className:"characterPicker__grid",ref:B,children:[oe.map((e,a)=>t.jsxs("button",{type:"button",className:"characterPicker__card",onClick:()=>{ee(e)},children:[t.jsx("img",{className:"characterPicker__cardImage",src:e.avatar,alt:""}),t.jsx("span",{className:"characterPicker__cardTag",children:e.title})]},String(e.id??a))),n===o.OFFICIAL&&v?t.jsx("p",{className:"characterPicker__loadingMore",children:i("pages.explore.feed.loadingMore")}):null]})]})]})}export{ye as default};
|
|
//# sourceMappingURL=index-B02RCqdn.js.map
|
|
|