-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: huge rewrite to separate admin and application and separate bun…
…dles
- Loading branch information
Showing
85 changed files
with
554 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import './styles'; | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import { Provider } from 'react-redux'; | ||
import { ConnectedRouter } from 'react-router-redux'; | ||
import createHistory from 'history/createBrowserHistory'; | ||
import configureStore from '@admin/store'; | ||
import App from '@admin/containers/App'; | ||
import Loadable from 'react-loadable'; | ||
|
||
// Hydrate the redux store from server state. | ||
const initialState = window.__INITIAL_STATE__; | ||
const history = createHistory(); | ||
const store = configureStore(initialState, history); | ||
|
||
// Render the application | ||
window.main = () => { | ||
Loadable.preloadReady().then(() => { | ||
ReactDOM.hydrate( | ||
<Provider store={store}> | ||
<ConnectedRouter history={history}> | ||
<App /> | ||
</ConnectedRouter> | ||
</Provider>, | ||
document.getElementById('app') | ||
); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Header } from './Header'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import { Switch } from 'react-router-dom'; | ||
import { Container } from 'semantic-ui-react'; | ||
import { RouteWithSubRoutes } from '@shared/components/common'; | ||
import { Header } from '@admin/components/common'; | ||
import { hot } from 'react-hot-loader'; | ||
import routes from '@admin/routes'; | ||
|
||
const App = () => { | ||
return ( | ||
<Container fluid={true}> | ||
<Header /> | ||
<Switch> | ||
{routes.map(route => ( | ||
<RouteWithSubRoutes key={route.path} {...route} /> | ||
))} | ||
</Switch> | ||
</Container> | ||
); | ||
}; | ||
|
||
export default hot(module)(App); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React, { Component } from 'react'; | ||
import { Helmet } from 'react-helmet'; | ||
|
||
class AdminHomePage extends Component { | ||
render() { | ||
return ( | ||
<div> | ||
<Helmet> | ||
<title>Admin</title> | ||
</Helmet> | ||
<h1>Admin Page</h1> | ||
<p> | ||
This is the admin home page. Work is still in progress. | ||
</p> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default AdminHomePage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { Helmet } from 'react-helmet'; | ||
import { searchProducts } from '@app/actions/search'; | ||
import { ProductSearch, ProductList } from '@app/components/products'; | ||
|
||
class AdminProductsPage extends Component { | ||
static propTypes = { | ||
dispatch: PropTypes.func.isRequired, | ||
products: PropTypes.object.isRequired | ||
}; | ||
|
||
componentDidMount() { | ||
const { dispatch, products } = this.props; | ||
|
||
if (!products.isLoaded) { | ||
return dispatch(searchProducts({ query: ' ' })); | ||
} | ||
} | ||
|
||
render() { | ||
const { products, dispatch } = this.props; | ||
const title = 'Products'; | ||
|
||
return ( | ||
<div> | ||
<Helmet> | ||
<title>{title}</title> | ||
</Helmet> | ||
<h1>{title}</h1> | ||
<ProductSearch dispatch={dispatch} products={products} /> | ||
<ProductList products={products} /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = state => ({ | ||
products: state.search.products | ||
}); | ||
|
||
export default connect(mapStateToProps)(AdminProductsPage); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { combineReducers } from 'redux'; | ||
import { routerReducer } from 'react-router-redux'; | ||
|
||
import auth from '@app/reducers/auth'; | ||
import products from '@app/reducers/products'; | ||
import search from '@app/reducers/search'; | ||
|
||
const rootReducer = combineReducers({ | ||
routing: routerReducer, | ||
auth, | ||
products, | ||
search | ||
}); | ||
|
||
export default rootReducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Error from '@admin/pages/Error'; | ||
import Home from '@admin/pages/Home'; | ||
import Products from '@admin/pages/Products'; | ||
|
||
export default [ | ||
{ path: '/admin', exact: true, component: Home }, | ||
{ path: '/admin/products', exact: true, component: Products }, | ||
{ path: '*', component: Error } | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { compose, createStore, applyMiddleware } from 'redux'; | ||
import thunk from 'redux-thunk'; | ||
import rootReducer from '@admin/reducers'; | ||
import { createLogger } from 'redux-logger'; | ||
import { callAPIMiddleware } from '@middleware'; | ||
import { routerMiddleware } from 'react-router-redux'; | ||
|
||
export default function configureStore(initialState, history = null) { | ||
/* Middleware | ||
* Configure this array with the middleware that you want included | ||
*/ | ||
let middleware = [ | ||
thunk, | ||
createLogger(), | ||
callAPIMiddleware | ||
]; | ||
|
||
if (history) { | ||
middleware.push(routerMiddleware(history)); | ||
} | ||
|
||
// Add universal enhancers here | ||
let enhancers = []; | ||
|
||
const composeEnhancers = ( | ||
typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ | ||
) || compose; | ||
const enhancer = composeEnhancers(...[ | ||
applyMiddleware(...middleware), | ||
...enhancers | ||
]); | ||
|
||
// create store with enhancers, middleware, reducers, and initialState | ||
const store = createStore(rootReducer, initialState, enhancer); | ||
|
||
if (module.hot) { | ||
// Enable Webpack hot module replacement for reducers | ||
module.hot.accept('../reducers', () => { | ||
const nextRootReducer = require('../reducers').default; | ||
store.replaceReducer(nextRootReducer); | ||
}); | ||
} | ||
|
||
return store; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { compose, createStore, applyMiddleware } from 'redux'; | ||
import thunk from 'redux-thunk'; | ||
import rootReducer from '@admin/reducers'; | ||
import { callAPIMiddleware } from '@middleware'; | ||
import { routerMiddleware } from 'react-router-redux'; | ||
|
||
export default function configureStore(initialState, history = null) { | ||
/* Middleware | ||
* Configure this array with the middleware that you want included. | ||
*/ | ||
let middleware = [ thunk, callAPIMiddleware ]; | ||
|
||
if (history) { | ||
middleware.push(routerMiddleware(history)); | ||
} | ||
|
||
// Add universal enhancers here | ||
let enhancers = []; | ||
|
||
const enhancer = compose(...[ | ||
applyMiddleware(...middleware), | ||
...enhancers | ||
]); | ||
|
||
// create store with enhancers, middleware, reducers, and initialState | ||
const store = createStore(rootReducer, initialState, enhancer); | ||
|
||
return store; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import React, { Fragment, Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { connect } from 'react-redux'; | ||
import { NavLink, withRouter } from 'react-router-dom'; | ||
import { Header, Menu } from 'semantic-ui-react'; | ||
import { logout } from '@app/actions/auth'; | ||
|
||
class HeaderView extends Component { | ||
static propTypes = { | ||
auth: PropTypes.object.isRequired, | ||
dispatch: PropTypes.func.isRequired | ||
} | ||
|
||
logout = () => { | ||
const { dispatch } = this.props; | ||
|
||
dispatch(logout()); | ||
} | ||
|
||
renderUser = () => { | ||
const { auth } = this.props; | ||
|
||
if (auth.isLoggedIn) { | ||
return ( | ||
<Fragment> | ||
<Menu.Item><b>{auth.user.username}</b></Menu.Item> | ||
<Menu.Item as="a" content="Logout" onClick={this.logout} /> | ||
</Fragment> | ||
); | ||
} | ||
|
||
return ( | ||
<Fragment> | ||
<Menu.Item to="/login" as={NavLink} content="Login" /> | ||
<Menu.Item to="/signup" as={NavLink} content="Signup" /> | ||
</Fragment> | ||
); | ||
} | ||
|
||
render() { | ||
return ( | ||
<Header> | ||
<Menu size="massive"> | ||
<Menu.Item to="/" exact as={NavLink} content="Home" /> | ||
<Menu.Item to="/products" exact as={NavLink} content="Products" /> | ||
<Menu.Menu position="right"> | ||
{this.renderUser()} | ||
</Menu.Menu> | ||
</Menu> | ||
</Header> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = (state) => ({ | ||
auth: state.auth | ||
}); | ||
|
||
export default withRouter(connect(mapStateToProps)(HeaderView)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as Footer } from './Footer'; | ||
export { default as Header } from './Header'; |
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
.../components/products/ProductList/index.js → .../components/products/ProductList/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...omponents/products/ProductSearch/index.js → ...omponents/products/ProductSearch/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.