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,
activeClass?: string,
innerRef: ?any,
authSrc?: string,
// Events
onClick: ?(any) => any,
onMouseEnter: ?(any) => any,
@ -50,6 +51,7 @@ const Button = forwardRef<any, {}>((props: Props, ref: any) => {
label,
largestLabel,
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,
@ -67,6 +69,7 @@ const Button = forwardRef<any, {}>((props: Props, ref: any) => {
myref,
dispatch, // <button> doesn't know what to do with dispatch
pathname,
authSrc,
...otherProps
} = props;
@ -172,13 +175,19 @@ const Button = forwardRef<any, {}>((props: Props, ref: any) => {
}
if (requiresAuth && !emailVerified) {
let redirectUrl = `/$/${PAGES.AUTH}?redirect=${pathname}`;
if (authSrc) {
redirectUrl += `&src=${authSrc}`;
}
return (
<NavLink
exact
onClick={e => {
e.stopPropagation();
}}
to={`/$/${PAGES.AUTH}?redirect=${pathname}`}
to={redirectUrl}
title={title || defaultTooltip}
disabled={disabled}
className={combinedClassName}

View file

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

View file

@ -4,37 +4,25 @@ import * as ICONS from 'constants/icons';
import React from 'react';
import classnames from 'classnames';
import Button from 'component/button';
import usePersistedState from 'effects/use-persisted-state';
type Props = {
uri: string,
doOpenModal: (string, {}) => void,
fileAction?: boolean,
disableSupport: boolean,
user: ?User,
};
export default function ClaimSupportButton(props: Props) {
const { doOpenModal, uri, fileAction, disableSupport, user } = 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]);
const { doOpenModal, uri, fileAction, disableSupport } = props;
if (disableSupport) {
return null;
}
return (
<>
<Button
button={fileAction ? undefined : 'alt'}
className={classnames({ 'button--file-action': fileAction, 'button--highlighted': showNudge })}
className={classnames({ 'button--file-action': fileAction })}
icon={ICONS.LBC}
iconSize={fileAction ? 22 : undefined}
label={__('Support --[button to support a claim]--')}
@ -42,22 +30,5 @@ export default function ClaimSupportButton(props: Props) {
title={__('Support this claim')}
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 Button from 'component/button';
import { formatNumberWithCommas } from 'util/number';
import NudgeFloating from 'component/nudgeFloating';
type Props = {
claim: StreamClaim,
@ -19,6 +20,7 @@ type Props = {
function FileReactions(props: Props) {
const { claim, uri, doFetchReactions, doReactionLike, doReactionDislike, likeCount, dislikeCount } = props;
const claimId = claim && claim.claim_id;
const channel = claim && claim.signing_channel && claim.signing_channel.name;
React.useEffect(() => {
if (claimId) {
@ -28,9 +30,17 @@ function FileReactions(props: Props) {
return (
<>
{channel && (
<NudgeFloating
name="nudge:support-acknowledge"
text={__('Let %channel% know you enjoyed this!', { channel })}
/>
)}
<Button
title={__('I like this')}
requiresAuth
requiresAuth={IS_WEB}
authSrc="filereaction_like"
className={classnames('button--file-action')}
label={formatNumberWithCommas(likeCount)}
iconSize={18}
@ -38,7 +48,8 @@ function FileReactions(props: Props) {
onClick={() => doReactionLike(uri)}
/>
<Button
requiresAuth
requiresAuth={IS_WEB}
authSrc={'filereaction_dislike'}
title={__('I dislike this')}
className={classnames('button--file-action')}
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.
</I18nMessage>
</span>
<Button button="secondary" label={__('Sign Up')} navigate={`/$/${PAGES.AUTH}`} />
<Button button="secondary" label={__('Sign Up')} navigate={`/$/${PAGES.AUTH}?src=sidenav_nudge`} />
</div>
);

View file

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