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 {Line} from 'rc-progress';
|
||||||
|
|
||||||
import lbry from './lbry.js';
|
import lbry from './lbry.js';
|
||||||
|
import RegisterPage from './page/register.js';
|
||||||
import SettingsPage from './page/settings.js';
|
import SettingsPage from './page/settings.js';
|
||||||
import HelpPage from './page/help.js';
|
import HelpPage from './page/help.js';
|
||||||
import WatchPage from './page/watch.js';
|
import WatchPage from './page/watch.js';
|
||||||
|
@ -40,6 +41,7 @@ var App = React.createClass({
|
||||||
message: 'Error message',
|
message: 'Error message',
|
||||||
data: 'Error data',
|
data: 'Error data',
|
||||||
},
|
},
|
||||||
|
_fullScreenPages: ['register', 'watch'],
|
||||||
|
|
||||||
_upgradeDownloadItem: null,
|
_upgradeDownloadItem: null,
|
||||||
_isMounted: false,
|
_isMounted: false,
|
||||||
|
@ -258,6 +260,8 @@ var App = React.createClass({
|
||||||
{
|
{
|
||||||
switch(this.state.viewingPage)
|
switch(this.state.viewingPage)
|
||||||
{
|
{
|
||||||
|
case 'register':
|
||||||
|
return <RegisterPage />;
|
||||||
case 'settings':
|
case 'settings':
|
||||||
return <SettingsPage />;
|
return <SettingsPage />;
|
||||||
case 'help':
|
case 'help':
|
||||||
|
@ -301,7 +305,7 @@ var App = React.createClass({
|
||||||
searchQuery = this.state.viewingPage == 'discover' && this.state.pageArgs ? this.state.pageArgs : '';
|
searchQuery = this.state.viewingPage == 'discover' && this.state.pageArgs ? this.state.pageArgs : '';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
this.state.viewingPage == 'watch' ?
|
this._fullScreenPages.includes(this.state.viewingPage) ?
|
||||||
mainContent :
|
mainContent :
|
||||||
<div id="window" className={ this.state.drawerOpen ? 'drawer-open' : 'drawer-closed' }>
|
<div id="window" className={ this.state.drawerOpen ? 'drawer-open' : 'drawer-closed' }>
|
||||||
<Drawer onCloseDrawer={this.closeDrawer} viewingPage={this.state.viewingPage} />
|
<Drawer onCloseDrawer={this.closeDrawer} viewingPage={this.state.viewingPage} />
|
||||||
|
|
|
@ -2,7 +2,7 @@ const querystring = require('querystring');
|
||||||
|
|
||||||
const lbryio = {};
|
const lbryio = {};
|
||||||
|
|
||||||
const CONNECTION_STRING = 'https://api.lbry.io/';
|
const CONNECTION_STRING = 'https://apidev.lbry.tech/';
|
||||||
|
|
||||||
const mocks = {
|
const mocks = {
|
||||||
'reward_type.get': (name) => {
|
'reward_type.get': (name) => {
|
||||||
|
@ -72,18 +72,20 @@ lbryio.call = function(resource, action, params, method='get') {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resolve(response.result);
|
resolve(response.data);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('about to call xhr.open');
|
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.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 React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import lbry from './lbry.js';
|
import lbry from './lbry.js';
|
||||||
|
import lbryio from './lbryio.js';
|
||||||
import lighthouse from './lighthouse.js';
|
import lighthouse from './lighthouse.js';
|
||||||
import App from './app.js';
|
import App from './app.js';
|
||||||
import SplashScreen from './component/splash.js';
|
import SplashScreen from './component/splash.js';
|
||||||
|
@ -16,7 +17,7 @@ window.addEventListener('contextmenu', (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
});
|
});
|
||||||
|
|
||||||
var init = function() {
|
let init = function() {
|
||||||
window.lbry = lbry;
|
window.lbry = lbry;
|
||||||
window.lighthouse = lighthouse;
|
window.lighthouse = lighthouse;
|
||||||
|
|
||||||
|
@ -27,8 +28,10 @@ var init = function() {
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
(
|
(
|
||||||
<SplashScreen message="Connecting" onLoadDone={function() {
|
<SplashScreen message="Connecting" onLoadDone={function() {
|
||||||
// Redirect to the claim code page if needed. Find somewhere better for this logic
|
// There are a couple of conditions where we want to preempt loading the app and send the user to a
|
||||||
if (!localStorage.getItem('claimCodeDone') && ['', '?', 'discover'].contains(window.location.search)) {
|
// different page. TODO: Find a better place for this logic.
|
||||||
|
|
||||||
|
if (!localStorage.getItem('claimCodeDone') && ['', '?', 'discover'].includes(window.location.search)) {
|
||||||
lbry.getBalance((balance) => {
|
lbry.getBalance((balance) => {
|
||||||
if (balance <= 0) {
|
if (balance <= 0) {
|
||||||
window.location.href = '?claim';
|
window.location.href = '?claim';
|
||||||
|
@ -40,9 +43,30 @@ var init = function() {
|
||||||
ReactDOM.render(<App/>, canvas);
|
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