Moved logic to mark selected server to parent component in order to affect all children compo0nents on the same route

This commit is contained in:
Alejandro Celaya
2018-07-24 19:17:01 +02:00
parent 3eaa66435a
commit 78ba7c75ff
6 changed files with 72 additions and 41 deletions

View File

@@ -1,33 +1,41 @@
import React from 'react';
import { Route, Switch } from 'react-router-dom';
import { connect } from 'react-redux';
import { selectServer } from '../servers/reducers/selectedServer';
import CreateShortUrl from '../short-urls/CreateShortUrl';
import ShortUrls from '../short-urls/ShortUrls';
import AsideMenu from './AsideMenu';
export function MenuLayout(props) {
return (
<div className="row">
<AsideMenu {...props} />
<div className="col-md-10 offset-md-2 col-sm-9 offset-sm-3">
<Switch>
<Route
exact
path="/server/:serverId/list-short-urls/:page"
component={ShortUrls}
/>
<Route
exact
path="/server/:serverId/create-short-url"
component={CreateShortUrl}
/>
</Switch>
export class MenuLayout extends React.Component {
componentDidMount() {
const { serverId } = this.props.match.params;
this.props.selectServer(serverId);
}
render() {
return (
<div className="row">
<AsideMenu {...this.props} />
<div className="col-md-10 offset-md-2 col-sm-9 offset-sm-3">
<Switch>
<Route
exact
path="/server/:serverId/list-short-urls/:page"
component={ShortUrls}
/>
<Route
exact
path="/server/:serverId/create-short-url"
component={CreateShortUrl}
/>
</Switch>
</div>
</div>
</div>
);
);
}
}
export default connect(state => ({
selectedServer: state.selectedServer,
shortUrlsListParams: state.shortUrlsListParams,
}))(MenuLayout);
}), { selectServer })(MenuLayout);