Skip to content

Commit

Permalink
Connects tabs component to Redux route
Browse files Browse the repository at this point in the history
  • Loading branch information
DalerAsrorov committed Oct 13, 2017
1 parent e29c993 commit 434d5cb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
12 changes: 0 additions & 12 deletions src/components/Login/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,6 @@ const styles = theme => ({
});

class Login extends PureComponent {
// componentDidMount() {
// fetch('/userstatus', {
// method: 'GET'
// })
// .then(response => response.json())
// .then(({ isAuthenticated }) => {
// if (isAuthenticated) {
// window.location
// }
// });
// }

static propTypes = {
classes: PropTypes.object
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/Main/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Route } from 'react-router';
import Nav from '../Nav';
import PublicPlaylists from '../PublicPlaylists';
import Nav from '../../containers/Nav';
import MyPlaylists from '../../containers/MyPlaylists';

const Main = ({ match: { url } }) => {
Expand Down
10 changes: 8 additions & 2 deletions src/components/Nav/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import PersonPin from 'material-ui-icons/PersonPin';
import Public from 'material-ui-icons/Public';
import FlashOn from 'material-ui-icons/FlashOn';

const ROUTE_INDEX_MAP = {
0: '/app',
1: '/app/public'
};

const styles = theme => ({
root: {
width: '100%',
Expand All @@ -18,12 +23,13 @@ const styles = theme => ({

class Nav extends PureComponent {
static propTypes = {
classes: PropTypes.object
classes: PropTypes.object,
navigateTo: PropTypes.func.isRequired
};

_handleChange = (event, value) => {
event.preventDefault();
console.log(event, value);
this.props.navigateTo(ROUTE_INDEX_MAP[value]);
};

render() {
Expand Down
5 changes: 5 additions & 0 deletions src/connectPage.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { connect } from 'react-redux';
import { push } from 'react-router-redux';
import { fetchMyPlaylists } from './actions';

const mapStateToProps = state => ({
Expand All @@ -8,6 +9,10 @@ const mapStateToProps = state => ({
export const mapDispatchToProps = dispatch => ({
fetchMyPlaylists() {
dispatch(fetchMyPlaylists());
},

navigateTo(path) {
dispatch(push(path));
}
});

Expand Down
4 changes: 4 additions & 0 deletions src/containers/Nav.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { connectStream } from '../connectPage';
import Nav from '../components/Nav';

export default connectStream(Nav);

0 comments on commit 434d5cb

Please sign in to comment.