adds requiresAuth bool to button and enables it on selected buttons

This commit is contained in:
jessop 2019-10-15 14:53:55 -04:00 committed by Sean Yesmunt
parent edcd2900ca
commit 00262eeb92
9 changed files with 58 additions and 5 deletions

View file

@ -30,6 +30,7 @@ export default function BlockButton(props: Props) {
icon={ICONS.BLOCK}
button={'alt'}
label={blockedOverride || blockLabel}
requiresAuth={IS_WEB}
onClick={e => {
e.stopPropagation();
if (!channelIsBlocked) {

View file

@ -1,3 +1,13 @@
import Button from './view';
import React, { forwardRef } from 'react';
import { connect } from 'react-redux';
import { selectUserVerifiedEmail } from 'lbryinc';
export default Button;
const mapStateToProps = state => ({
pathname: state.router.location.pathname,
emailVerified: selectUserVerifiedEmail(state),
});
const ConnectedButton = connect(mapStateToProps)(Button);
export default forwardRef((props, ref) => <ConnectedButton {...props} myref={ref} />);

View file

@ -6,6 +6,7 @@ import classnames from 'classnames';
import { NavLink } from 'react-router-dom';
import { formatLbryUriForWeb } from 'util/uri';
import { OutboundLink } from 'react-ga';
import * as PAGES from 'constants/pages';
type Props = {
id: ?string,
@ -30,6 +31,11 @@ type Props = {
onClick: ?(any) => any,
onMouseEnter: ?(any) => any,
onMouseLeave: ?(any) => any,
pathname: string,
emailVerified: boolean,
requiresAuth: ?boolean,
myref: any,
dispatch: any,
};
// use forwardRef to allow consumers to pass refs to the button content if they want to
@ -55,9 +61,15 @@ const Button = forwardRef<any, {}>((props: Props, ref: any) => {
iconColor,
constrict,
activeClass,
emailVerified,
requiresAuth,
myref,
dispatch, // <button> doesn't know what to do with dispatch
pathname,
...otherProps
} = props;
const currentPath = pathname.split('/$/')[1];
const combinedClassName = classnames(
'button',
button
@ -103,6 +115,22 @@ const Button = forwardRef<any, {}>((props: Props, ref: any) => {
}
}
if (requiresAuth && !emailVerified) {
return (
<NavLink
ref={ref}
exact
to={`/$/${PAGES.AUTH}?redirect=${currentPath}`}
title={title}
disabled={disabled}
className={combinedClassName}
activeClassName={activeClass}
>
{content}
</NavLink>
);
}
return path ? (
<NavLink
ref={ref}

View file

@ -89,6 +89,7 @@ export function CommentCreate(props: Props) {
disabled={channel === CHANNEL_NEW || !commentValue.length}
type="submit"
label={__('Post')}
requiresAuth={IS_WEB}
/>
</div>
</Form>

View file

@ -47,6 +47,7 @@ export default function SubscribeButton(props: Props) {
iconColor="red"
icon={unfollowOverride ? ICONS.UNSUBSCRIBE : ICONS.SUBSCRIBE}
button={'alt'}
requiresAuth={IS_WEB}
label={unfollowOverride || subscriptionLabel}
onClick={e => {
e.stopPropagation();

View file

@ -21,7 +21,7 @@ function DiscoverPage(props: Props) {
hideCustomization={IS_WEB && !email}
personalView
tags={followedTags.map(tag => tag.name)}
meta={<Button button="link" label={__('Customize')} navigate={`/$/${PAGES.FOLLOWING}`} />}
meta={<Button button="link" label={__('Customize')} requiresAuth={IS_WEB} navigate={`/$/${PAGES.FOLLOWING}`} />}
/>
</Page>
);

View file

@ -184,6 +184,7 @@ class FilePage extends React.Component<Props> {
button="alt"
icon={icons.TIP}
label={__('Tip')}
requiresAuth={IS_WEB}
title={__('Send a tip to this creator')}
onClick={() => openModal(MODALS.SEND_TIP, { uri, claimIsMine, isSupport: false })}
/>
@ -193,6 +194,7 @@ class FilePage extends React.Component<Props> {
button="alt"
icon={icons.SUPPORT}
label={__('Support')}
requiresAuth={IS_WEB}
title={__('Support this claim')}
onClick={() => openModal(MODALS.SEND_TIP, { uri, claimIsMine, isSupport: true })}
/>

View file

@ -45,7 +45,7 @@ function TagsPage(props: Props) {
<Page>
<ClaimListDiscover
tags={tags}
meta={<Button ref={buttonRef} button="link" onClick={handleFollowClick} label={label} />}
meta={<Button ref={buttonRef} button="link" onClick={handleFollowClick} requiresAuth={IS_WEB} label={label} />}
/>
</Page>
);

View file

@ -803,5 +803,15 @@
"This app will automatically download new free content from channels you are subscribed to. You may configure this in Settings or on the Subscriptions page.": "This app will automatically download new free content from channels you are subscribed to. You may configure this in Settings or on the Subscriptions page.",
"(Only available on the desktop app.)": "(Only available on the desktop app.)",
"If we have your email address, we will send you notifications related to new content. You may configure these emails from the Help page.": "If we have your email address, we will send you notifications related to new content. You may configure these emails from the Help page.",
"Light": "Light"
}
"Light": "Light",
"Subscriber": "Subscriber",
"This account must undergo review before you can participate in the rewards program.": "This account must undergo review before you can participate in the rewards program.",
"This can take anywhere from several minutes to several days.": "This can take anywhere from several minutes to several days.",
"We apologize for this inconvenience, but have added this additional step to prevent fraud.": "We apologize for this inconvenience, but have added this additional step to prevent fraud.",
"If you continue to see this message, send us an email to help@lbry.com.": "If you continue to see this message, send us an email to help@lbry.com.",
"Please enjoy free content in the meantime!": "Please enjoy free content in the meantime!",
"Claimed Rewards": "Claimed Rewards",
"This feature is not yet available for wallets with balances, but the gerbils are working on it.": "This feature is not yet available for wallets with balances, but the gerbils are working on it.",
"I Understand": "I Understand",
"No modifier provided after separator %modSeperator%.": "No modifier provided after separator %modSeperator%."
}