retrieves config from newly created route

This commit is contained in:
James
2019-10-18 17:26:46 -04:00
15 changed files with 151 additions and 58 deletions

View File

@@ -1,6 +1,6 @@
import React from 'react';
import { PayloadIcon } from 'payload/components';
import PayloadIcon from '../PayloadIcon';
const Icon = () => {
return (

View File

@@ -3,16 +3,22 @@ import { withRouter } from 'react-router-dom';
import { connect } from 'react-redux';
import { NavLink, Link } from 'react-router-dom';
import Arrow from '../../graphics/Arrow';
import Icon from '../../graphics/Icon';
import './index.scss';
const mapState = state => ({
collections: state.common.collections
config: state.common.config
});
const Sidebar = props => {
const Icon = props.icon;
const {
collections,
routes: {
admin,
}
} = props.config;
return (
<aside className="sidebar">
@@ -21,8 +27,8 @@ const Sidebar = props => {
</Link>
<span className="uppercase-label">Collections</span>
<nav>
{props.collections && Object.keys(props.collections).map((key, i) => {
const href = `/collections/${props.collections[key].slug}`;
{collections && Object.keys(collections).map((key, i) => {
const href = `${admin}/collections/${collections[key].slug}`;
const classes = props.location.pathname.indexOf(href) > -1
? 'active'
: undefined;
@@ -30,7 +36,7 @@ const Sidebar = props => {
return (
<Link className={classes} key={i} to={href}>
<Arrow />
{props.collections[key].plural}
{collections[key].labels.plural}
</Link>
);
})}

View File

@@ -26,7 +26,9 @@ class Localizer extends Component {
this.setState({ active: !this.state.active })
render() {
const { locales } = this.props.config.localization;
let locales = [];
if (this.props.config && this.props.config.localization) locales = this.props.config.localization.locales;
if (locales.length <= 1) return null;

View File

@@ -1,5 +1,6 @@
import { Component } from 'react';
import { connect } from 'react-redux';
import api from '../../../api';
const mapDispatch = dispatch => ({
loadConfig: payload => dispatch({ type: 'LOAD_CONFIG', payload })
@@ -7,8 +8,9 @@ const mapDispatch = dispatch => ({
class LoadConfig extends Component {
componentDidMount() {
// fetch('/')
// this.props.loadConfig(config);
api.requests.get('/config').then((config) => {
this.props.loadConfig(config)
})
}
render() {

View File

@@ -23,7 +23,7 @@ class SetLocale extends Component {
setLocale = () => {
const { searchParams, config, setLocale } = this.props;
if (searchParams && config) {
if (searchParams && config.localization) {
if (searchParams.locale && config.localization.locales.indexOf(searchParams.locale) > -1) {
setLocale(searchParams.locale);
} else if (!this.state.init) {
@@ -38,7 +38,7 @@ class SetLocale extends Component {
}
componentDidUpdate(prevProps) {
if (prevProps.searchParams !== this.props.searchParams) {
if (prevProps.searchParams !== this.props.searchParams || prevProps.config !== this.props.config) {
this.setLocale();
}
}

View File

@@ -110,7 +110,6 @@ module.exports = (config) => {
filename: './index.html'
}),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin()
],
resolve: {
alias: {

View File

@@ -6,7 +6,13 @@ const defaultState = {
viewHeight: false,
stepNav: [],
locale: null,
config: null,
config: {
collections: {},
localization: {
locales: []
},
routes: {},
},
searchParams: {},
status: []
};