Progress toward register page
This commit is contained in:
parent
b074242783
commit
98b38855a2
3 changed files with 43 additions and 13 deletions
|
@ -2,6 +2,7 @@ import React from 'react';
|
|||
import {Line} from 'rc-progress';
|
||||
|
||||
import lbry from './lbry.js';
|
||||
import RegisterPage from './page/register.js';
|
||||
import SettingsPage from './page/settings.js';
|
||||
import HelpPage from './page/help.js';
|
||||
import WatchPage from './page/watch.js';
|
||||
|
@ -40,6 +41,7 @@ var App = React.createClass({
|
|||
message: 'Error message',
|
||||
data: 'Error data',
|
||||
},
|
||||
_fullScreenPages: ['register', 'watch'],
|
||||
|
||||
_upgradeDownloadItem: null,
|
||||
_isMounted: false,
|
||||
|
@ -258,6 +260,8 @@ var App = React.createClass({
|
|||
{
|
||||
switch(this.state.viewingPage)
|
||||
{
|
||||
case 'register':
|
||||
return <RegisterPage />;
|
||||
case 'settings':
|
||||
return <SettingsPage />;
|
||||
case 'help':
|
||||
|
@ -301,7 +305,7 @@ var App = React.createClass({
|
|||
searchQuery = this.state.viewingPage == 'discover' && this.state.pageArgs ? this.state.pageArgs : '';
|
||||
|
||||
return (
|
||||
this.state.viewingPage == 'watch' ?
|
||||
this._fullScreenPages.includes(this.state.viewingPage) ?
|
||||
mainContent :
|
||||
<div id="window" className={ this.state.drawerOpen ? 'drawer-open' : 'drawer-closed' }>
|
||||
<Drawer onCloseDrawer={this.closeDrawer} viewingPage={this.state.viewingPage} />
|
||||
|
|
|
@ -2,7 +2,7 @@ const querystring = require('querystring');
|
|||
|
||||
const lbryio = {};
|
||||
|
||||
const CONNECTION_STRING = 'https://api.lbry.io/';
|
||||
const CONNECTION_STRING = 'https://apidev.lbry.tech/';
|
||||
|
||||
const mocks = {
|
||||
'reward_type.get': (name) => {
|
||||
|
@ -72,18 +72,20 @@ lbryio.call = function(resource, action, params, method='get') {
|
|||
}));
|
||||
}
|
||||
} else {
|
||||
resolve(response.result);
|
||||
resolve(response.data);
|
||||
}
|
||||
});
|
||||
|
||||
console.log('about to call xhr.open');
|
||||
xhr.open(method, CONNECTION_STRING + resource + '/' + action, true);
|
||||
|
||||
if (method == 'post') {
|
||||
if (method == 'get') {
|
||||
xhr.open('get', CONNECTION_STRING + resource + '/' + action + '?' + querystring.stringify(params), true);
|
||||
xhr.send();
|
||||
} else if (method == 'post') {
|
||||
xhr.open('post', CONNECTION_STRING + resource + '/' + action, true);
|
||||
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
xhr.send(querystring.stringify(params));
|
||||
}
|
||||
|
||||
xhr.send(querystring.stringify(params));
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import lbry from './lbry.js';
|
||||
import lbryio from './lbryio.js';
|
||||
import lighthouse from './lighthouse.js';
|
||||
import App from './app.js';
|
||||
import SplashScreen from './component/splash.js';
|
||||
|
@ -16,7 +17,7 @@ window.addEventListener('contextmenu', (event) => {
|
|||
event.preventDefault();
|
||||
});
|
||||
|
||||
var init = function() {
|
||||
let init = function() {
|
||||
window.lbry = lbry;
|
||||
window.lighthouse = lighthouse;
|
||||
|
||||
|
@ -27,8 +28,10 @@ var init = function() {
|
|||
ReactDOM.render(
|
||||
(
|
||||
<SplashScreen message="Connecting" onLoadDone={function() {
|
||||
// Redirect to the claim code page if needed. Find somewhere better for this logic
|
||||
if (!localStorage.getItem('claimCodeDone') && ['', '?', 'discover'].contains(window.location.search)) {
|
||||
// There are a couple of conditions where we want to preempt loading the app and send the user to a
|
||||
// different page. TODO: Find a better place for this logic.
|
||||
|
||||
if (!localStorage.getItem('claimCodeDone') && ['', '?', 'discover'].includes(window.location.search)) {
|
||||
lbry.getBalance((balance) => {
|
||||
if (balance <= 0) {
|
||||
window.location.href = '?claim';
|
||||
|
@ -40,9 +43,30 @@ var init = function() {
|
|||
ReactDOM.render(<App/>, canvas);
|
||||
}
|
||||
}}/>
|
||||
),
|
||||
canvas);
|
||||
), canvas);
|
||||
}
|
||||
};
|
||||
|
||||
init();
|
||||
if (localStorage.getItem('accessToken') || window.location.search == '?register') {
|
||||
// User is already registered, or on the registration page
|
||||
init();
|
||||
} else {
|
||||
// Send
|
||||
lbry.status().then(({installation_id}) => {
|
||||
installation_id += parseInt(Date.now(), 10); // temp
|
||||
installation_id += "X".repeat(96 - installation_id.length); // temp
|
||||
lbryio.call('user_install', 'exists', {app_id: installation_id}).then((userExists) => {
|
||||
if (userExists) {
|
||||
/* TODO: somehow user exists with the same installation ID, but we don't have the token recorded. What do we do here? */
|
||||
} else {
|
||||
lbryio.call('user', 'new', {
|
||||
language: 'en',
|
||||
app_id: installation_id,
|
||||
}, 'post').then(({ID}) => {
|
||||
localStorage.setItem('accessToken', ID);
|
||||
window.location = '?register';
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue