2016-11-22 21:19:08 +01:00
|
|
|
import React from 'react';
|
2017-01-21 22:31:41 +01:00
|
|
|
import {Icon} from './common.js';
|
2017-04-10 14:32:40 +02:00
|
|
|
import Modal from '../component/modal.js';
|
|
|
|
import rewards from '../rewards.js';
|
2016-11-22 21:19:08 +01:00
|
|
|
|
|
|
|
export let Link = React.createClass({
|
2017-01-09 05:56:21 +01:00
|
|
|
propTypes: {
|
|
|
|
label: React.PropTypes.string,
|
|
|
|
icon: React.PropTypes.string,
|
|
|
|
button: React.PropTypes.string,
|
|
|
|
badge: React.PropTypes.string,
|
|
|
|
hidden: React.PropTypes.bool,
|
|
|
|
},
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
hidden: false,
|
|
|
|
disabled: false,
|
|
|
|
};
|
|
|
|
},
|
2017-01-13 16:44:23 +01:00
|
|
|
handleClick: function(e) {
|
2016-08-07 22:36:57 +02:00
|
|
|
if (this.props.onClick) {
|
2017-01-13 16:44:23 +01:00
|
|
|
this.props.onClick(e);
|
2016-08-07 22:36:57 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
render: function() {
|
2017-01-09 05:56:21 +01:00
|
|
|
if (this.props.hidden) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2017-01-17 11:50:38 +01:00
|
|
|
/* The way the class name is generated here is a mess -- refactor */
|
|
|
|
|
2017-01-09 05:56:21 +01:00
|
|
|
const className = (this.props.className || '') +
|
2017-01-25 04:22:36 +01:00
|
|
|
(!this.props.className && !this.props.button ? 'button-text' : '') + // Non-button links get the same look as text buttons
|
2017-02-21 07:26:59 +01:00
|
|
|
(this.props.button ? ' button-block button-' + this.props.button + ' button-set-item' : '') +
|
2017-01-09 05:56:21 +01:00
|
|
|
(this.props.disabled ? ' disabled' : '');
|
2016-08-07 22:36:57 +02:00
|
|
|
|
2017-01-09 11:43:57 +01:00
|
|
|
let content;
|
|
|
|
if (this.props.children) { // Custom content
|
|
|
|
content = this.props.children;
|
|
|
|
} else {
|
2017-01-24 01:22:25 +01:00
|
|
|
content = (
|
|
|
|
<span {... 'button' in this.props ? {className: 'button__content'} : {}}>
|
|
|
|
{'icon' in this.props ? <Icon icon={this.props.icon} fixed={true} /> : null}
|
|
|
|
{<span className="link-label">{this.props.label}</span>}
|
|
|
|
{'badge' in this.props ? <span className="badge">{this.props.badge}</span> : null}
|
|
|
|
</span>
|
|
|
|
);
|
2017-01-09 11:43:57 +01:00
|
|
|
}
|
|
|
|
|
2016-08-07 22:36:57 +02:00
|
|
|
return (
|
2017-01-09 05:56:21 +01:00
|
|
|
<a className={className} href={this.props.href || 'javascript:;'} title={this.props.title}
|
|
|
|
onClick={this.handleClick} {... 'style' in this.props ? {style: this.props.style} : {}}>
|
2017-01-24 01:22:25 +01:00
|
|
|
{content}
|
2016-08-07 22:36:57 +02:00
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
2017-04-10 14:32:40 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
export let RewardLink = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
type: React.PropTypes.string.isRequired,
|
|
|
|
claimed: React.PropTypes.bool,
|
2017-04-12 22:23:20 +02:00
|
|
|
onRewardClaim: React.PropTypes.func,
|
|
|
|
onRewardFailure: React.PropTypes.func
|
2017-04-10 14:32:40 +02:00
|
|
|
},
|
|
|
|
refreshClaimable: function() {
|
|
|
|
switch(this.props.type) {
|
|
|
|
case 'new_user':
|
|
|
|
this.setState({ claimable: true });
|
|
|
|
return;
|
|
|
|
|
|
|
|
case 'first_publish':
|
|
|
|
lbry.claim_list_mine().then(function(list) {
|
|
|
|
this.setState({
|
|
|
|
claimable: list.length > 0
|
|
|
|
})
|
|
|
|
}.bind(this));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
componentWillMount: function() {
|
|
|
|
this.refreshClaimable();
|
|
|
|
},
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
claimable: true,
|
|
|
|
pending: false,
|
|
|
|
errorMessage: null
|
|
|
|
}
|
|
|
|
},
|
|
|
|
claimReward: function() {
|
|
|
|
this.setState({
|
|
|
|
pending: true
|
|
|
|
})
|
|
|
|
rewards.claimReward(this.props.type).then(function(reward) {
|
|
|
|
this.setState({
|
|
|
|
pending: false,
|
|
|
|
errorMessage: null
|
|
|
|
})
|
|
|
|
if (this.props.onRewardClaim) {
|
|
|
|
this.props.onRewardClaim();
|
|
|
|
}
|
|
|
|
}.bind(this)).catch(function(error) {
|
|
|
|
this.setState({
|
|
|
|
errorMessage: error.message,
|
|
|
|
pending: false
|
|
|
|
})
|
|
|
|
}.bind(this))
|
|
|
|
},
|
|
|
|
clearError: function() {
|
2017-04-12 22:23:20 +02:00
|
|
|
if (this.props.onRewardFailure) {
|
|
|
|
this.props.onRewardFailure()
|
|
|
|
}
|
2017-04-10 14:32:40 +02:00
|
|
|
this.setState({
|
|
|
|
errorMessage: null
|
|
|
|
})
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
return (
|
|
|
|
<div className="reward-link">
|
|
|
|
{this.props.claimed
|
|
|
|
? <span><Icon icon="icon-check" /> Reward claimed.</span>
|
2017-04-12 22:23:20 +02:00
|
|
|
: <Link button={this.props.button ? this.props.button : 'alt'} disabled={this.state.pending || !this.state.claimable } label="Claim Reward" onClick={this.claimReward} />}
|
2017-04-10 14:32:40 +02:00
|
|
|
{this.state.errorMessage ?
|
|
|
|
<Modal isOpen={true} contentLabel="Reward Claim Error" className="error-modal" onConfirmed={this.clearError}>
|
|
|
|
{this.state.errorMessage}
|
|
|
|
</Modal>
|
|
|
|
: ''}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-01-21 22:31:41 +01:00
|
|
|
});
|