Skip to content
This repository was archived by the owner on Jan 6, 2019. It is now read-only.

Commit 55c85b4

Browse files
author
Didier Franc
committed
Add react-code-splitting + some cleanup
1 parent 00feeab commit 55c85b4

File tree

14 files changed

+86
-61
lines changed

14 files changed

+86
-61
lines changed

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"babel-core": "^6.22.1",
3030
"babel-eslint": "^7.0.0",
3131
"babel-jest": "^18.0.0",
32-
"babel-loader": "^6.2.9",
32+
"babel-loader": "^6.2.10",
3333
"babel-plugin-styled-components": "0.0.3-0",
3434
"babel-plugin-transform-runtime": "^6.22.0",
3535
"babel-preset-es2015": "^6.22.0",
@@ -45,14 +45,15 @@
4545
"html-webpack-plugin": "^2.24.1",
4646
"jest": "^18.0.0",
4747
"react-test-renderer": "^15.4.1",
48-
"serve": "^3.2.2",
49-
"webpack": "2.2.0",
50-
"webpack-dev-server": "2.2.0-rc.0"
48+
"serve": "3.2.2",
49+
"webpack": "^2.2.1",
50+
"webpack-dev-server": "^2.3.0"
5151
},
5252
"dependencies": {
5353
"lodash": "^4.17.4",
5454
"offline-plugin": "^4.5.5",
5555
"react": "^15.4.1",
56+
"react-code-splitting": "^1.0.3",
5657
"react-dom": "^15.4.1",
5758
"react-redux": "^5.0.2",
5859
"react-router-dom": "4.0.0-beta.3",

src/actions/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { actionTypes as types, urls } from '../constants'
2-
import { getToken, post } from '../helpers'
2+
import { post } from '../helpers'
33

44
export const signup = ({ email, password }) => (dispatch) => {
55
dispatch({ type: types.SIGNUP_REQUEST })
@@ -23,12 +23,10 @@ export const login = ({ email, password }) => (dispatch) => {
2323
})
2424
}
2525

26-
export const loginWithToken = () => (dispatch) => {
27-
const token = getToken()
28-
if (!token) {
29-
dispatch({ type: types.LOGIN_FAILURE })
30-
return
31-
}
26+
export const loginWithToken = () => (dispatch, getState) => {
27+
const token = getState().user.token
28+
29+
if (typeof token === 'undefined') return
3230

3331
dispatch({ type: types.LOGIN_REQUEST })
3432
post({

src/components/App.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react'
2+
import { connect } from 'react-redux'
3+
import { Route, Redirect } from 'react-router-dom'
4+
import Async from 'react-code-splitting'
5+
6+
import Login from './Auth/Login'
7+
import Signup from './Auth/Signup'
8+
import Header from './Header'
9+
import { Body } from './Styled'
10+
11+
const Home = () => <Async load={import('./Home')} />
12+
13+
const App = ({ user }) => (
14+
<Body>
15+
<Header />
16+
{user.token ? <Route path="/" component={Home} /> : <Redirect to="/login" />}
17+
<Route path="/signup" component={Signup} />
18+
<Route path="/login" component={Login} />
19+
</Body>
20+
)
21+
22+
App.propTypes = {
23+
user: React.PropTypes.shape({}).isRequired,
24+
}
25+
26+
export default connect(state => ({ user: state.user }))(App)

src/components/Form.js renamed to src/components/Auth/Form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22

3-
import { TextField, Submit } from './Styled'
3+
import { TextField, Submit } from '../Styled'
44

55
const Form = ({ onSubmit }) => (
66
<form onSubmit={onSubmit}>

src/components/Login.js renamed to src/components/Auth/Login.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import React from 'react'
22
import { connect } from 'react-redux'
33
import { Redirect } from 'react-router-dom'
44

5-
import { login } from '../actions'
5+
import { login } from '../../actions'
66

7-
import { FormTitle, FooterLink } from './Styled'
7+
import { FormTitle, FooterLink } from '../Styled'
88
import Form from './Form'
99

1010
const Login = ({ user, login }) => {

src/components/Signup.js renamed to src/components/Auth/Signup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import React from 'react'
22
import { connect } from 'react-redux'
33
import { Redirect } from 'react-router-dom'
44

5-
import { signup } from '../actions'
5+
import { signup } from '../../actions'
66

7-
import { FormTitle, FooterLink } from './Styled'
7+
import { FormTitle, FooterLink } from '../Styled'
88
import Form from './Form'
99

1010
const Signup = ({ user, signup }) => {

src/components/Github.js renamed to src/components/Header/Github.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22

3-
import { GithubButton, GithubCount, GithubLink } from './Styled'
3+
import { GithubButton, GithubCount, GithubLink } from '../Styled'
44

55
class Github extends React.Component {
66
state = {

src/components/Header.js renamed to src/components/Header/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22

3-
import { Title } from './Styled'
3+
import { Title } from '../Styled'
44
import Github from './Github'
55

66
const Header = () => (

0 commit comments

Comments
 (0)