From 98b62feb5ff30f6ff387bb5aec67ebf91bd1e12b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Tue, 19 Mar 2019 18:49:30 +0100 Subject: [PATCH] done without CSS --- src/App.js | 78 +++++++++++++++++++++++++------ src/Components/AddRandomButton.js | 13 ++++++ src/Components/Card.js | 20 ++++++++ 3 files changed, 96 insertions(+), 15 deletions(-) create mode 100644 src/Components/AddRandomButton.js create mode 100644 src/Components/Card.js 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 (
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
+

IronContacts

+ + + +
+ {this.state.contacts.map((item, index) => { + return
+ + +
+ }) + } +
); } diff --git a/src/Components/AddRandomButton.js b/src/Components/AddRandomButton.js new file mode 100644 index 000000000..860310ec9 --- /dev/null +++ b/src/Components/AddRandomButton.js @@ -0,0 +1,13 @@ +import React, { Component } from 'react'; + +class AddRandomButon extends Component { + render() { + return ( +
+ +
+ ); + } +} + +export default AddRandomButon; \ No newline at end of file diff --git a/src/Components/Card.js b/src/Components/Card.js new file mode 100644 index 000000000..578848e57 --- /dev/null +++ b/src/Components/Card.js @@ -0,0 +1,20 @@ +import React, { Component } from 'react'; + + +class Card extends Component { + render() { + const { pictureUrl, name, popularity } = this.props; + return ( +
+
+ +

{name}

+

{popularity}

+ +
+
+ ); + } +} + +export default Card; \ No newline at end of file