diff --git a/src/App.js b/src/App.js index 7e261ca47..0bafc6ddd 100755 --- a/src/App.js +++ b/src/App.js @@ -1,25 +1,112 @@ import React, { Component } from 'react'; -import logo from './logo.svg'; import './App.css'; +import ContactCard from './components/ContactCard'; +import contacts from './data/contacts.json'; +import Button from './components/Button'; + +let firstFiveContacts = contacts.slice(0,5); +let randomContact = contacts[Math.floor(Math.random() * contacts.length)]; class App extends Component { + state = { + contacts: firstFiveContacts, + } + + clickAddRandomContact = () => { + const { contacts } = this.state; + let random = Math.floor(Math.random() * (contacts.length)); + // console.log(`obtengo el random: ${random}`); + this.setState({ + contacts: [contacts[random], ...contacts] + }) + } + + addContact = () => { + const { contacts } = this.state; + this.setState({ + contacts: [randomContact, ...contacts] + }) + } + + sortByNames = () => { + const { contacts } = this.state; + const sortedContacts = contacts.sort( + (a,b) => { + if(a.name < b.name){ + return -1; + } else if(a.name > b.name){ + return 1; + } else{ + return 0; + } + }) + + this.setState({ + contacts: sortedContacts + }) + }; + + sortByPopularity = () => { + const { contacts } = this.state; + const sortedByPop = contacts.sort((a,b) => a.popularity - b.popularity ); + + this.setState({ + contacts: sortedByPop + }) + }; + + removeContact = (contact) => { + const {contacts} = this.state; + + // remove the contact + /* exemple with arrow functions + let tasks = [ + {'name': 'write', 'duration': 60}, + {'name': 'workout', 'duration': 120}, + {'name': 'duolingo', 'duration': 170} + ]; + let dificultad = tasks.filter((task) => task.duration >= 120); + */ + + const contactFiltered = contacts.filter((contactActtual) => contactActtual.name !== contact.name); + console.log("contactos filtrados", contactFiltered); + + this.setState({ + contacts: contactFiltered + }) + }; + render() { return (
-
- logo -

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

- - Learn React - -
+

IronContacts

+ + + + + + + +
+ {this.state.contacts.map((card, index) =>{ + return ( + + ); + })} +
+
); } diff --git a/src/components/Button.js b/src/components/Button.js new file mode 100644 index 000000000..3ac884d03 --- /dev/null +++ b/src/components/Button.js @@ -0,0 +1,11 @@ +import React from 'react'; + +const Button = ({ children, myProp }) => { + return ( + + ); +}; + +export default Button; \ No newline at end of file diff --git a/src/components/ContactCard.js b/src/components/ContactCard.js new file mode 100644 index 000000000..f37479d0d --- /dev/null +++ b/src/components/ContactCard.js @@ -0,0 +1,34 @@ +import React from 'react'; +import Button from './Button'; + +function ContactCard(props){ + + const {name, pictureUrl, popularity, remove} = props; + console.log({remove}) + return ( +
+ + + + + + + + + + + + + +
PictureNamePopularityAction
+ actor + {name}{popularity} + +
+
+ ); +} + +export default ContactCard; \ No newline at end of file diff --git a/src/index.css b/src/index.css index cee5f348f..60c727071 100755 --- a/src/index.css +++ b/src/index.css @@ -12,3 +12,31 @@ code { font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace; } + +table{ + display: table; + font-size: 2em; + width: 50%; + margin: auto; + margin: 0 auto; + text-align: left; +} + +td{ + width: 33%; +} + +img{ + max-width: 150px; +} + +button{ + color: #0099CC; + background: transparent; + border: 2px solid #0099CC; + border-radius: 6px; + padding: 15px; + margin: 10px; + font-size: 1rem; + +} \ No newline at end of file