moves collections to redux
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
export { default as App } from './components/App';
|
||||
|
||||
// Redux
|
||||
export { default as LoadGlobals } from './components/LoadGlobals';
|
||||
|
||||
// Controls
|
||||
export { default as Button } from './components/controls/Button';
|
||||
|
||||
@@ -56,9 +53,9 @@ export { default as Label } from './components/type/Label';
|
||||
|
||||
// Utilities
|
||||
export { default as MeasureWindow } from './components/utilities/MeasureWindow';
|
||||
export { default as LoadCollections } from './components/utilities/LoadCollections';
|
||||
export { default as MeasureScroll } from './components/utilities/MeasureScroll';
|
||||
export { default as SetStepNav } from './components/utilities/SetStepNav';
|
||||
export { default as LoadGlobals } from './components/utilities/LoadGlobals';
|
||||
|
||||
// Views
|
||||
export { default as Dashboard } from './components/views/Dashboard';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { BrowserRouter as Router } from 'react-router-dom';
|
||||
import { Provider } from 'react-redux';
|
||||
import { LoadGlobals, MeasureWindow, MeasureScroll, LoadCollections } from 'payload/components';
|
||||
import { LoadGlobals, MeasureWindow, MeasureScroll } from 'payload/components';
|
||||
|
||||
import '../scss/app.scss';
|
||||
|
||||
@@ -12,7 +12,6 @@ const App = props => {
|
||||
<LoadGlobals config={props.config} collections={props.collections} />
|
||||
<Router>
|
||||
<React.Fragment>
|
||||
<LoadCollections collections={props.collections} />
|
||||
<MeasureScroll />
|
||||
<MeasureWindow />
|
||||
{props.children}
|
||||
|
||||
@@ -6,8 +6,8 @@ import { Arrow, Label } from 'payload/components';
|
||||
|
||||
import './index.scss';
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
collections: state.collections.all
|
||||
const mapState = state => ({
|
||||
collections: state.common.collections
|
||||
});
|
||||
|
||||
const Sidebar = props => {
|
||||
@@ -21,7 +21,7 @@ const Sidebar = props => {
|
||||
</Link>
|
||||
<Label>Collections</Label>
|
||||
<nav>
|
||||
{props.collections.map((item, i) => {
|
||||
{props.collections && props.collections.map((item, i) => {
|
||||
const href = `/collections/${item.slug}`;
|
||||
const classes = props.location.pathname.indexOf(href) > -1
|
||||
? 'active'
|
||||
@@ -44,4 +44,4 @@ const Sidebar = props => {
|
||||
);
|
||||
}
|
||||
|
||||
export default withRouter(connect(mapStateToProps)(Sidebar));
|
||||
export default withRouter(connect(mapState)(Sidebar));
|
||||
|
||||
@@ -3,12 +3,13 @@ import { connect } from 'react-redux';
|
||||
import { Switch, Route, withRouter } from 'react-router-dom';
|
||||
|
||||
const mapState = state => ({
|
||||
config: state.common.config
|
||||
config: state.common.config,
|
||||
collections: state.common.collections
|
||||
})
|
||||
|
||||
const CollectionRoutes = props => {
|
||||
|
||||
if (props.config) {
|
||||
if (props.config && props.collections) {
|
||||
return props.collections.map((collection, i) => {
|
||||
if (collection) {
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
loadCollections: data => dispatch({ type: 'LOAD_COLLECTIONS', payload: data }),
|
||||
});
|
||||
|
||||
class LoadCollections extends Component {
|
||||
|
||||
componentDidMount() {
|
||||
this.props.loadCollections(this.props.collections);
|
||||
}
|
||||
|
||||
render() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(null, mapDispatchToProps)(LoadCollections);
|
||||
21
src/components/utilities/LoadGlobals/index.js
Normal file
21
src/components/utilities/LoadGlobals/index.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Component } from 'react';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
const mapDispatch = dispatch => ({
|
||||
loadGlobals: globals => dispatch({ type: 'LOAD_GLOBALS', payload: globals })
|
||||
})
|
||||
|
||||
class LoadGlobals extends Component {
|
||||
componentDidMount() {
|
||||
this.props.loadGlobals({
|
||||
config: this.props.config,
|
||||
collections: this.props.collections
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export default connect(null, mapDispatch)(LoadGlobals);
|
||||
@@ -1,19 +0,0 @@
|
||||
const defaultState = {
|
||||
all: []
|
||||
};
|
||||
|
||||
export default (state = defaultState, action) => {
|
||||
switch (action.type) {
|
||||
case 'LOAD_COLLECTIONS':
|
||||
|
||||
return {
|
||||
...state,
|
||||
all: action.payload
|
||||
};
|
||||
|
||||
default:
|
||||
//
|
||||
}
|
||||
|
||||
return state;
|
||||
};
|
||||
@@ -7,7 +7,8 @@ const defaultState = {
|
||||
viewHeight: false,
|
||||
modalState: false,
|
||||
stepNav: [],
|
||||
config: null
|
||||
config: null,
|
||||
collections: null
|
||||
};
|
||||
|
||||
export default (state = defaultState, action) => {
|
||||
@@ -55,11 +56,12 @@ export default (state = defaultState, action) => {
|
||||
stepNav: action.payload
|
||||
};
|
||||
|
||||
case 'LOAD_CONFIG':
|
||||
case 'LOAD_GLOBALS':
|
||||
|
||||
return {
|
||||
...state,
|
||||
config: action.payload
|
||||
config: action.payload.config,
|
||||
collections: action.payload.collections
|
||||
};
|
||||
|
||||
default:
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import common from './reducers/common';
|
||||
import collections from './reducers/collections';
|
||||
|
||||
export {
|
||||
common,
|
||||
collections
|
||||
common
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user