2 lines
5.8 KiB
JavaScript
2 lines
5.8 KiB
JavaScript
import{d as se,r,G as re,H as oe,d0 as ie,bb as ne,k as T,$ as ue,ae as ce,o as de,ai as ve,y as m,z as p,C as x,D as fe,A as a,a5 as y,R as D,J as o,B as S,a2 as j,a0 as U,a1 as N,F as O,a6 as H,d_ as pe,dg as V,O as he}from"./Cbt2tPBc.js";import{f as ge,h as me,j as _e}from"./SolGyfyY.js";import{u as z}from"./CfQT9Pjy.js";import{B as G}from"./_OSaw0MT.js";import{e as C}from"./DGFRw2HL.js";import{S as ye,P as we}from"./BN8guUTz.js";import{B as xe}from"./DVxbPVlR.js";import{S as Se}from"./C9QN_Mfk.js";import"./DlAUqK2U.js";import"./Dn4CZ-Yo.js";import"./Bbd_Ti14.js";import"./5ZDQaK5A.js";import"./lDFIwPIu.js";import"./BxF7pQIy.js";import"./CscEAC8U.js";import"./BiDL-COj.js";import"./sFfhux-l.js";/* empty css */const Ce={class:"w-full h-screen overflow-y-auto"},be={class:"flex w-full p-4 gap-8 justify-between items-center"},ke={class:"flex gap-4 items-center"},Re={class:"font-semibold text-lg"},De=["disabled"],Ue={class:"w-full grid grid-cols-3 mt-2 gap-2px pb-5vh"},Ie={key:0,class:"h-80vh flex items-center justify-center"},Be={class:"h-50vh flex flex-col justify-center items-center gap-4"},Pe={class:"circle_highlight"},Fe=["alt"],Ae=["placeholder"],Ee={key:1,class:"flex items-center h-90vh relative"},Le={class:"w-full"},Te={class:"flex justify-center absolute bottom-20 w-inherit w-full overflow-x-auto"},je=["onClick","alt"],lt=se({__name:"index",setup(Ne){const I=r(!1),B=r(null),i=re(),P=r(),{user:F}=oe(),$=ie(),_=r(!1),b=r(!0),v=r([]),c=r([]),A=r(!1),l=r(1),E=r(),M=r(),w=r(null),f=r(),h=r(),k=r(!0);ne(()=>{c.value.length>0?k.value||(f.value=v.value.find(e=>e.id===c.value[0])?.media_url,h.value=f.value,k.value=!0):k.value=!1});const q=T(()=>i.useString(l.value===1?"newHighLight":l.value===2?"title":"editCover")),R=T(()=>{switch(l.value){case 1:return c.value.length===0;case 2:return!w.value;case 3:return!1}});function J(e){M.value=e}function W(e){h.value=e}function K(){B.value?.click()}function Q(e){const t=e.target.files?.[0];if(t){const u=new FileReader;u.onload=d=>{f.value=d.target?.result},u.readAsDataURL(t),b.value=!1}}function X(e){f.value=v.value?.find(t=>t.id===c.value[e])?.media_url,b.value=!0}const Y=()=>{c.value&&l.value++},Z=()=>{l.value--},ee=async()=>{try{_.value=!0;const e=await ge(F?.user_id);v.value=e?.flatMap(t=>t?.mediaitems)}catch{V.error("error in fetching stories")}finally{_.value=!1}};async function te(e){const u=await(await fetch(e)).blob();return new Promise((d,n)=>{const s=new FileReader;s.onloadend=()=>d(s.result),s.onerror=n,s.readAsDataURL(u)})}async function ae(){try{if(h.value?.startsWith("data:image")){const e=L(h.value,"cover.jpg");return(await z(e,{endpoint:i.STORAGE_UPLOAD}))?.data?.fullPath}else{const e=await te(i.useDataStorage(h.value)),t=L(e,"cover.jpg"),{data:u,error:d}=await z(t,{endpoint:i.STORAGE_UPLOAD});if(d)throw d;return u?.fullPath}}catch(e){console.error("Error in uploadCoverIfNeeded:",e)}}function L(e,t){const u=e.split(","),d=u[0].match(/:(.*?);/)[1],n=atob(u[1]);let s=n.length;const g=new Uint8Array(s);for(;s--;)g[s]=n.charCodeAt(s);return new File([g],t,{type:d})}const le=async()=>{if(!R.value){if(l.value===1)Y();else if(l.value===3)P.value.crop(),l.value--,A.value=!0;else if(l.value===2)try{_.value=!0;const e=await ae(),{data:t,status:u}=await me(w.value,F?.user_id,e);u===201&&t?.length&&await _e(c.value,t[0]?.id)}catch{V.error("error in creating highlight")}finally{he(),_.value=!1}}};return ue(()=>l.value,e=>{e===2&&ce(()=>{E.value?.focus()})},{immediate:!0}),de(async()=>{await ee()}),(e,t)=>{const u=Se,d=ve("lazy");return p(),m(U,null,[x(u,{spinning:_.value},{default:fe(()=>[a("div",Ce,[a("div",be,[a("div",ke,[x(G,{icon:o(i).isRTL?"vuesax-linear:arrow-right":"vuesax-linear:arrow-left",onClick:t[0]||(t[0]=n=>l.value===1?o($).back():Z())},null,8,["icon"]),a("div",Re,S(q.value),1)]),a("div",{class:j(["text-primary text-sm fw-bold",{"cursor-not-allowed !text-gray":R.value}]),disabled:R.value,onClick:le},S(o(i).useString(l.value===1?"next":"done")),11,De)]),y(a("div",Ue,[(p(!0),m(U,null,N(v.value,n=>(p(),O(ye,{key:n.id,story:n,selectedStory:c.value,"onUpdate:selectedStory":t[1]||(t[1]=s=>c.value=s)},null,8,["story","selectedStory"]))),128))],512),[[H,l.value===1&&v.value&&v.value.length!==0]]),l.value===1&&(!v.value||v.value.length===0)?(p(),m("div",Ie,[a("div",null,S(o(i).useString("noItems")),1)])):D("",!0),y(a("div",Be,[a("div",Pe,[y(a("img",{class:"",alt:o(i).appName.en},null,8,Fe),[[d,{src:A.value?h.value:o(i).useDataStorage(h.value),loading:o(C),error:o(C)}]]),t[5]||(t[5]=a("svg",{viewBox:"0 0 100 100"},[a("circle",{cx:"50",cy:"50",r:"45"})],-1))]),a("div",{class:"text-primary text-xs",onClick:t[2]||(t[2]=n=>l.value=3)},S(o(i).useString("editCover")),1),y(a("input",{ref_key:"highlightInputRef",ref:E,"onUpdate:modelValue":t[3]||(t[3]=n=>w.value=n),type:"text",placeholder:o(i).useString("highlights"),class:"highlight-input"},null,8,Ae),[[pe,w.value]])],512),[[H,l.value===2]]),l.value===3?(p(),m("div",Ee,[a("div",Le,[f.value?(p(),O(we,{key:0,ref_key:"cropper",ref:P,class:"h-90vh absolute top-0 w-inherit highlightCover",onOnCropped:W,src:b.value?o(i).useDataStorage(f.value):f.value},null,8,["src"])):D("",!0),a("div",Te,[(p(!0),m(U,null,N(c.value,(n,s)=>y((p(),m("img",{class:j(["w-2.5rem h-2.5rem",f.value===v.value.find(g=>g.id===c.value[s])?.media_url?"border-1.5px border-solid border-gray-8 p2px":""]),onClick:g=>X(s),alt:o(i).appName.en},null,10,je)),[[d,{src:o(i).useDataStorage(v.value?.find(g=>g.id===c.value[s])?.media_url),loading:o(C),error:o(C)}]])),256)),a("div",{class:"flex items-center justify-center w-2.7rem h-2.5rem",onClick:K},[x(G,{icon:"vuesax-linear:gallery"}),a("input",{type:"file",accept:"image/*",ref_key:"fileInputRef",ref:B,class:"hidden h-full w-full",onChange:Q},null,544)])])])])):D("",!0)])]),_:1},8,["spinning"]),x(xe,{open:I.value,"onUpdate:open":t[4]||(t[4]=n=>I.value=n),onSuccess:J},null,8,["open"])],64)}}});export{lt as default};
|