Files
ambersplace.net/cohost-archive/static/client-preact-components-pages-follow-requests.02dfa60a396a0c092dac.js

2 lines
9.1 KiB
JavaScript

"use strict";(self.__LOADABLE_LOADED_CHUNKS__=self.__LOADABLE_LOADED_CHUNKS__||[]).push([[5790,9629],{2735:function(e,t,o){o.d(t,{Qj:function(){return E},zx:function(){return k}});var r=o(65443),l=o.n(r),n=o(94159),c=o(6285);function a(){return a=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&(e[r]=o[r])}return e},a.apply(this,arguments)}const s=c.z.enum(["pill","roundrect","authn"]),i=c.z.enum(["cherry","strawberry","mango","not-black","red","green","accent","secondary","authn-primary","authn-other"]),u=(c.z.object({buttonStyle:s,color:i,className:c.z.string().optional()}),l()("bg-notWhite","hover:text-notWhite")),d=l()("font-atkinson","font-bold","rounded-full","border-2"),g=l()("body-2","rounded-lg"),p=l()("flex","h-12","items-center","justify-center","rounded-lg","px-6","text-lg"),f=l()("border-cherry","hover:bg-cherry","text-cherry","active:bg-cherry-600","active:border-cherry-600","disabled:text-cherry-300","disabled:border-cherry-300","focus:outline-cherry","focus:ring-cherry",u),b=l()("border-strawberry","hover:bg-strawberry","text-strawberry","active:bg-strawberry-600","active:border-strawberry-600","disabled:text-strawberry-300","disabled:border-strawberry-300","focus:outline-strawberry","focus:ring-strawberry",u),w=l()("border-red","hover:bg-red","text-red","active:bg-red-600","active:border-red-600","disabled:text-red-300","disabled:border-red-300","focus:outline-red",u),m=l()("border-green","hover:bg-green","text-green","active:bg-green-600","active:border-green-600","disabled:text-green-300","disabled:border-green-300","focus:outline-green",u),h=l()("border-mango","hover:bg-mango","text-mango","bg-notBlack","hover:text-notBlack"),y=l()("border-notBlack","hover:bg-notBlack","text-notBlack","focus:outline-notBlack","focus:ring-notBlack",u),j=l()("border-accent","text-accent","bg-foreground","hover:bg-accent","hover:text-text"),x=l()("bg-secondary","text-notWhite","dark:text-notBlack","hover:bg-secondary-600"),v=l()("bg-foreground","text-text","hover:bg-foreground-600","active:bg-foreground-700","disabled:bg-foreground-200"),S=l()("border-2","border-foreground","text-foreground","hover:bg-longan-200"),I=e=>l()("leading-none","align-middle","py-2","px-4","no-select",e.className,{[d]:"pill"===e.buttonStyle,[g]:"roundrect"===e.buttonStyle,[p]:"authn"===e.buttonStyle,[f]:"cherry"===e.color,[b]:"strawberry"===e.color,[h]:"mango"===e.color,[y]:"not-black"===e.color,[w]:"red"===e.color,[j]:"accent"===e.color,[m]:"green"===e.color,[x]:"secondary"===e.color,[v]:"authn-primary"===e.color,[S]:"authn-other"===e.color}),k=n.forwardRef((({buttonStyle:e,color:t,className:o,...r},l)=>{const c=I({buttonStyle:e,color:t,className:o,...r});return n.createElement("button",a({},r,{className:c,ref:l}),r.children)}));k.displayName="Button";const E=n.forwardRef((({buttonStyle:e,color:t,...o},r)=>{const l=I({buttonStyle:e,color:t,...o});return n.createElement("a",a({},o,{className:l,ref:r}),o.children)}));E.displayName="LinkButton"},81511:function(e,t,o){o.r(t),o.d(t,{FollowRequestsContext:function(){return r}});const r=(0,o(94159).createContext)({onAction:()=>{}})},24863:function(e,t,o){o.r(t),o.d(t,{FollowRequests:function(){return i}});var r=o(94159),l=o(90275),n=o(80752),c=o(20616),a=o(81511);const s=(e,t)=>{switch(t.action){case"accept":return{...e,[t.projectId]:{...e[t.projectId],actionTaken:!0}};case"decline":{const{[t.projectId]:o,...r}=e;return r}}},i=({requesters:e})=>{const[t,o]=(0,r.useReducer)(s,(e=>e.reduce(((e,t)=>({...e,[t.projectId]:{project:t,actionTaken:!1}})),{}))(e)),i=(0,r.useCallback)(((e,t)=>{o({action:t,projectId:e})}),[]);return r.createElement(r.Fragment,null,r.createElement(l.ql,{title:"follow requests"}),r.createElement(a.FollowRequestsContext.Provider,{value:{onAction:i}},r.createElement("div",{className:"container mx-auto mt-16 grid w-full grid-cols-1 gap-16 lg:grid-cols-4"},r.createElement(c.w3,null),r.createElement("div",{"data-theme":"light",className:"co-themed-box cohost-shadow-light dark:cohost-shadow-dark col-span-2 mx-auto w-full max-w-prose rounded-lg bg-notWhite p-3 text-notBlack"},r.createElement("h1",{className:"text-2xl font-bold"},"Follow requests"),r.createElement("div",{className:"mt-6 flex flex-col gap-4"},Object.values(t).length?Object.values(t).map((e=>r.createElement(n.t,{key:e.project.projectId,project:e.project,isFollowRequest:!e.actionTaken}))):r.createElement("p",null,"You don't currently have any pending follow requests!"))))))};i.displayName="follow-requests",t.default=i},64499:function(e,t,o){o.d(t,{e:function(){return f}});var r=o(71860),l=o(70769),n=o(6285);let c=function(e){return e[e.NotFollowing=0]="NotFollowing",e[e.FollowRequested=1]="FollowRequested",e[e.Following=2]="Following",e}({});n.z.nativeEnum(c);var a=o(94159),s=o(51028),i=o(8227),u=o(2735),d=o(12093),g=o(21281),p=o(91045);const f=e=>a.createElement(a.Suspense,null,a.createElement(b,e)),b=({project:e,onFollow:t,color:o})=>{const n=(0,i.Pc)(),f=r.S.useContext(),b=r.S.projects.followingState.useQuery({projectHandle:e.handle},{suspense:!0}),w=(0,g.Z3)().get("ssrUrl"),m=(0,a.useCallback)((o=>({onMutate:async()=>{await f.projects.followingState.cancel({projectHandle:e.handle});const t=f.projects.followingState.getData({projectHandle:e.handle});return f.projects.followingState.setData({projectHandle:e.handle},{readerToProject:o}),{previousState:t}},onError:(t,o,r)=>{f.projects.followingState.setData({projectHandle:e.handle},r?.previousState)},onSettled:async()=>{await f.projects.followingState.invalidate({projectHandle:e.handle})},onSuccess:e=>{t&&t(e.followingState)}})),[t,e.handle,f.projects.followingState]),h=r.S.relationships.createFollowRequest.useMutation({...m(e.privacy===l.WL.Private?c.FollowRequested:c.Following)}),y=r.S.relationships.unfollow.useMutation({...m(c.NotFollowing)}),j=r.S.relationships.declineOrCancelFollowRequest.useMutation({...m(c.NotFollowing)}),{t:x}=(0,s.$G)(),v=b.data?.readerToProject??null,[S,I]=(0,a.useState)(!1),k=(0,a.useCallback)((async()=>{if(!n.projectId)return;const t={fromProjectId:n.projectId,toProjectId:e.projectId};switch(v){case c.FollowRequested:await j.mutateAsync(t);break;case c.NotFollowing:await h.mutateAsync(t);break;case c.Following:I(!0);break;case null:return}}),[j,h,v,e.projectId,n.projectId]),E=(0,a.useCallback)((async()=>{if(!n.projectId)return;const t={fromProjectId:n.projectId,toProjectId:e.projectId};await y.mutateAsync(t),I(!1)}),[e.projectId,n.projectId,y]);let F="unknown";if(n.loggedIn)if(v===c.Following)F=x("client:page.unfollow-button","unfollow");else if(v===c.NotFollowing)F=e.privacy===l.WL.Private?x("client:page.follow-request-button","send follow request"):x("client:page.follow-button","follow");else{if(v!==c.FollowRequested)return null;F=x("client:page.cancel-follow-request-button","cancel follow request")}else F=x("common:login");return n.loggedIn?a.createElement(a.Fragment,null,a.createElement(p.w,{isOpen:S,title:x("client:unfollow-page.confirm-title","Unfollow this page?"),body:x("client:unfollow-page.confirm-body","Are you sure you want to unfollow this page?"),confirm:{label:x("common:unfollow","unfollow")},cancel:{label:x("common:cancel","cancel")},onConfirm:E,onCancel:()=>I(!1)}),a.createElement(u.zx,{buttonStyle:"pill",color:o,onClick:k},F)):a.createElement(u.Qj,{buttonStyle:"pill",color:o,href:d.ZP.public.login({originalUrl:w}).toString()},F)}},80752:function(e,t,o){o.d(t,{t:function(){return p}});var r=o(94159),l=o(83052),n=o(64499),c=o(71860),a=o(81511),s=o(51028),i=o(8227),u=o(2735);const d=({requester:e})=>{const{t:t}=(0,s.$G)(),o=(0,i.Pc)(),{onAction:l}=(0,r.useContext)(a.FollowRequestsContext),n=c.S.useContext(),d=t=>({onSettled:async()=>{l(e.projectId,t),await n.relationships.countFollowRequests.invalidate(),await n.posts.profilePosts.invalidate()}}),g=c.S.relationships.acceptFollowRequest.useMutation(d("accept")),p=(0,r.useCallback)((async()=>{o.projectId&&await g.mutateAsync({fromProjectId:e.projectId,toProjectId:o.projectId})}),[g,e.projectId,o.projectId]),f=c.S.relationships.declineOrCancelFollowRequest.useMutation(d("decline")),b=(0,r.useCallback)((async()=>{o.projectId&&await f.mutateAsync({fromProjectId:e.projectId,toProjectId:o.projectId})}),[f,e.projectId,o.projectId]);return r.createElement("div",{className:"flex flex-row justify-center gap-2"},r.createElement(u.zx,{buttonStyle:"pill",color:"green",onClick:p},t("server:relationships.accept-follow-request-button-text-short","accept")),r.createElement(u.zx,{buttonStyle:"pill",color:"red",onClick:b},t("server:relationships.decline-follow-request-button-text-short","decline")))};var g=o(51540);const p=({project:e,isFollowRequest:t=!1})=>r.createElement("div",{className:"flex flex-row items-center gap-1"},r.createElement(g.t,{project:e}),r.createElement("div",{className:"min-w-0 flex-shrink justify-center gap-0 lg:flex-row"},r.createElement("div",{className:"items-left flex flex-shrink flex-row gap-1 lg:flex-col"},r.createElement(l.H,{project:e})),r.createElement("p",null,e.dek)),r.createElement("div",{className:"flex-grow"}),t?r.createElement(d,{requester:e}):r.createElement(n.e,{project:e,color:"cherry"}))}}]);
//# sourceMappingURL=client-preact-components-pages-follow-requests.02dfa60a396a0c092dac.js.map