diff --git a/ui/js/component/auth.js b/ui/js/component/auth.js index 7b934f339..0ff99c26f 100644 --- a/ui/js/component/auth.js +++ b/ui/js/component/auth.js @@ -9,23 +9,28 @@ import {CreditAmount, Address} from "../component/common.js"; import {getLocal, getSession, setSession, setLocal} from '../utils.js'; -const SubmitEmailStage = React.createClass({ - getInitialState: function() { - return { +class SubmitEmailStage extends React.Component { + constructor(props) { + super(props); + + this.state = { rewardType: null, email: '', submitting: false }; - }, - handleEmailChanged: function(event) { + } + + handleEmailChanged(event) { this.setState({ email: event.target.value, }); - }, - onEmailSaved: function(email) { + } + + onEmailSaved(email) { this.props.setStage("confirm", { email: email }) - }, - handleSubmit: function(event) { + } + + handleSubmit(event) { event.preventDefault(); this.setState({ @@ -42,38 +47,43 @@ const SubmitEmailStage = React.createClass({ } this.setState({ submitting: false }); }); - }, - render: function() { + } + + render() { return (
-
+ { this.handleSubmit(event) }}> { this._emailRow = ref }} type="text" label="Email" placeholder="scrwvwls@lbry.io" name="email" value={this.state.email} - onChange={this.handleEmailChanged} /> + onChange={(event) => { this.handleEmailChanged(event) }} />
- + { this.handleSubmit(event) }} />
); } -}); +} -const ConfirmEmailStage = React.createClass({ - getInitialState: function() { - return { +class ConfirmEmailStage extends React.Component { + constructor(props) { + super(props); + + this.state = { rewardType: null, code: '', submitting: false, errorMessage: null, }; - }, - handleCodeChanged: function(event) { + } + + handleCodeChanged(event) { this.setState({ code: event.target.value, }); - }, - handleSubmit: function(event) { + } + + handleSubmit(event) { event.preventDefault(); this.setState({ submitting: true, @@ -93,16 +103,17 @@ const ConfirmEmailStage = React.createClass({ onSubmitError(new Error("Your email is still not verified.")) //shouldn't happen? } }, onSubmitError); - }, - render: function() { + } + + render() { return (
-
+ { this.handleSubmit(event) }}> { this._codeRow = ref }} type="text" - name="code" placeholder="a94bXXXXXXXXXXXXXX" value={this.state.code} onChange={this.handleCodeChanged} + name="code" placeholder="a94bXXXXXXXXXXXXXX" value={this.state.code} onChange={(event) => { this.handleCodeChanged(event) }} helper="A verification code is required to access this version."/>
- + { this.handleSubmit(event)}} />
No code? { this.props.setStage("nocode")}} label="Click here" />. @@ -111,25 +122,26 @@ const ConfirmEmailStage = React.createClass({
); } -}); +} -const WelcomeStage = React.createClass({ - propTypes: { - endAuth: React.PropTypes.func, - }, - getInitialState: function() { - return { +class WelcomeStage extends React.Component { + constructor(props) { + super(props); + + this.state = { hasReward: false, rewardAmount: null, - } - }, - onRewardClaim: function(reward) { + }; + } + + onRewardClaim(reward) { this.setState({ hasReward: true, rewardAmount: reward.amount }) - }, - render: function() { + } + + render() { return ( !this.state.hasReward ? @@ -140,7 +152,7 @@ const WelcomeStage = React.createClass({

Below, LBRY is controlled by users -- you -- via blockchain and decentralization.

Thank you for making content freedom possible! Here's a nickel, kid.

- this.props.setStage(null)} onConfirmed={() => { this.props.setStage(null) }} /> + { this.onRewardClaim(event) }} onRewardFailure={() => this.props.setStage(null)} onConfirmed={() => { this.props.setStage(null) }} />
: @@ -156,11 +168,13 @@ const WelcomeStage = React.createClass({ ); } -}); +} +WelcomeStage.propTypes = { + endAuth: React.PropTypes.func, +}; - -const ErrorStage = React.createClass({ - render: function() { +class ErrorStage extends React.Component { + render() { return (

An error was encountered that we cannot continue from.

@@ -170,29 +184,32 @@ const ErrorStage = React.createClass({
); } -}); +} -const PendingStage = React.createClass({ - render: function() { +class PendingStage extends React.Component { + render() { return (

Preparing for first access

); } -}); +} -const CodeRequiredStage = React.createClass({ - _balanceSubscribeId: null, - getInitialState: function() { - return { +class CodeRequiredStage extends React.Component { + constructor(props) { + super(props); + + this._balanceSubscribeId = nullp + + this.state = { balance: 0, address: getLocal('wallet_address') - } - }, + }; + } - componentWillMount: function() { + componentWillMount() { this._balanceSubscribeId = lbry.balanceSubscribe((balance) => { this.setState({ balance: balance @@ -205,13 +222,15 @@ const CodeRequiredStage = React.createClass({ this.setState({ address: address }); }); } - }, - componentWillUnmount: function() { + } + + componentWillUnmount() { if (this._balanceSubscribeId) { lbry.balanceUnsubscribe(this._balanceSubscribeId) } - }, - render: function() { + } + + render() { const disabled = this.state.balance < 1; return (
@@ -234,31 +253,36 @@ const CodeRequiredStage = React.createClass({
); } -}); +} -export const AuthOverlay = React.createClass({ - _stages: { - pending: PendingStage, - error: ErrorStage, - nocode: CodeRequiredStage, - email: SubmitEmailStage, - confirm: ConfirmEmailStage, - welcome: WelcomeStage - }, - getInitialState: function() { - return { +export class AuthOverlay extends React.Component { + constructor(props) { + super(props); + + this._stages = { + pending: PendingStage, + error: ErrorStage, + nocode: CodeRequiredStage, + email: SubmitEmailStage, + confirm: ConfirmEmailStage, + welcome: WelcomeStage + } + + this.state = { stage: "pending", stageProps: {} }; - }, - setStage: function(stage, stageProps = {}) { + } + + setStage(stage, stageProps = {}) { this.setState({ stage: stage, stageProps: stageProps }) - }, - componentWillMount: function() { + } + + componentWillMount() { lbryio.authenticate().then((user) => { if (!user.HasVerifiedEmail) { if (getLocal('auth_bypassed')) { @@ -284,8 +308,9 @@ export const AuthOverlay = React.createClass({ } })); }) - }, - render: function() { + } + + render() { if (!this.state.stage) { return null; } @@ -294,9 +319,9 @@ export const AuthOverlay = React.createClass({ this.state.stage != "welcome" ?

LBRY Early Access

- + { this.setStage(stage, stageProps) }} />
: - + { this.setStage(stage, stageProps) }} {...this.state.stageProps} /> ); } -}); \ No newline at end of file +} \ No newline at end of file diff --git a/ui/js/component/common.js b/ui/js/component/common.js index aac91004a..fc37c280a 100644 --- a/ui/js/component/common.js +++ b/ui/js/component/common.js @@ -2,65 +2,69 @@ import React from 'react'; import lbry from '../lbry.js'; //component/icon.js -export let Icon = React.createClass({ - propTypes: { +export class Icon extends React.Component { + static propTypes = { icon: React.PropTypes.string.isRequired, className: React.PropTypes.string, fixed: React.PropTypes.bool, - }, - render: function() { + } + + static defaultProps = { + lines: null + } + + render() { const {fixed, className, ...other} = this.props; const spanClassName = ('icon ' + ('fixed' in this.props ? 'icon-fixed-width ' : '') + this.props.icon + ' ' + (this.props.className || '')); return } -}); +} -export let TruncatedText = React.createClass({ - propTypes: { - lines: React.PropTypes.number - }, - getDefaultProps: function() { - return { - lines: null, - } - }, - render: function() { +export class TruncatedText extends React.Component { + static propTypes = { + lines: React.PropTypes.number, + } + + render() { return {this.props.children}; } -}); +} -export let BusyMessage = React.createClass({ - propTypes: { - message: React.PropTypes.string - }, - render: function() { +export class BusyMessage extends React.Component { + static propTypes = { + message: React.PropTypes.string, + } + + render() { return {this.props.message} } -}); +} -export let CurrencySymbol = React.createClass({ - render: function() { return LBC; } -}); +export class CurrencySymbol extends React.Component { + render() { + return LBC; + } +} -export let CreditAmount = React.createClass({ - propTypes: { +export class CreditAmount extends React.Component { + static propTypes = { amount: React.PropTypes.number.isRequired, precision: React.PropTypes.number, isEstimate: React.PropTypes.bool, label: React.PropTypes.bool, showFree: React.PropTypes.bool, look: React.PropTypes.oneOf(['indicator', 'plain']), - }, - getDefaultProps: function() { - return { - precision: 1, - label: true, - showFree: false, - look: 'indicator', - } - }, - render: function() { + } + + static defaultProps = { + precision: 1, + label: true, + showFree: false, + look: 'indicator', + } + + render() { const formattedAmount = lbry.formatCredits(this.props.amount, this.props.precision); let amountText; if (this.props.showFree && parseFloat(formattedAmount) == 0) { @@ -80,45 +84,56 @@ export let CreditAmount = React.createClass({ ); } -}); +} -var addressStyle = { +let addressStyle = { fontFamily: '"Consolas", "Lucida Console", "Adobe Source Code Pro", monospace', }; -export let Address = React.createClass({ - _inputElem: null, - propTypes: { +export class Address extends React.Component { + static propTypes = { address: React.PropTypes.string, - }, - render: function() { + } + + constructor(props) { + super(props); + + this._inputElem = null; + } + + render() { return ( { this._inputElem = input; }} onFocus={() => { this._inputElem.select(); }} style={addressStyle} readOnly="readonly" value={this.props.address}> ); } -}); +} -export let Thumbnail = React.createClass({ - _defaultImageUri: lbry.imagePath('default-thumb.svg'), - _maxLoadTime: 10000, - _isMounted: false, - - propTypes: { +export class Thumbnail extends React.Component { + static propTypes = { src: React.PropTypes.string, - }, - handleError: function() { + } + + handleError() { if (this.state.imageUrl != this._defaultImageUri) { this.setState({ imageUri: this._defaultImageUri, }); } - }, - getInitialState: function() { - return { + } + + constructor(props) { + super(props); + + this._defaultImageUri = lbry.imagePath('default-thumb.svg') + this._maxLoadTime = 10000 + this._isMounted = false + + this.state = { imageUri: this.props.src || this._defaultImageUri, }; - }, - componentDidMount: function() { + } + + componentDidMount() { this._isMounted = true; setTimeout(() => { if (this._isMounted && !this.refs.img.complete) { @@ -127,14 +142,16 @@ export let Thumbnail = React.createClass({ }); } }, this._maxLoadTime); - }, - componentWillUnmount: function() { + } + + componentWillUnmount() { this._isMounted = false; - }, - render: function() { + } + + render() { const className = this.props.className ? this.props.className : '', otherProps = Object.assign({}, this.props) delete otherProps.className; - return - }, -}); + return { this.handleError() }} {...otherProps} className={className} src={this.state.imageUri} /> + } +} diff --git a/ui/js/component/fileActions/view.jsx b/ui/js/component/fileActions/view.jsx index c1e9d6e3c..44eb4ade3 100644 --- a/ui/js/component/fileActions/view.jsx +++ b/ui/js/component/fileActions/view.jsx @@ -118,7 +118,7 @@ class FileActions extends React.Component { openModal('confirmRemove')} label="Remove..." /> : '' } + contentLabel="Confirm Purchase" onConfirmed={this.onAffirmPurchase.bind(this)} onAborted={this.closeModal.bind(this)}> This will purchase {title} for credits. field, e.g.