Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Done #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions src/components/BandInput.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
// Add BandInput component
import React, { Component } from 'react'
import React, { Component } from 'react';

class BandInput extends Component {

state = {
name: ''
}

handleOnChange(event) {
this.setState({
name: event.target.value,
});
}

handleOnSubmit(event) {
event.preventDefault();
this.props.addBand(this.state);
this.setState({
name: '',
});
}

render() {
return(
return (
<div>
Band Input
<form onSubmit={(event) => this.handleOnSubmit(event)}>
<input
type="text"
value={this.state.name}
onChange={(event) => this.handleOnChange(event)} />
<input type="submit" />
</form>
</div>
)
);
}
}
};

export default BandInput
export default BandInput;
16 changes: 16 additions & 0 deletions src/components/Bands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';

const Bands = props => {
const bands = props.bands.map((band, index) => {
return <li key={index}>{band.name}</li>;
});

return (
<div>
{bands}
</div>
);

};

export default Bands;
14 changes: 11 additions & 3 deletions src/containers/BandsContainer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import React, { Component } from 'react'
import BandInput from '../components/BandInput';
import Bands from '../components/Bands';
import { connect } from 'react-redux'

class BandsContainer extends Component {
render() {
return(
return (
<div>
BandsContainer
<BandInput addBand={this.props.addBand}/>
<Bands bands={this.props.bands}/>
</div>
)
}
}

export default BandsContainer
const mapStateToProps = ({ bands }) => ({ bands })

const mapDispatchToProps = dispatch => ({ addBand: band => dispatch({ type: "ADD_BAND", band }) })

export default connect(mapStateToProps, mapDispatchToProps)(BandsContainer)
7 changes: 6 additions & 1 deletion src/reducers/manageBand.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
export default function manageBand(state = {
bands: [],
}, action) {
return state
switch (action.type) {
case 'ADD_BAND':
return { ...state, bands: [...state.bands, action.band] }
default:
return state;
}
};