Skip to content

Commit

Permalink
connected header and navbar components to redux store to get links
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxnelson997 committed Jul 10, 2018
1 parent aa94fd1 commit 579f9cb
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
22 changes: 22 additions & 0 deletions src/components/headernavbar/header.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
import React, { Component } from 'react';

import { connect } from 'react-redux';

class Header extends Component {
render() {
return (
<div className='header'>
<img src='http://via.placeholder.com/50x50'/>
<div className='header__links'>
{
this.props.headerLinks.map((link, index) => {
return (
<a className='header__link' key={index} onClick={() => console.log('trying to switch tab')}>
{link.title}
</a>
)
})
}
</div>
</div>
)
}
}

function mapStateToProps(state) {
const{ headerLinks } = state.headerNavbar;
return {
headerLinks
}
}

Header = connect(mapStateToProps)(Header);

export default Header;
21 changes: 20 additions & 1 deletion src/components/headernavbar/navbar.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
import React, { Component } from 'react';

import { connect } from 'react-redux';

class Navbar extends Component {
render() {
return (
<div className='navbar'>

{
this.props.navbarLinks.map((link, index) => {
return (
<a className='navbar__link' key={index} onClick={() => console.log('trying to switch tab')}>
{link.title}
</a>
)
})
}
</div>
)
}
}

function mapStateToProps(state) {
const{ navbarLinks } = state.headerNavbar;
return {
navbarLinks
}
}

Navbar = connect(mapStateToProps)(Navbar);

export default Navbar;
18 changes: 16 additions & 2 deletions src/reducers/headernavbarReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,22 @@ import {
} from '../actions/types';

const INITIAL_STATE = {
headerLinks: [],
navbarLinks: []
headerLinks: [
{
title: 'yooo'
},
{
title: 'YOOO'
}
],
navbarLinks: [
{
title: 'account'
},
{
title: 'purchases'
}
]
}

export default function(state = INITIAL_STATE, action) {
Expand Down
4 changes: 2 additions & 2 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { combineReducers } from 'redux';
import { reducer as form } from 'redux-form';

import HeaderNavbar from './headernavbarReducer';
import headerNavbar from './headernavbarReducer';

const rootReducer = combineReducers({
form,
HeaderNavbar
headerNavbar
});

export default rootReducer;

0 comments on commit 579f9cb

Please sign in to comment.