diff --git a/ui/js/app.js b/ui/js/app.js index 2677c0b91..d7ca70f5d 100644 --- a/ui/js/app.js +++ b/ui/js/app.js @@ -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 ; case 'settings': return ; 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 :
diff --git a/ui/js/lbryio.js b/ui/js/lbryio.js index 7271462a0..0becbf487 100644 --- a/ui/js/lbryio.js +++ b/ui/js/lbryio.js @@ -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)); }); }; diff --git a/ui/js/main.js b/ui/js/main.js index 5d397bb26..9e10b1b41 100644 --- a/ui/js/main.js +++ b/ui/js/main.js @@ -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( ( { if (balance <= 0) { window.location.href = '?claim'; @@ -40,9 +43,30 @@ var init = function() { ReactDOM.render(, 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'; + }); + } + }); + }); +}