Seed Support #56

Closed
ocnios wants to merge 173 commits from master into build
2 changed files with 42 additions and 24 deletions
Showing only changes of commit 3727e275c4 - Show all commits

View file

@ -88,6 +88,32 @@ var App = React.createClass({
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() {
var match, param, val, viewingPage, pageArgs,
drawerOpenRaw = sessionStorage.getItem('drawerOpen');
@ -98,9 +124,17 @@ var App = React.createClass({
modal: null,
downloadProgress: null,
downloadComplete: false,
registrationCheckComplete: null,
justRegistered: false,
});
},
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) => {
this.alertError(event.detail);
});
@ -138,6 +172,8 @@ var App = React.createClass({
});
});
}
this.updateRegistrationStatus();
},
openDrawer: function() {
sessionStorage.setItem('drawerOpen', true);
@ -297,10 +333,14 @@ var App = React.createClass({
return <DeveloperPage />;
case 'discover':
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() {
if (!this.state.registrationCheckComplete) {
return null;
}
var mainContent = this.getMainContent(),
headerLinks = this.getHeaderLinks(),
searchQuery = this.state.viewingPage == 'discover' && this.state.pageArgs ? this.state.pageArgs : '';

View file

@ -47,26 +47,4 @@ let init = function() {
}
};
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';
});
}
});
});
}
init();