loader.NewTweetsPill.2fbd3aba.js 11 KB

12
  1. "use strict";(self.webpackChunk_twitter_responsive_web=self.webpackChunk_twitter_responsive_web||[]).push([["loader.NewTweetsPill"],{91393:(e,t,i)=>{i.r(t),i.d(t,{NewTweetsPill:()=>D,default:()=>k});i(6886);var s=i(2784),n=i(25686),r=i(79866),o=i(73186),a=i(11839),l=i(37800),c=i(36934),m=i(79404),u=i.n(m),h=i(49650),p=i(1206),d=i(19884),w=i(24762),_=i(19313),g=i(24949),y=i(53223),b=i(6800),f=i(92160),T=i(57659);const S=(e,t)=>t.alert&&t.alert.userIds||(0,b.o)(),v=(0,f.Z)().propsFromState((()=>({userImageUrls:(0,g.P1)(T.ZP.selectAll,S,((e,t)=>t?(0,y.Z)(t.map((t=>{const i=e[t];return i?i.profile_image_url_https:void 0}))):[]))}))).withAnalytics({component:"new_tweet_prompt"}),Z=u().gdb8bdcc,C=u().ac0f6492,E={},x={};class D extends s.PureComponent{constructor(...e){super(...e),this.state={show:!1},this._getLastShownTime=()=>x[this.props.timelineId],this._hide=()=>{const{alert:e,removeAlert:t,timelineId:i}=this.props;this._mounted&&(this._updateLastShownTime(i),this.setState({show:!1})),e&&setTimeout((()=>t()),500)},this._attemptShow=()=>{const{featureSwitches:e}=this.context,{alert:t,isAtNewest:i,removeAlert:s,timelineId:n,unreadCount:r}=this.props;if(this._attemptShowTimeout&&(clearTimeout(this._attemptShowTimeout),this._attemptShowTimeout=null),this._mounted&&(t||r>0)){const r=this._getDelayRemaining();if(r<=0){if(t&&i())return void s();this.setState({show:!0}),E[n]=Date.now(),this._scribeAction("show");const r=e.isTrue("responsive_web_home_sticky_new_tweets_pill_enabled"),o=e.getNumberValue("responsive_web_home_sticky_new_tweets_pill_duration_seconds",-1);r&&o>0&&(this._autoDismissTimeout=setTimeout(this._hide,1e3*o))}else this._attemptShowTimeout=setTimeout(this._attemptShow,r)}},this._handleScrollDown=()=>{const{featureSwitches:e}=this.context,{alert:t,remainVisibleInterval:i,timelineId:s}=this.props;if(t&&this.state.show&&e.isTrue("responsive_web_home_sticky_new_tweets_pill_enabled"))return;let n=i;t&&t.displayDurationMs&&t.displayDurationMs>-1&&(n=t.displayDurationMs),this.state.show&&Date.now()>=E[s]+n&&(this._scribeAction("dismiss"),this._hide())},this._handleClick=()=>{const{applyNewTweetsBarInstructions:e}=this.props;this._scribeAction("click"),window.scrollTo(0,0),null==e||e(),this._hide()}}componentDidMount(){this._mounted=!0,this._getLastShownTime()||this._updateLastShownTime(this.props.timelineId),this._attemptShow(),this._cancelMomentum=(0,w.ZP)({onUp:p.Z,onDown:this._handleScrollDown})}componentDidUpdate(e,t){const{alert:i,timelineId:s,unreadCount:n}=this.props,r=e.timelineId!==s,o=r&&!this._getLastShownTime();r?(o&&this._updateLastShownTime(s),t.show&&this._updateLastShownTime(e.timelineId),null==e.removeAlert||e.removeAlert(),this.setState({show:!1}),this._attemptShow()):((i&&!t.show||n>e.unreadCount)&&this._attemptShow(),!e.alert&&0!==n||i||this._hide())}componentWillUnmount(){const{removeAlert:e,timelineId:t}=this.props;this._mounted=!1,this._attemptShowTimeout&&clearTimeout(this._attemptShowTimeout),this._autoDismissTimeout&&clearTimeout(this._autoDismissTimeout),this.state.show&&(this._updateLastShownTime(t),null==e||e()),this._cancelMomentum()}render(){const{alert:e,label:t,userImageUrls:i}=this.props,{show:m}=this.state;let u;u=e?e.richText&&s.createElement(d.Z,{entities:e.richText.entities,text:e.richText.text}):t;const p=r.Z.generate({backgroundColor:o.Z.theme.colors.primary,color:o.Z.theme.colors.whiteOnColor}),w=m?I.show:I.hide;return s.createElement(n.Z,{accessibilityRole:"status",style:w},s.createElement(a.Z,{accessibilityHidden:!m,accessibilityLabel:C,accessibilityRole:"button",interactiveStyles:p,onClick:this._handleClick,style:I.pill},s.createElement(n.Z,{style:I.innerPill},s.createElement(h.Z,{style:I.icon}),i&&i.length>0?s.createElement(n.Z,{style:I.facepile},s.createElement(l.Z,{borderColor:"primary",userAvatarSize:"large",userAvatarUrls:i})):null,s.createElement(c.ZP,{color:"whiteOnColor",numberOfLines:1,style:I.pillText},u))))}_getDelayRemaining(){const{featureSwitches:e}=this.context,{alert:t,triggerDelay:i}=this.props,s=e.getNumberValue("responsive_web_home_sticky_new_tweets_pill_delay_seconds",1),n=e.isTrue("responsive_web_home_sticky_new_tweets_pill_enabled")&&s>0?1e3*s:t&&t.triggerDelayMs||i;return this._getLastShownTime()+n-Date.now()}_updateLastShownTime(e){e&&(x[e]=Date.now())}_scribeAction(e){const{analytics:t}=this.props;if("click"===e&&window.performance){const i=(window.performance.now()/1e3).toFixed(2);t.scribe({action:e,data:{time_since_launch:i}})}else t.scribeAction(e)}}D.contextType=_.rC,D.defaultProps={isAtNewest:()=>!0,label:Z,remainVisibleInterval:3e3,triggerDelay:24e4,unreadCount:0};const I=o.Z.create((e=>{const t={transitionProperty:"transform, opacity",transitionDuration:"0.15s"};return{pill:{justifyContent:"center",paddingHorizontal:e.spaces.space16,boxShadow:e.boxShadows.small,backgroundColor:e.colors.primary,borderRadius:e.borderRadii.infinite,marginVertical:e.spaces.space16},innerPill:{flexDirection:"row",paddingVertical:e.spaces.space4},icon:{width:e.spaces.space20,marginEnd:e.spaces.space4,alignSelf:"center",color:e.colors.whiteOnColor},facepile:{marginEnd:e.spaces.space8},pillText:{alignSelf:"center"},hide:{...t,opacity:0,transform:[{translate3d:"0, -3.5em, 0"}],transitionTimingFunction:"ease, ease, step-end"},show:{...t,pointerEvents:"all",opacity:1,transform:[{translate3d:"0, 0, 0"}],transitionTimingFunction:"ease, ease, step-start"}}})),k=v(D)},19231:(e,t,i)=>{i.r(t),i.d(t,{LAST_DISMISSED:()=>D,NewTweetsPillv2:()=>P,PILL_AUTO_DISMISS_DELAY_MS:()=>A,PILL_LAST_SEEN_MINIMUM_DELAY:()=>k,PILL_SHOW_DELAY_MS:()=>I,default:()=>N});i(6886);var s=i(2784),n=i(25686),r=i(6555),o=i(79404),a=i.n(o),l=i(49650),c=i(36934),m=i(37800),u=i(79866),h=i(11839),p=i(73186);const d=a().aed03d34;const w=p.Z.create((e=>({root:{backgroundColor:e.colors.primary,borderRadius:e.borderRadii.infinite,boxShadow:e.boxShadows.small,justifyContent:"center",paddingVertical:e.spaces.space4,paddingHorizontal:e.spaces.space16},facepiles:{marginStart:e.spaces.space4,marginEnd:e.spaces.space2},icon:{alignSelf:"center",color:e.colors.whiteOnColor},pillContent:{flexDirection:"row"},pillText:{marginStart:e.spaces.space4,alignSelf:"center"}}))),_=function(e){const{label:t,onClick:i,onImpression:r,userAvatarUrls:o}=e;s.useEffect((()=>{null==r||r()}),[]);const a=u.Z.generate({backgroundColor:p.Z.theme.colors.primary,color:p.Z.theme.colors.whiteOnColor});return s.createElement(n.Z,{accessibilityRole:"status"},s.createElement(h.Z,{interactiveStyles:a,onClick:i,style:w.root},s.createElement(n.Z,{style:w.pillContent},s.createElement(l.Z,{style:w.icon}),o&&o.length>0?s.createElement(n.Z,{accessibilityLabel:d,style:w.facepiles,testID:"userAvatars"},s.createElement(m.Z,{borderColor:"primary",userAvatarSize:"large",userAvatarUrls:o})):null,s.createElement(c.ZP,{color:"whiteOnColor",style:w.pillText},t))))};var g=i(24949),y=i(53223),b=i(92160),f=i(57659);const T=[],S=Object.freeze({}),v=(e,{alert:t})=>t&&t.userIds||T,Z=(e,{module:t})=>(null==t?void 0:t.selectNewTweetsBar(e))||S,C=(0,b.Z)().propsFromState((()=>({userImageUrls:(0,g.P1)(f.ZP.selectAll,v,((e,t)=>t.length>0?(0,y.Z)(t.map((t=>{const i=e[t];return i?i.profile_image_url_https:void 0}))):T)),newTweetsBar:Z}))).withAnalytics({component:"new_tweet_prompt"}),E=a().gdb8bdcc,x=a().a0b7f128,D={},I=1e3,k=3e4,A=12e4;function P(e){const{alert:t,analytics:i,applyNewTweetsBarInstructions:o,label:a=E,newTweetsBar:l,removeAlert:c,timelineId:m,unreadCount:u=0,userImageUrls:h}=e,p=s.useRef(null),d=s.useRef(null),w=s.useRef(!0),[g,y]=s.useState(!1),b=s.useCallback((e=>{i.scribe({action:e,..."click"===e&&window.performance&&{data:{time_since_launch:(window.performance.now()/1e3).toFixed(2)}}})}),[i]),f=s.useCallback((()=>{D[m]=Date.now(),w.current&&y(!1),b("click"),null==o||o(),null==c||c()}),[o,c,b,m]),T=s.useCallback((()=>{window.scrollTo(0,0),f()}),[f]),S=s.useCallback((()=>{w.current&&y(!0),p.current&&clearTimeout(p.current),p.current=setTimeout(f,A)}),[f]);s.useEffect((()=>{w.current=!0})),s.useEffect((()=>{if(!!(t||l.count||u)){if(d.current&&(clearTimeout(d.current),d.current=null),D[m]){const e=Date.now()-D[m];if(e<k)return void(d.current=setTimeout(S,k-e))}d.current=setTimeout(S,I)}}),[m,t,l.count,u,f,S]);const v=(null==t?void 0:t.richText)&&s.createElement(r.Z,{entities:t.richText.entities,text:t.richText.text}),Z=s.useMemo((()=>[L.pill,g?L.show:L.hide]),[g]),C=g?null!=v?v:a:x;return s.createElement(n.Z,{style:Z,testID:"pill-container"},s.createElement(_,{label:C,onClick:T,userAvatarUrls:h}))}const L=p.Z.create((e=>{const t={transitionProperty:"transform, opacity, visibility",transitionDuration:"0.15s"};return{pill:{marginVertical:e.spaces.space16},hide:{...t,visibility:"hidden",opacity:0,transform:[{translate3d:"0, -3.5em, 0"}],transitionTimingFunction:"ease, ease, step-end"},show:{...t,pointerEvents:"all",opacity:1,visibility:"visible",transform:[{translate3d:"0, 0, 0"}],transitionTimingFunction:"ease, ease, step-start"}}})),N=s.memo(C(P))},49898:(e,t,i)=>{i.d(t,{Z:()=>w});var s=i(2784),n=i(6555),r=i(400),o=i(88809),a=i(24949),l=i(92160),c=i(57659);const m=(e,t)=>t.entityId&&c.ZP.select(e,t.entityId)||void 0,u=e=>`/${e.screen_name}`,h=e=>e.name,p=(0,l.Z)().propsFromState((()=>({user:m,badging:(0,a.P1)(m,(e=>e?{displayContext:"content",isBlueVerified:e.is_blue_verified,isProtected:e.protected,isVerified:e.verified,verifiedType:e.verified_type,translatorType:e.translator_type}:void 0))}))).adjustStateProps((({badging:e,user:t})=>({badging:e,link:t&&u(t),screenName:t&&t.screen_name,text:t&&h(t)||""})));class d extends s.PureComponent{render(){const{color:e,link:t,onClick:i,screenName:r,text:a,weight:l,withHashflags:c}=this.props,m=s.createElement(n.Z.TextFragment,{color:e,link:t,onClick:i,weight:l,withHashflags:c},a,this._renderBadges());return r?s.createElement(o.Z,{screenName:r},m):m}_renderBadges(){const{badging:e}=this.props;return e?s.createElement(r.Z,e):null}}const w=p(d)},19884:(e,t,i)=>{i.d(t,{Z:()=>p});var s=i(7896),n=i(2784),r=i(6555),o=i(73186),a=i(91584),l=i(49898);const c="Center",m="Natural";class u extends n.PureComponent{render(){const{accessibilityRole:e,alignment:t,color:i,entities:o,forceAutoTextDirection:m,nativeID:u,onEntityClick:p,rtl:d,size:w,style:_,text:g,weight:y,withHashflags:b}=this.props,f=t===c?"center":void 0,T=m?"auto":d?"rtl":"ltr";return n.createElement(r.Z,{accessibilityRole:e,align:f,color:i,dir:T,entities:o,nativeID:u,onEntityClick:p,renderFragment:{user:(e,t)=>n.createElement(l.Z,(0,s.Z)({},e,{color:"text",entityId:t.id})),url:(e,t)=>n.createElement(r.Z.TextFragment,(0,s.Z)({},e,{link:(0,a.s9)(t)}))},size:w,style:[h.hideOverflow,_],text:g,weight:y,withHashflags:b})}}u.defaultProps={alignment:m};const h=o.Z.create((e=>({hideOverflow:{overflow:"hidden"}}))),p=u},6800:(e,t,i)=>{i.d(t,{o:()=>n});var s=i(16742);const n=(0,s.Z)([]);(0,s.Z)({})}}]);
  2. //# sourceMappingURL=https://ton.local.twitter.com/responsive-web-internal/sourcemaps/client-web/loader.NewTweetsPill.2fbd3aba.js.map