mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Going LIte
This commit is contained in:
@@ -1,29 +1,23 @@
|
||||
import React from 'react'
|
||||
import { Provider } from 'react-redux'
|
||||
import { updateUser } from 'boost/actions'
|
||||
import { fetchCurrentUser } from 'boost/api'
|
||||
// import { updateUser } from 'boost/actions'
|
||||
import { Router, Route, IndexRoute } from 'react-router'
|
||||
import MainPage from './MainPage'
|
||||
import LoginPage from './LoginPage'
|
||||
import SignupPage from './SignupPage'
|
||||
import HomePage from './HomePage'
|
||||
import auth from 'boost/auth'
|
||||
import store, { devToolElement } from 'boost/store'
|
||||
// import auth from 'boost/auth'
|
||||
import store from 'boost/store'
|
||||
let ReactDOM = require('react-dom')
|
||||
require('../styles/main/index.styl')
|
||||
|
||||
function onlyUser (state, replaceState) {
|
||||
let currentUser = auth.user()
|
||||
if (currentUser == null) return replaceState('login', '/login')
|
||||
if (state.location.pathname === '/') return replaceState('user', '/users/' + currentUser.id)
|
||||
// let currentUser = auth.user()
|
||||
// if (currentUser == null) return replaceState('login', '/login')
|
||||
// if (state.location.pathname === '/') return replaceState('user', '/users/' + currentUser.id)
|
||||
}
|
||||
|
||||
let routes = (
|
||||
<Route path='/' component={MainPage}>
|
||||
<Route name='login' path='login' component={LoginPage}/>
|
||||
<Route name='signup' path='signup' component={SignupPage}/>
|
||||
<IndexRoute name='home' component={HomePage} onEnter={onlyUser}/>
|
||||
<Route name='user' path='/users/:userId' component={HomePage} onEnter={onlyUser}/>
|
||||
<IndexRoute name='home' component={HomePage}/>
|
||||
</Route>
|
||||
)
|
||||
|
||||
@@ -34,26 +28,25 @@ ReactDOM.render((
|
||||
<Provider store={store}>
|
||||
<Router>{routes}</Router>
|
||||
</Provider>
|
||||
{devToolElement}
|
||||
</div>
|
||||
), el, function () {
|
||||
let loadingCover = document.getElementById('loadingCover')
|
||||
loadingCover.parentNode.removeChild(loadingCover)
|
||||
|
||||
// Refresh user information
|
||||
if (auth.user() != null) {
|
||||
fetchCurrentUser()
|
||||
.then(function (res) {
|
||||
let user = res.body
|
||||
store.dispatch(updateUser(user))
|
||||
})
|
||||
.catch(function (err) {
|
||||
if (err.status === 401) {
|
||||
auth.clear()
|
||||
if (window != null) window.location.reload()
|
||||
}
|
||||
console.error(err.message)
|
||||
console.log('Fetch failed')
|
||||
})
|
||||
}
|
||||
// if (auth.user() != null) {
|
||||
// fetchCurrentUser()
|
||||
// .then(function (res) {
|
||||
// let user = res.body
|
||||
// store.dispatch(updateUser(user))
|
||||
// })
|
||||
// .catch(function (err) {
|
||||
// if (err.status === 401) {
|
||||
// auth.clear()
|
||||
// if (window != null) window.location.reload()
|
||||
// }
|
||||
// console.error(err.message)
|
||||
// console.log('Fetch failed')
|
||||
// })
|
||||
// }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user