Client: redux setup
This commit is contained in:
0
mpwo_client/src/actions/index.js
Normal file
0
mpwo_client/src/actions/index.js
Normal file
@ -1,8 +0,0 @@
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
|
||||
import App from './components/App'
|
||||
import registerServiceWorker from './registerServiceWorker'
|
||||
|
||||
ReactDOM.render(<App />, document.getElementById('root'))
|
||||
registerServiceWorker()
|
@ -1 +1,33 @@
|
||||
require('./client.jsx')
|
||||
/* eslint-disable react/jsx-filename-extension */
|
||||
import { createBrowserHistory } from 'history'
|
||||
import React from 'react'
|
||||
import ReactDOM from 'react-dom'
|
||||
import { Provider } from 'react-redux'
|
||||
import { routerMiddleware } from 'react-router-redux'
|
||||
import { applyMiddleware, createStore, compose } from 'redux'
|
||||
import thunk from 'redux-thunk'
|
||||
|
||||
import App from './components/App'
|
||||
import registerServiceWorker from './registerServiceWorker'
|
||||
import reducers from './reducers'
|
||||
|
||||
|
||||
export const history = createBrowserHistory()
|
||||
|
||||
export const rootNode = document.getElementById('root')
|
||||
|
||||
export const store = createStore(
|
||||
reducers,
|
||||
window.__STATE__, // Server state
|
||||
(window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose)(
|
||||
applyMiddleware(routerMiddleware(history), thunk)
|
||||
)
|
||||
)
|
||||
|
||||
ReactDOM.render(
|
||||
<Provider store={store} history={history}>
|
||||
<App />
|
||||
</Provider>,
|
||||
rootNode
|
||||
)
|
||||
registerServiceWorker()
|
||||
|
9
mpwo_client/src/reducers/index.js
Normal file
9
mpwo_client/src/reducers/index.js
Normal file
@ -0,0 +1,9 @@
|
||||
import { combineReducers } from 'redux'
|
||||
|
||||
import user from './user'
|
||||
|
||||
const reducers = combineReducers({
|
||||
user,
|
||||
})
|
||||
|
||||
export default reducers
|
21
mpwo_client/src/reducers/user.js
Normal file
21
mpwo_client/src/reducers/user.js
Normal file
@ -0,0 +1,21 @@
|
||||
const user = (state = null, action) => {
|
||||
switch (action.type) {
|
||||
case 'AUTH_ERROR':
|
||||
case 'PROFILE_ERROR':
|
||||
case 'LOGOUT':
|
||||
window.localStorage.removeItem('authToken')
|
||||
return null
|
||||
case 'PROFILE_SUCCESS':
|
||||
return {
|
||||
id: action.message.data.id,
|
||||
username: action.message.data.username,
|
||||
email: action.message.data.email,
|
||||
isAdmin: action.message.data.is_admin,
|
||||
createdAt: action.message.data.created_at,
|
||||
}
|
||||
default:
|
||||
return state
|
||||
}
|
||||
}
|
||||
|
||||
export default user
|
Reference in New Issue
Block a user