Skip to content
This repository has been archived by the owner on Oct 12, 2021. It is now read-only.

Commit

Permalink
Refactored login flow. Promise reject bubbles up to the main app.
Browse files Browse the repository at this point in the history
  • Loading branch information
astrotars committed Nov 6, 2016
1 parent 0e281c0 commit 5e22d9c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
4 changes: 1 addition & 3 deletions assets/js/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ export const init = () => dispatch => dispatch(Topics.load())
]).then(data => Promise.resolve([...data])), err => {
return Promise.reject(err)
})
).catch(err => {
Promise.reject(err)
})
).catch(err => Promise.reject(err))

export const reload = () => dispatch => {
return Promise.all([
Expand Down
3 changes: 2 additions & 1 deletion assets/js/actions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import * as TopicActions from 'actions/Topics'
export const ME = 'USER_ME'
export const me = () => dispatch => {

if (!localStorage.getItem('token')) return Promise.reject(new Error('No JWT Token'))
if (!localStorage.getItem('token'))
return Promise.reject(new Error('No JWT Token'))

return dispatch({
type: ME,
Expand Down
40 changes: 18 additions & 22 deletions assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,23 @@ const isReady = (nextState, replace, callback) => {
})
}

new Promise(() => {

const renderApp = () =>
render((
<Provider store={store}>
<Router history={history}>
<Route path="/app/getting-started" component={GetStarted} onEnter={isReady} />
<Route path="/app" component={App} onEnter={isReady}>
<Route path="personalization-feed" component={Home}/>
<Route path="subscriptions" component={Subscriptions}>
<IndexRoute component={SubscriptionLanding} />
<Route path=":id" component={SubscriptionFeed} />
</Route>
const renderApp = () =>
render((
<Provider store={store}>
<Router history={history}>
<Route path="/app/getting-started" component={GetStarted} onEnter={isReady} />
<Route path="/app" component={App} onEnter={isReady}>
<Route path="personalization-feed" component={Home}/>
<Route path="subscriptions" component={Subscriptions}>
<IndexRoute component={SubscriptionLanding} />
<Route path=":id" component={SubscriptionFeed} />
</Route>
</Router>
</Provider>
), document.getElementById('root'))

loading.then(
() => renderApp(),
() => renderApp()
)
</Route>
</Router>
</Provider>
), document.getElementById('root'))

}).catch(e => console.warn('err:', e))
loading.then(
() => renderApp(),
() => renderApp()
)

0 comments on commit 5e22d9c

Please sign in to comment.