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