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
8.6 KiB
2 lines
8.6 KiB
import{j as u}from"./markdown-vendor-BZI_VWzW.js";import{u as de,r as c}from"./data-vendor-BOGugMqL.js";import{g as fe}from"./react-vendor-wlKWdfEb.js";import{bb as J,bc as X,bd as me,o as ee,be as ge,j as pe}from"./index-D2jM1hO2.js";import{M as ye}from"./arco-vendor-CAnKnMnO.js";const E=50,_e=3e3,he=120,te="myCreations:taskCreated",Se=new URL("/assets/pending-iKg2Z6_3.png",import.meta.url).href,re=[{title:"image",type:1},{title:"video",type:2},{title:"template",type:4}];function U(e){if(e==null||e==="")return null;if(typeof e=="number")return e<1e11?e*1e3:e;const r=Date.parse(String(e));return Number.isNaN(r)?null:r}function N(e){const r=e?.id??e?.taskId;return r==null||r===""?null:String(r)}function ne(e){return e?.status==0||e?.status==1}function Pe(e){return e==-1||e==-2}function Te(e,r){const s=e?.userErrorTipMsg;return typeof s=="string"&&s.trim()?s.trim():s!=null&&s!==""?String(s):r}function be(e){const r=new Set;for(const s of e){const f=N(s);f&&ne(s)&&r.add(f)}return[...r].sort().join(",")}function se(e,r){const s=e?.type??e?.taskType;return s==null||s===""?!0:Number(s)===r}function R(e){return e?.data?.list??[]}function k(e,r){const s={...e};return Number(r)===1?s.subType="102,103":delete s.subType,Number(r)===4?(delete s.type,ge({...s,idList:e.idList})):pe({...s,ids:e.idList})}function Ne(e,r,s){const f=new Map;for(const d of r){const i=N(d);i&&se(d,s)&&f.set(i,d)}return f.size===0?e:e.map(d=>{const i=N(d);return i&&f.has(i)?f.get(i):d})}function Ce(e,r,s,f){for(const d of e){if(!Pe(d?.status)||!se(d,r))continue;const i=N(d);!i||s.has(i)||(s.add(i),ye.error(Te(d,f)))}}function ae(e){const r=Math.max(0,Math.floor(e||0));return Array.from({length:r},(s,f)=>f)}function Le(e,r){return ne(e)?ae(e?.batchSize).length>0:e?.status!=2||!Array.isArray(e?.resultList)||e.resultList.length===0?!1:r===1||r===4?e.resultList.some(s=>!!s?.images?.[0]):r===2?e.resultList.some(s=>!!s?.video):!1}function Ie(e,r){if(!r)return e;let s=!1;const f=[];for(const d of e){if(d?.status!=2||!Array.isArray(d?.resultList)){f.push(d);continue}const i=d.resultList.filter(C=>{const _=C?.id??C?.assetId;return String(_??"")!==r});i.length!==d.resultList.length&&(s=!0),i.length>0?f.push({...d,resultList:i}):s=!0}return s?f:e}function ke({tabIdPrefix:e}){const{t:r}=de(),[s,f]=fe(),d=s.get(J),[i,C]=c.useState(1),[_,h]=c.useState([]),[z,j]=c.useState(1),[L,S]=c.useState(!0),[P,w]=c.useState(!1),[A,q]=c.useState(!1),[D,F]=c.useState(null),B=c.useRef(null),Y=c.useRef(!1),g=c.useRef(0),I=c.useRef(0),G=c.useRef(new Set),H=c.useRef(r);H.current=r;const V=c.useRef(async()=>{}),K=X(Date.now(),"YYYY-MM-DD"),O=c.useMemo(()=>{const t=[..._].sort((a,l)=>(U(l?.createTime)??0)-(U(a?.createTime)??0)).filter(a=>Le(a,i)),n=new Map;for(const a of t){const l=U(a?.createTime),o=l!=null?X(l,"YYYY-MM-DD"):"unknown";n.has(o)||n.set(o,[]),n.get(o).push(a)}return[...n.entries()].map(([a,l])=>({dateKey:a,taskList:l}))},[_,i]),T=c.useCallback(t=>({type:i,page:t,pageSize:E,status_min:0}),[i]),M=c.useMemo(()=>be(_),[_]),Z=c.useRef(M);Z.current=M;const $=c.useRef(i);$.current=i,c.useEffect(()=>{const t=n=>{const a=n.detail,l=Number(a?.type);if(!Number.isFinite(l)||l!==$.current)return;const o=g.current;k(T(1),l).then(y=>{if(g.current!==o)return;const p=R(y);h(p),j(1),S(p.length>=E),F(null)}).catch(()=>{})};return window.addEventListener(te,t),()=>{window.removeEventListener(te,t)}},[T]),c.useEffect(()=>{const t=s.get("type");if(t==null)return;const n=Number(t);Number.isFinite(n)&&re.some(a=>a.type===n)&&C(n)},[s]),c.useEffect(()=>{let t=!1;g.current+=1,G.current.clear();const n=g.current;j(1),S(!0),h([]),w(!0),F(null);const l=d!=null&&d!==""?he:0;let o=!1;const y=()=>{t||g.current!==n||(o=!0,k(T(1),i).then(m=>{if(t||g.current!==n)return;const v=R(m);h(v),S(v.length>=E)}).catch(m=>{t||g.current!==n||(F(m instanceof Error?m:new Error(String(m))),h([]),S(!1))}).finally(()=>{!t&&g.current===n&&w(!1)}))};let p;return l===0?y():p=window.setTimeout(y,l),()=>{t=!0,p!==void 0&&window.clearTimeout(p),o||w(!1)}},[i,T,d]),c.useEffect(()=>{if(!M)return;const t=g.current;let n=!0;const a=++I.current;async function l(){if(!n||I.current!==a||g.current!==t)return;const p=Z.current.split(",").filter(Boolean);if(p.length===0)return;const m=$.current;try{const v=await k({idList:p.join(","),type:m},m);if(!n||I.current!==a||g.current!==t)return;const x=R(v);if(x.length===0)return;console.log("[MyCreationsPanel] poll updates",x.map(b=>({id:N(b),status:b?.status,type:b?.type,taskType:b?.taskType})));const ue=H.current("pages.create.panels.myCreations.taskFailedFallback");Ce(x,m,G.current,ue),h(b=>Ne(b,x,m))}catch{}}l();const o=window.setInterval(()=>void l(),_e);return()=>{n=!1,I.current+=1,window.clearInterval(o)}},[M,i]);const ie=c.useCallback(async()=>{if(!L||Y.current||P||A)return;Y.current=!0,q(!0);const t=g.current,n=z+1;try{const a=await k(T(n),i);if(g.current!==t)return;const l=R(a);l.length===0?S(!1):(h(o=>[...o,...l]),j(n),S(l.length>=E))}catch{g.current===t&&S(!1)}finally{Y.current=!1,q(!1)}},[L,P,A,T,z]);V.current=ie,c.useEffect(()=>{const t=B.current;if(!t||!L||P)return;const n=new IntersectionObserver(a=>{a[0]?.isIntersecting&&V.current()},{root:null,rootMargin:"160px",threshold:0});return n.observe(t),()=>n.disconnect()},[L,P,_.length]);const oe=c.useCallback(t=>{C(t),f(n=>{const a=new URLSearchParams(n);return a.set("type",String(t)),a.delete(J),a},{replace:!0})},[f]),Q=c.useCallback(t=>t==="unknown"?r("pages.create.panels.myCreations.dateUnknown"):t===K?r("pages.create.panels.myCreations.dateToday"):t.replace(/-/g,"/"),[r,K]),W=c.useCallback(async t=>{const n=String(t?.id??t?.assetId??""),a=l=>{const o=String(l||n);o&&h(y=>Ie(y,o))};if(i==4){const o=(await me(t.id))?.data?.id;if(o==null||o==="")return;ee({assetId:o,onDeleted:a});return}ee({assetId:t.id,onDeleted:a})},[i]),ce=c.useCallback(t=>{t.currentTarget.querySelector("video")?.play()},[]),le=c.useCallback(t=>{t.currentTarget.querySelector("video")?.pause()},[]);return u.jsxs("div",{className:"createPage__myCreationsWrap",children:[u.jsx("div",{className:"createPage__subRow",children:u.jsx("div",{className:"createPage__filters",role:"group","aria-label":r("pages.create.filtersAria"),"data-active-tab":i,children:re.map(({title:t,type:n})=>u.jsx("button",{type:"button","data-type":n,"data-selected":i===n,"aria-pressed":i===n,className:classNames("createPage__filterPill",i===n&&"createPage__filterPill_active"),onClick:()=>oe(n),children:r(`pages.create.filters.${t}`)},n))})}),u.jsxs("section",{className:"createPage__panel createPage__panel_below_filters",id:`${e}-panel-myCreations`,role:"tabpanel","aria-labelledby":`${e}-tab-myCreations`,children:[P&&_.length===0?u.jsx("p",{className:"createPage__panelStatus",children:r("common.loading")}):null,D?u.jsx("p",{className:"createPage__panelStatus createPage__panelStatus_error",children:D.message}):null,!P&&!D&&O.length===0?u.jsx("p",{className:"createPage__panelPlaceholder",children:r("pages.create.panels.myCreations.placeholder")}):null,O.length>0?u.jsxs(u.Fragment,{children:[u.jsx("div",{className:"createPage__myCreationsGrouped",children:O.map(({dateKey:t,taskList:n})=>u.jsxs("section",{className:"createPage__myCreationsDaySection","aria-label":Q(t),children:[u.jsx("h3",{className:"createPage__myCreationsDayTitle",children:Q(t)}),u.jsx("ul",{className:"createPage__myCreationsList",role:"list",children:n.flatMap((a,l)=>{if(a.status==2&&a.resultList)return a.resultList.map((o,y)=>{const p=String(o.id??o.assetId??`${t}-${a?.id??"task"}-${y}`);if(i===1||i===4){const m=o?.images?.[0];return m?u.jsx("li",{className:"createPage__myCreationsListItem",onClick:()=>W(o),children:u.jsx("img",{className:"createPage__myCreationsThumb",src:m,alt:"",loading:"lazy"})},p):null}if(i===2){const m=o?.video;return m?u.jsx("li",{className:"createPage__myCreationsListItem",onClick:()=>W(o),onMouseEnter:ce,onMouseLeave:le,children:u.jsx("video",{className:"createPage__myCreationsThumb",src:m,muted:!0,playsInline:!0,loop:!0,preload:"metadata",poster:typeof o.cover=="string"?o.cover:void 0,"aria-hidden":!0})},p):null}return null});if(a.status==0||a.status==1){const o=N(a)??`idx-${l}`;return ae(a.batchSize).map(y=>u.jsxs("li",{className:"createPage__myCreationsListItem createPage__myCreationsListItem_pending",children:[u.jsx("img",{className:"createPage__myCreationsPendingIcon",src:Se,alt:""}),u.jsx("span",{className:"createPage__myCreationsPendingLabel",children:r("pages.create.panels.myCreations.generating")})]},`pending-${o}-${y}`))}return null})})]},t))}),L?u.jsx("div",{ref:B,className:"createPage__myCreationsSentinel","aria-hidden":!0}):null,A?u.jsx("p",{className:"createPage__panelStatus createPage__myCreationsLoadMore",children:r("common.loading")}):null]}):null]})]})}export{ke as default};
|
|
//# sourceMappingURL=index-CmjUVPL-.js.map
|
|
|