Seed Support #56
2 changed files with 42 additions and 24 deletions
42
ui/js/app.js
42
ui/js/app.js
|
@ -88,6 +88,32 @@ var App = React.createClass({
|
||||||
pageArgs: pageArgs === undefined ? null : pageArgs
|
pageArgs: pageArgs === undefined ? null : pageArgs
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
updateRegistrationStatus: function() {
|
||||||
|
if (localStorage.getItem('accessToken')) {
|
||||||
|
this.setState({
|
||||||
|
registrationCheckComplete: true,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
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) => {
|
||||||
|
// TODO: deal with case where user exists already with the same app ID, but we have no access token.
|
||||||
|
// Possibly merge in to the existing user with the same app ID.
|
||||||
|
lbryio.call('user', 'new', {
|
||||||
|
language: 'en',
|
||||||
|
app_id: installation_id,
|
||||||
|
}, 'post').then(({ID}) => {
|
||||||
|
localStorage.setItem('accessToken', ID);
|
||||||
|
this.setState({
|
||||||
|
registrationCheckComplete: true,
|
||||||
|
justRegistered: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
var match, param, val, viewingPage, pageArgs,
|
var match, param, val, viewingPage, pageArgs,
|
||||||
drawerOpenRaw = sessionStorage.getItem('drawerOpen');
|
drawerOpenRaw = sessionStorage.getItem('drawerOpen');
|
||||||
|
@ -98,9 +124,17 @@ var App = React.createClass({
|
||||||
modal: null,
|
modal: null,
|
||||||
downloadProgress: null,
|
downloadProgress: null,
|
||||||
downloadComplete: false,
|
downloadComplete: false,
|
||||||
|
registrationCheckComplete: null,
|
||||||
|
justRegistered: false,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
|
if (!localStorage.getItem('accessToken') && window.location.search != '?discover') {
|
||||||
|
// User isn't registered but somehow made it to a page other than Discover, so send them to
|
||||||
|
// Discover to get them registered and show them the welcome screen.
|
||||||
|
window.location.search = '?discover';
|
||||||
|
}
|
||||||
|
|
||||||
document.addEventListener('unhandledError', (event) => {
|
document.addEventListener('unhandledError', (event) => {
|
||||||
this.alertError(event.detail);
|
this.alertError(event.detail);
|
||||||
});
|
});
|
||||||
|
@ -138,6 +172,8 @@ var App = React.createClass({
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.updateRegistrationStatus();
|
||||||
},
|
},
|
||||||
openDrawer: function() {
|
openDrawer: function() {
|
||||||
sessionStorage.setItem('drawerOpen', true);
|
sessionStorage.setItem('drawerOpen', true);
|
||||||
|
@ -297,10 +333,14 @@ var App = React.createClass({
|
||||||
return <DeveloperPage />;
|
return <DeveloperPage />;
|
||||||
case 'discover':
|
case 'discover':
|
||||||
default:
|
default:
|
||||||
return <DiscoverPage {... this.state.pageArgs !== null ? {query: this.state.pageArgs} : {} } />;
|
return <DiscoverPage showWelcome={this.state.justRegistered} {... this.state.pageArgs !== null ? {query: this.state.pageArgs} : {} } />;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
|
if (!this.state.registrationCheckComplete) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
var mainContent = this.getMainContent(),
|
var mainContent = this.getMainContent(),
|
||||||
headerLinks = this.getHeaderLinks(),
|
headerLinks = this.getHeaderLinks(),
|
||||||
searchQuery = this.state.viewingPage == 'discover' && this.state.pageArgs ? this.state.pageArgs : '';
|
searchQuery = this.state.viewingPage == 'discover' && this.state.pageArgs ? this.state.pageArgs : '';
|
||||||
|
|
|
@ -47,26 +47,4 @@ let init = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (localStorage.getItem('accessToken') || window.location.search == '?register') {
|
init();
|
||||||
// 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