{name}
+{popularity}
+ +diff --git a/src/App.js b/src/App.js index 7e261ca47..18d0d9c7a 100755 --- a/src/App.js +++ b/src/App.js @@ -1,25 +1,73 @@ import React, { Component } from 'react'; -import logo from './logo.svg'; import './App.css'; +import contacts from './data/contacts.json' +import Card from './Components/Card' +import AddRandomButon from './Components/AddRandomButton' + class App extends Component { + + state = { + contacts: contacts.slice(0, 5) + } + + handleClickRandom = () => { + const index = Math.floor(Math.random() * contacts.length); + const randomContact = contacts[index] + this.setState({ + contacts: [...this.state.contacts, randomContact] + }) + } + + handleClickSortByName = () => { + const nameArray = this.state.contacts.sort((a, b) => { + return a.name.localeCompare(b.name); + }) + this.setState({ + contacts: nameArray, + }) + } + + handleClickSortByPopularity = () => { + const popuArray = this.state.contacts.sort((a, b) => { + return b.popularity - a.popularity; + }) + this.setState({ + contacts: popuArray, + }) + } + + handleClickDeleted = (index) => { + const { contacts } = this.state; + contacts.splice(index, 1); + this.setState({ + contacts + }) + } + render() { return (
- Edit src/App.js and save to reload.
-
{name}
+{popularity}
+ +