From 6732072a14548852595cf38541ff6caab6f83609 Mon Sep 17 00:00:00 2001 From: JdeJ Date: Sat, 23 Mar 2019 14:25:40 +0100 Subject: [PATCH] donde --- src/App.js | 67 +++++++++++++++++++++++++++-------- src/components/addContact.js | 40 +++++++++++++++++++++ src/components/contactList.js | 38 ++++++++++++++++++++ 3 files changed, 131 insertions(+), 14 deletions(-) create mode 100644 src/components/addContact.js create mode 100644 src/components/contactList.js diff --git a/src/App.js b/src/App.js index 7e261ca47..12888514a 100755 --- a/src/App.js +++ b/src/App.js @@ -2,24 +2,63 @@ import React, { Component } from 'react'; import logo from './logo.svg'; import './App.css'; +import allContacts from './data/contacts.json'; +import ContactList from './components/contactList'; +import AddContact from './components/addContact'; + class App extends Component { + + state = { + contacts: allContacts.slice(0,5), + } + + handleClick = (e) => { + const random = allContacts[Math.floor(Math.random()*allContacts.length)]; + this.setState({ + contacts: [...this.state.contacts, random], + }); + } + + handleSort = (e) => { + const sorted = this.state.contacts.sort(function (a, b) { + if (a[e.target.id] > b[e.target.id]) { + return 1; + } + if (a[e.target.id] < b[e.target.id]) { + return -1; + } + // a must be equal to b + return 0; + }); + this.setState({ + contacts: sorted, + }); + } + + remove = (index) => { + this.state.contacts.splice(index, 1); + this.setState({ + contacts: [...this.state.contacts], + }); + } + + add = (contact) => { + this.setState({ + contacts: [...this.state.contacts, contact], + }); + } + render() { return (
-
- logo -

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

- - Learn React - -
+

IronContacts

+ +

+ + + +

+
); } diff --git a/src/components/addContact.js b/src/components/addContact.js new file mode 100644 index 000000000..49cee73cb --- /dev/null +++ b/src/components/addContact.js @@ -0,0 +1,40 @@ +import React, { Component } from 'react' + +export default class addContact extends Component { + + state = { + name: '', + pictureUrl: '', + popularity: '', + }; + + handleAdd = () => { + this.props.new(this.state); + this.setState({ + name: '', + pictureUrl: '', + popularity: '', + }) + } + + handleInput = (e) => { + this.setState({ + [e.target.name]: e.target.value, + }) + } + + render() { + return ( +
+

New contact

+ + + + + + + +
+ ) + } +} diff --git a/src/components/contactList.js b/src/components/contactList.js new file mode 100644 index 000000000..b80860897 --- /dev/null +++ b/src/components/contactList.js @@ -0,0 +1,38 @@ +import React, { Component } from 'react'; + + +const NewTr = ({contact, remove, index}) => { + return ( + + + {contact.name} + {contact.name} + {contact.popularity} + + + + ) +} + + +export default class contactList extends Component { + render() { + return ( +
+ + + + + + + + + + {this.props.contacts.map((element, index) => { + return + })} +
PictureNamePopularityAction
+
+ ) + } +}