From 5e4e720b1db2553bcd283d4a11f1ace15fe4854e Mon Sep 17 00:00:00 2001 From: Marc Benaiges Date: Tue, 19 Mar 2019 20:13:25 +0100 Subject: [PATCH] done without CSS --- src/App.css | 28 +++++++++++++ src/App.js | 82 +++++++++++++++++++++++++++++++-------- src/components/Contact.js | 17 ++++++++ src/components/Header.js | 16 ++++++++ 4 files changed, 127 insertions(+), 16 deletions(-) create mode 100644 src/components/Contact.js create mode 100644 src/components/Header.js diff --git a/src/App.css b/src/App.css index b41d297ca..30113697a 100755 --- a/src/App.css +++ b/src/App.css @@ -31,3 +31,31 @@ transform: rotate(360deg); } } + +img { + width: 100px; + height: 150px; +} + +.container { + display: flex; + flex-direction: column; +} + +h1 { + text-align: center; +} +.titles { + display: flex; + justify-content: space-around; + margin-left:15%; + margin-right: 15%; +} + +ul { + margin-left:15%; + margin-right: 15%; + padding: 0; + display: flex; + justify-content: space-around; +} \ No newline at end of file diff --git a/src/App.js b/src/App.js index 7e261ca47..f5d2c1abb 100755 --- a/src/App.js +++ b/src/App.js @@ -1,26 +1,76 @@ import React, { Component } from 'react'; -import logo from './logo.svg'; import './App.css'; +import contacts from './data/contacts.json' +import Contact from './components/Contact' +import Header from './components/Header' + + class App extends Component { + + state = { + contactsArray: contacts.slice(0, 5) + } + + addRandom = () => { + const randomContact = contacts[Math.floor(Math.random() * contacts.length)]; + this.setState({ + contactsArray: [...this.state.contactsArray, randomContact] + }) + } + + sortByName = () => { + this.setState({ + contactsArray: this.state.contactsArray.sort(function (a, b) { + if (a.name < b.name) { return -1; } + if (a.name > b.name) { return 1; } + return 0; + }) + }) + } + + sortByPopularity = () => { + this.setState({ + contactsArray: this.state.contactsArray.sort(function (a, b) { + return b.popularity - a.popularity; + }) + }) + } + + deleteContact = (contact) => { + let { contactsArray } = this.state + contactsArray.splice(contact, 1) + this.setState({ + contactsArray + }) + } + + renderList() { + return this.state.contactsArray.map((contact, index) => { + return + + }) + } render() { return ( -
-
- logo -

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

- - Learn React - -
+
+

IronContacts

+ + + +
+
+ {this.renderList()} +
+ ); } } diff --git a/src/components/Contact.js b/src/components/Contact.js new file mode 100644 index 000000000..67caeb9fe --- /dev/null +++ b/src/components/Contact.js @@ -0,0 +1,17 @@ +import React, { Component } from 'react'; + +class Contact extends Component { + render() { + const { pictureUrl, name, popularity, deleteHandler, index } = this.props; + return ( +
    + img +

    {name}

    +

    {popularity}

    + +
+ ); + } +} + +export default Contact; \ No newline at end of file diff --git a/src/components/Header.js b/src/components/Header.js new file mode 100644 index 000000000..97cbd88cf --- /dev/null +++ b/src/components/Header.js @@ -0,0 +1,16 @@ +import React, { Component } from 'react'; + +class Header extends Component { + render() { + return ( +
+

Picture

+

Name

+

Popularity

+

Action

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