Created
April 3, 2020 14:30
-
-
Save mannawar/a97f2e3cde2b68f4fc342fc7f621944c to your computer and use it in GitHub Desktop.
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
import React, { Component } from 'react'; | |
import { connect } from 'react-redux'; | |
import './App.css'; | |
import Link from '../Components/Link'; | |
import SearchBox from '../Components/SearchBox'; | |
import Cardlist from '../Components/Cardlist'; | |
import Scroll from '../Components/Scroll'; | |
import ErrorBoundary from '../Components/ErrorBoundary'; | |
import { setSearchField, requestRobots } from '../actions'; | |
const mapStateToProps = state => { | |
return { | |
searchField: state.searchRobots.searchField, | |
robots: state.requestRobots.robots, | |
isPending: state.requestRobots.isPending, | |
error: state.requestRobots.error | |
} | |
} | |
const mapDispatchToProps = (dispatch) => { | |
return { | |
onSearchChange: (event) => dispatch(setSearchField(event.target.value)), | |
onRequestRobots: () => dispatch(requestRobots()) | |
} | |
} | |
class App extends Component { | |
render() { | |
const { searchField, onSearchChange, robots, isPending } = this.props; | |
const filteredRobots = robots.filter(robot => { | |
return robot.name.toLowerCase().includes(searchField.toLowerCase()) | |
}) | |
return isPending ? | |
<h1>Loading</h1>: | |
( | |
<div className='tc'> | |
<h1 className='f1'>Robofriends</h1> | |
<SearchBox searchChange={onSearchChange}/> | |
<Scroll> | |
<ErrorBoundary> | |
<Cardlist robots={filteredRobots}/> | |
</ErrorBoundary> | |
</Scroll> | |
<Link /> | |
</div> | |
); | |
} | |
componentDidMount() { | |
this.props.onRequestRobots(); | |
} | |
} | |
export default connect(mapStateToProps, mapDispatchToProps)(App); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment