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.
 
 
 

1 lines
11 KiB

var G=Object.defineProperty;var L=(e,t,s)=>t in e?G(e,t,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[t]=s;var c=(e,t,s)=>L(e,typeof t!="symbol"?t+"":t,s);import{V as T,f as M,e as F,C as H,_ as B,g as y,h as l,i as d,j as n,q as _,l as g,p as P,w as I,F as C,x as r,k as m,z as N,t as p}from"./index-BLqts8WY.js";import{E as R}from"./EntityIcon-CF1RwQI5.js";import{I as U}from"./InfiniteScroll-B5tl9k_n.js";import{Q as A}from"./QuickNav-DgCyvgDx.js";import{O as V}from"./OnboardingDialog-CiAZLb6o.js";import{P as E}from"./ProjectIcon-BlrP4rvy.js";import{T as z}from"./TopMessage-BE0GBIgW.js";import{U as Y}from"./UserNameDialog-B8a82q1n.js";import{l as Q,h as q,e as J,ao as K,g as O,ap as W}from"./index-MyY_xqVN.js";import"./index-CsfPLOYu.js";var X=Object.defineProperty,Z=Object.getOwnPropertyDescriptor,ee=(e,t,s,a)=>{for(var i=a>1?void 0:a?Z(t,s):t,u=e.length-1,f;u>=0;u--)(f=e[u])&&(i=(a?f(t,s,i):f(i))||i);return a&&i&&X(t,s,i),i};let D=class extends T{constructor(){super(...arguments);c(this,"$notify");c(this,"activeDid","");c(this,"allContacts",[]);c(this,"allMyDids",[]);c(this,"apiServer","");c(this,"givenName","");c(this,"isLoading",!1);c(this,"isRegistered",!1);c(this,"offers",[]);c(this,"projectNameFromHandleId",{});c(this,"projects",[]);c(this,"showOffers",!1);c(this,"showProjects",!0);c(this,"libsUtil",Q);c(this,"didInfo",q)}errNote(s){this.$notify({group:"alert",type:"danger",title:"Error",text:s},5e3)}async mounted(){try{const s=await M();this.activeDid=s.activeDid||"",this.apiServer=s.apiServer||"",this.isRegistered=!!s.isRegistered,this.givenName=s.firstName||"",this.allContacts=await F.contacts.toArray(),this.allMyDids=await J(),s.finishedOnboarding||this.$refs.onboardingDialog.open(K.Create),this.allMyDids.length===0?(console.error("No accounts found."),this.errNote("You need an identifier to load your projects.")):await this.loadProjects()}catch(s){console.error("Error initializing:",s),this.errNote("Something went wrong loading your projects.")}}async projectDataLoader(s){try{const a=await O(this.activeDid,this.$notify);this.isLoading=!0;const i=await this.axios.get(s,{headers:a});if(i.status===200&&i.data.data){const u=i.data.data;for(const f of u){const{name:b,description:v,handleId:h,image:j,issuerDid:w,rowid:k}=f;this.projects.push({name:b,description:v,image:j,handleId:h,issuerDid:w,rowid:k})}}else console.error("Bad server response & data for plans:",i.status,i.data),this.errNote("Failed to get projects from the server.")}catch(a){console.error("Got error loading plans:",a.message||a),this.errNote("Got an error loading projects.")}finally{this.isLoading=!1}}async loadMoreProjectData(s){if(this.projects.length>0&&s){const a=this.projects[this.projects.length-1];await this.loadProjects(`beforeId=${a.rowid}`)}}async loadProjects(s=""){const a=`${this.apiServer}/api/v2/report/plansByIssuer?${s}`;await this.projectDataLoader(a)}onClickLoadProject(s){const a={path:"/project/"+encodeURIComponent(s)};this.$router.push(a)}onClickNewProject(){const s={name:"new-edit-project"};this.$router.push(s)}onClickLoadClaim(s){const a={path:"/claim/"+encodeURIComponent(s)};this.$router.push(a)}async offerDataLoader(s){const a=await O(this.activeDid);try{this.isLoading=!0;const i=await this.axios.get(s,{headers:a});if(i.status===200&&i.data.data)for(const u of i.data.data){if(u.fulfillsPlanHandleId){const f=await W(u.fulfillsPlanHandleId,this.axios,this.apiServer,this.activeDid),b=f==null?void 0:f.name;this.projectNameFromHandleId[u.fulfillsPlanHandleId]=b}this.offers=this.offers.concat([u])}else console.error("Bad server response & data for offers:",i.status,i.data),this.$notify({group:"alert",type:"danger",title:"Error",text:"Failed to get offers from the server. Try again later."},-1)}catch(i){console.error("Got error loading offers:",i.message||i),this.$notify({group:"alert",type:"danger",title:"Error",text:"Got an error loading offers."},-1)}finally{this.isLoading=!1}}async loadMoreOfferData(s){if(this.offers.length>0&&s){const a=this.offers[this.offers.length-1];await this.loadOffers(`&beforeId=${a.jwtId}`)}}async loadOffers(s=""){const a=`${this.apiServer}/api/v2/report/offers?offeredByDid=${this.activeDid}${s}`;await this.offerDataLoader(a)}showNameThenIdDialog(){this.givenName?this.promptForShareMethod():this.$refs.userNameDialog.open(()=>{this.promptForShareMethod()})}promptForShareMethod(){this.$notify({group:"modal",type:"confirm",title:"Are you nearby with cameras?",text:"If so, we'll use those with QR codes to share.",onCancel:async()=>{},onNo:async()=>{this.$router.push({name:"share-my-contact-info"})},onYes:async()=>{this.$router.push({name:"contact-qr"})},noText:"we will share another way",yesText:"we are nearby with cameras"},-1)}computedOfferTabClassNames(){return{"inline-block":!0,"py-3":!0,"rounded-t-lg":!0,"border-b-2":!0,active:this.showOffers,"text-black":this.showOffers,"border-black":this.showOffers,"font-semibold":this.showOffers,"text-blue-600":!this.showOffers,"border-transparent":!this.showOffers,"hover:border-slate-400":!this.showOffers}}computedProjectTabClassNames(){return{"inline-block":!0,"py-3":!0,"rounded-t-lg":!0,"border-b-2":!0,active:this.showProjects,"text-black":this.showProjects,"border-black":this.showProjects,"font-semibold":this.showProjects,"text-blue-600":!this.showProjects,"border-transparent":!this.showProjects,"hover:border-slate-400":!this.showProjects}}};D=ee([H({components:{EntityIcon:R,InfiniteScroll:U,QuickNav:A,OnboardingDialog:V,ProjectIcon:E,TopMessage:z,UserNameDialog:Y}})],D);const te={id:"Content",class:"p-6 pb-24 max-w-3xl mx-auto"},oe={class:"text-center text-slate-500 border-b border-slate-300 mt-8"},se={class:"flex flex-wrap justify-center gap-4 -mb-px"},ne={key:1,class:"fixed left-6 bottom-24 text-center text-4xl leading-none bg-slate-400 text-white w-14 py-2.5 rounded-full"},re={key:0,class:"text-center py-4"},ae={id:"listOffers",class:"border-t border-slate-300"},ie={class:"block py-4 flex gap-4"},le={key:0,class:"flex-none"},de={key:1,class:"flex-none w-12"},ce={class:"text-sm"},he={key:0},ue={key:0},fe={key:1},me={key:2},pe={class:"text-sm text-slate-400"},ge={key:0},ye={key:1},be={key:1},we={key:0},ve={key:1},je=["onClick"],ke={key:0,class:"text-center py-4"},Pe={key:0},Ie={key:1},Ce={id:"listProjects",class:"border-t border-slate-300"},De=["onClick"],xe={class:"flex-none"},_e={class:"grow overflow-hidden"},Ne={class:"text-base font-semibold"},Oe={class:"text-sm truncate"};function $e(e,t,s,a,i,u){const f=y("QuickNav"),b=y("TopMessage"),v=y("OnboardingDialog"),h=y("fa"),j=y("router-link"),w=y("ProjectIcon"),k=y("EntityIcon"),x=y("InfiniteScroll"),$=y("UserNameDialog");return r(),l(C,null,[d(f,{selected:"Projects"}),d(b),n("section",te,[t[12]||(t[12]=n("h1",{id:"ViewHeading",class:"text-4xl text-center font-light"}," Your Project Ideas ",-1)),d(v,{ref:"onboardingDialog"},null,512),n("div",oe,[n("ul",se,[n("li",null,[n("a",{href:"#",onClick:t[0]||(t[0]=o=>{e.offers=[],e.projects=[],e.showOffers=!0,e.showProjects=!1,e.loadOffers()}),class:_(e.computedOfferTabClassNames())}," Offers ",2)]),n("li",null,[n("a",{href:"#",onClick:t[1]||(t[1]=o=>{e.offers=[],e.projects=[],e.showOffers=!1,e.showProjects=!0,e.loadProjects()}),class:_(e.computedProjectTabClassNames())}," Projects ",2)])])]),e.isRegistered&&e.showProjects?(r(),l("button",{key:0,class:"fixed right-6 top-24 text-center text-4xl leading-none bg-green-600 text-white w-14 py-2.5 rounded-full",onClick:t[2]||(t[2]=o=>e.onClickNewProject())},[d(h,{icon:"plus",class:"fa-fw"})])):g("",!0),e.isLoading?(r(),l("div",ne,[d(h,{icon:"spinner",class:"fa-spin-pulse"})])):g("",!0),e.showOffers?(r(),P(x,{key:2,onReachedBottom:e.loadMoreOfferData},{default:I(()=>[e.offers.length===0?(r(),l("div",re,[t[5]||(t[5]=m(" You have not offered anything. ")),t[6]||(t[6]=n("br",null,null,-1)),d(j,{to:"/discover",class:"text-blue-600"},{default:I(()=>t[4]||(t[4]=[m(" Look for projects worth some of your time. ")])),_:1})])):g("",!0),n("ul",ae,[(r(!0),l(C,null,N(e.offers,o=>(r(),l("li",{class:"border-b border-slate-300",key:o.handleId},[n("div",ie,[o.fulfillsPlanHandleId?(r(),l("div",le,[d(w,{entityId:o.fulfillsPlanHandleId,iconSize:48,class:"inline-block align-middle border border-slate-300 rounded-md max-h-12 max-w-12"},null,8,["entityId"])])):g("",!0),o.recipientDid?(r(),l("div",de,[d(k,{entityId:o.recipientDid,iconSize:48,class:"inline-block align-middle border border-slate-300 rounded-md"},null,8,["entityId"])])):g("",!0),n("div",null,[n("div",null," To "+p(o.fulfillsPlanHandleId?e.projectNameFromHandleId[o.fulfillsPlanHandleId]:e.didInfo(o.recipientDid,e.activeDid,e.allMyDids,e.allContacts)),1),n("div",null,p(o.objectDescription),1),n("span",ce,[o.amount?(r(),l("span",he,[d(h,{icon:e.libsUtil.iconForUnitCode(o.unit),class:"fa-fw text-slate-400"},null,8,["icon"]),o.amountGiven>=o.amount?(r(),l("span",ue,[d(h,{icon:"check-circle",class:"fa-fw text-green-500"}),m(" All "+p(o.amount)+" given ",1)])):(r(),l("span",fe,[d(h,{icon:"triangle-exclamation",class:"fa-fw text-yellow-500"}),m(" "+p(o.amountGiven?"":"All")+" "+p(o.amount-(o.amountGiven||0))+" remaining ",1)])),o.amountGiven>0?(r(),l("span",me,[n("span",pe,[m(" ("+p(o.amountGiven)+" given, ",1),o.amountGivenConfirmed>=o.amountGiven?(r(),l("span",ge," all ")):(r(),l("span",ye,[o.amountGiven>=o.amount?(r(),P(h,{key:0,icon:"triangle-exclamation",class:"fa-fw text-yellow-300"})):g("",!0),m(" "+p(o.amountGivenConfirmed||0),1)])),t[7]||(t[7]=m(" of that is confirmed) "))])])):g("",!0)])):(r(),l("span",be,[o.nonAmountGivenConfirmed?(r(),l("span",we,[d(h,{icon:"check-circle",class:"fa-fw text-green-500"}),m(" "+p(o.nonAmountGivenConfirmed)+" "+p(o.nonAmountGivenConfirmed==1?"give":"gives")+" are confirmed. ",1)])):(r(),l("span",ve,[d(h,{icon:"triangle-exclamation",class:"fa-fw text-yellow-500"}),t[8]||(t[8]=n("span",{class:"text-sm"},"Not confirmed by anyone",-1))]))])),n("a",{onClick:S=>e.onClickLoadClaim(o.jwtId)},[d(h,{icon:"file-lines",class:"pl-2 text-blue-500 cursor-pointer"})],8,je)])])])]))),128))])]),_:1},8,["onReachedBottom"])):g("",!0),e.showProjects?(r(),P(x,{key:3,onReachedBottom:e.loadMoreProjectData},{default:I(()=>[e.projects.length===0?(r(),l("div",ke,[t[11]||(t[11]=m(" You have not announced any projects. ")),e.isRegistered?(r(),l("div",Pe,[t[9]||(t[9]=m(" Hit the big ")),d(h,{icon:"plus",class:"bg-green-600 text-white px-1.5 py-1 rounded-full"}),t[10]||(t[10]=m(" button. You'll never know until you try. "))])):(r(),l("div",Ie,[n("button",{onClick:t[3]||(t[3]=o=>e.showNameThenIdDialog()),class:"text-md font-bold bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white mt-2 px-2 py-3 rounded-md"}," Get someone to onboard you. "),d($,{ref:"userNameDialog"},null,512)]))])):g("",!0),n("ul",Ce,[(r(!0),l(C,null,N(e.projects,o=>(r(),l("li",{class:"border-b border-slate-300",key:o.handleId},[n("a",{onClick:S=>e.onClickLoadProject(o.handleId),class:"block py-4 flex gap-4"},[n("div",xe,[d(w,{entityId:o.handleId,iconSize:48,imageUrl:o.image,class:"inline-block align-middle border border-slate-300 rounded-md max-h-12 max-w-12"},null,8,["entityId","imageUrl"])]),n("div",_e,[n("h2",Ne,p(o.name),1),n("div",Oe,p(o.description),1)])],8,De)]))),128))])]),_:1},8,["onReachedBottom"])):g("",!0)])],64)}const Ee=B(D,[["render",$e]]);export{Ee as default};