-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing connect fn for the songDetail component
- Loading branch information
Showing
3 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
|
||
const SongDetail = (props) => { | ||
if (props.selected) { | ||
return ( | ||
<div className="ui card"> | ||
<div className="content"> | ||
<div className="header">Song Details: </div> | ||
</div> | ||
<div className="content"> | ||
<h4 className="ui sub header">Title : {props.selected.title}</h4> | ||
<div className="ui small feed"> | ||
<div className="event"> | ||
<div className="content"> | ||
<div className="summary"> | ||
An Umm-Kalthoum Song with A duration of { props.selected.duration } | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
return <div>Select A song to get its details.</div> | ||
} | ||
|
||
const mapStateToProps = state => { | ||
return { selected: state.selectedSong } | ||
} | ||
|
||
export default connect(mapStateToProps)(SongDetail); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { selectSong } from '../actions'; | ||
class SongsList extends React.Component { | ||
|
||
render () { | ||
console.log(" > render") | ||
const renderedList = this.props.songs.map(s => { | ||
return ( | ||
<div key={s.title} className="item"> | ||
<div className="right floated content"> | ||
<button | ||
onClick={() => this.props.selectSong(s)} | ||
className="ui button primary" | ||
> | ||
Select | ||
</button> | ||
</div> | ||
<div className="content"> | ||
{s.title} | ||
</div> | ||
</div> | ||
) | ||
}) | ||
return ( | ||
<div className="ui divided list"> | ||
{renderedList} | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
const mapStateToProps = state => { | ||
return { songs: state.songs }; | ||
} | ||
|
||
export default connect(mapStateToProps, { selectSong })(SongsList); |