move nudge to FileReactions and add src param to sign up redirects

This commit is contained in:
Sean Yesmunt 2020-11-17 14:10:14 -05:00
parent 00350fec80
commit e5301dec04
8 changed files with 88 additions and 47 deletions

View file

@ -27,6 +27,7 @@ type Props = {
iconColor?: string, iconColor?: string,
activeClass?: string, activeClass?: string,
innerRef: ?any, innerRef: ?any,
authSrc?: string,
// Events // Events
onClick: ?(any) => any, onClick: ?(any) => any,
onMouseEnter: ?(any) => any, onMouseEnter: ?(any) => any,
@ -50,6 +51,7 @@ const Button = forwardRef<any, {}>((props: Props, ref: any) => {
label, label,
largestLabel, largestLabel,
icon, icon,
// This should rarely be used. Regular buttons should just use `icon` // This should rarely be used. Regular buttons should just use `icon`
// `iconRight` is used for the header (home) button with the LBRY icon and external links that are displayed inline // `iconRight` is used for the header (home) button with the LBRY icon and external links that are displayed inline
iconRight, iconRight,
@ -67,6 +69,7 @@ const Button = forwardRef<any, {}>((props: Props, ref: any) => {
myref, myref,
dispatch, // <button> doesn't know what to do with dispatch dispatch, // <button> doesn't know what to do with dispatch
pathname, pathname,
authSrc,
...otherProps ...otherProps
} = props; } = props;
@ -172,13 +175,19 @@ const Button = forwardRef<any, {}>((props: Props, ref: any) => {
} }
if (requiresAuth && !emailVerified) { if (requiresAuth && !emailVerified) {
let redirectUrl = `/$/${PAGES.AUTH}?redirect=${pathname}`;
if (authSrc) {
redirectUrl += `&src=${authSrc}`;
}
return ( return (
<NavLink <NavLink
exact exact
onClick={e => { onClick={e => {
e.stopPropagation(); e.stopPropagation();
}} }}
to={`/$/${PAGES.AUTH}?redirect=${pathname}`} to={redirectUrl}
title={title || defaultTooltip} title={title || defaultTooltip}
disabled={disabled} disabled={disabled}
className={combinedClassName} className={combinedClassName}

View file

@ -1,13 +1,11 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { doOpenModal } from 'redux/actions/app'; import { doOpenModal } from 'redux/actions/app';
import { selectUser } from 'redux/selectors/user';
import { makeSelectTagInClaimOrChannelForUri } from 'lbry-redux'; import { makeSelectTagInClaimOrChannelForUri } from 'lbry-redux';
import ClaimSupportButton from './view'; import ClaimSupportButton from './view';
const DISABLE_SUPPORT_TAG = 'disable-support'; const DISABLE_SUPPORT_TAG = 'disable-support';
const select = (state, props) => ({ const select = (state, props) => ({
disableSupport: makeSelectTagInClaimOrChannelForUri(props.uri, DISABLE_SUPPORT_TAG)(state), disableSupport: makeSelectTagInClaimOrChannelForUri(props.uri, DISABLE_SUPPORT_TAG)(state),
user: selectUser(state),
}); });
export default connect(select, { export default connect(select, {

View file

@ -4,60 +4,31 @@ import * as ICONS from 'constants/icons';
import React from 'react'; import React from 'react';
import classnames from 'classnames'; import classnames from 'classnames';
import Button from 'component/button'; import Button from 'component/button';
import usePersistedState from 'effects/use-persisted-state';
type Props = { type Props = {
uri: string, uri: string,
doOpenModal: (string, {}) => void, doOpenModal: (string, {}) => void,
fileAction?: boolean, fileAction?: boolean,
disableSupport: boolean, disableSupport: boolean,
user: ?User,
}; };
export default function ClaimSupportButton(props: Props) { export default function ClaimSupportButton(props: Props) {
const { doOpenModal, uri, fileAction, disableSupport, user } = props; const { doOpenModal, uri, fileAction, disableSupport } = props;
const [showNudge, setShowNudge] = React.useState(false);
const [nudgeAcknowledged, setNudgeAcknowledged] = usePersistedState('nudge:support-acknowledge', false);
const emailVerified = user && user.has_verified_email;
React.useEffect(() => {
if (!emailVerified && !nudgeAcknowledged && fileAction) {
setShowNudge(true);
}
}, [emailVerified, nudgeAcknowledged, fileAction]);
if (disableSupport) { if (disableSupport) {
return null; return null;
} }
return ( return (
<> <Button
<Button button={fileAction ? undefined : 'alt'}
button={fileAction ? undefined : 'alt'} className={classnames({ 'button--file-action': fileAction })}
className={classnames({ 'button--file-action': fileAction, 'button--highlighted': showNudge })} icon={ICONS.LBC}
icon={ICONS.LBC} iconSize={fileAction ? 22 : undefined}
iconSize={fileAction ? 22 : undefined} label={__('Support --[button to support a claim]--')}
label={__('Support --[button to support a claim]--')} requiresAuth={IS_WEB}
requiresAuth={IS_WEB} title={__('Support this claim')}
title={__('Support this claim')} onClick={() => doOpenModal(MODALS.SEND_TIP, { uri, isSupport: true })}
onClick={() => doOpenModal(MODALS.SEND_TIP, { uri, isSupport: true })} />
/>
{showNudge && (
<div className="nudge">
<div className="nudge__wrapper">
<span className="nudge__text">{__('Create an account to support this creator!')}</span>
<Button
className="nudge__close"
button="close"
icon={ICONS.REMOVE}
onClick={() => {
setNudgeAcknowledged(true);
setShowNudge(false);
}}
/>
</div>
</div>
)}
</>
); );
} }

View file

@ -4,6 +4,7 @@ import React from 'react';
import classnames from 'classnames'; import classnames from 'classnames';
import Button from 'component/button'; import Button from 'component/button';
import { formatNumberWithCommas } from 'util/number'; import { formatNumberWithCommas } from 'util/number';
import NudgeFloating from 'component/nudgeFloating';
type Props = { type Props = {
claim: StreamClaim, claim: StreamClaim,
@ -19,6 +20,7 @@ type Props = {
function FileReactions(props: Props) { function FileReactions(props: Props) {
const { claim, uri, doFetchReactions, doReactionLike, doReactionDislike, likeCount, dislikeCount } = props; const { claim, uri, doFetchReactions, doReactionLike, doReactionDislike, likeCount, dislikeCount } = props;
const claimId = claim && claim.claim_id; const claimId = claim && claim.claim_id;
const channel = claim && claim.signing_channel && claim.signing_channel.name;
React.useEffect(() => { React.useEffect(() => {
if (claimId) { if (claimId) {
@ -28,9 +30,17 @@ function FileReactions(props: Props) {
return ( return (
<> <>
{channel && (
<NudgeFloating
name="nudge:support-acknowledge"
text={__('Let %channel% know you enjoyed this!', { channel })}
/>
)}
<Button <Button
title={__('I like this')} title={__('I like this')}
requiresAuth requiresAuth={IS_WEB}
authSrc="filereaction_like"
className={classnames('button--file-action')} className={classnames('button--file-action')}
label={formatNumberWithCommas(likeCount)} label={formatNumberWithCommas(likeCount)}
iconSize={18} iconSize={18}
@ -38,7 +48,8 @@ function FileReactions(props: Props) {
onClick={() => doReactionLike(uri)} onClick={() => doReactionLike(uri)}
/> />
<Button <Button
requiresAuth requiresAuth={IS_WEB}
authSrc={'filereaction_dislike'}
title={__('I dislike this')} title={__('I dislike this')}
className={classnames('button--file-action')} className={classnames('button--file-action')}
label={formatNumberWithCommas(dislikeCount)} label={formatNumberWithCommas(dislikeCount)}

View file

@ -0,0 +1,9 @@
import { connect } from 'react-redux';
import { selectUser } from 'redux/selectors/user';
import NudgeFloating from './view';
const select = state => ({
user: selectUser(state),
});
export default connect(select)(NudgeFloating);

View file

@ -0,0 +1,43 @@
// @flow
import * as ICONS from 'constants/icons';
import React from 'react';
import usePersistedState from 'effects/use-persisted-state';
import Button from 'component/button';
type Props = {
user: ?User,
name: string,
text: string,
};
export default function NudgeFloating(props: Props) {
const { user, name, text } = props;
const [showNudge, setShowNudge] = React.useState(false);
const [nudgeAcknowledged, setNudgeAcknowledged] = usePersistedState(name, false);
const emailVerified = user && user.has_verified_email;
React.useEffect(() => {
if (!emailVerified && !nudgeAcknowledged) {
setShowNudge(true);
}
}, [emailVerified, nudgeAcknowledged]);
return (
showNudge && (
<div className="nudge">
<div className="nudge__wrapper">
<span className="nudge__text">{text}</span>
<Button
className="nudge__close"
button="close"
icon={ICONS.REMOVE}
onClick={() => {
setNudgeAcknowledged(true);
setShowNudge(false);
}}
/>
</div>
</div>
)
);
}

View file

@ -288,7 +288,7 @@ function SideNavigation(props: Props) {
Sign up to earn %lbc% for you and your favorite creators. Sign up to earn %lbc% for you and your favorite creators.
</I18nMessage> </I18nMessage>
</span> </span>
<Button button="secondary" label={__('Sign Up')} navigate={`/$/${PAGES.AUTH}`} /> <Button button="secondary" label={__('Sign Up')} navigate={`/$/${PAGES.AUTH}?src=sidenav_nudge`} />
</div> </div>
); );

View file

@ -27,7 +27,7 @@
height: 1rem; height: 1rem;
width: 1rem; width: 1rem;
top: -0.5rem; top: -0.5rem;
left: 3rem; left: 1rem;
transform: rotate(45deg); transform: rotate(45deg);
background-color: var(--color-secondary); background-color: var(--color-secondary);
} }