diff --git a/src/App.css b/src/App.css index b41d297ca..9bfc759c3 100755 --- a/src/App.css +++ b/src/App.css @@ -31,3 +31,9 @@ transform: rotate(360deg); } } + +img { + width: auto; + max-height: 300px; + border-radius: 5px; +} diff --git a/src/App.js b/src/App.js index 7e261ca47..e03a985a7 100755 --- a/src/App.js +++ b/src/App.js @@ -1,25 +1,13 @@ import React, { Component } from 'react'; -import logo from './logo.svg'; import './App.css'; +import ContactList from './components/ContactList'; class App extends Component { render() { return (
-
- logo -

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

- - Learn React - -
+

IronContacts

+
); } diff --git a/src/components/Contact.js b/src/components/Contact.js new file mode 100644 index 000000000..04d67f34c --- /dev/null +++ b/src/components/Contact.js @@ -0,0 +1,14 @@ +import React from 'react' + +const Contact = ({ pictureUrl, name, popularity, deleteContact }) => { + return ( + + {name} + {name} + {popularity} + + + ) +} + +export default Contact; diff --git a/src/components/ContactList.js b/src/components/ContactList.js new file mode 100644 index 000000000..84b3d8a2c --- /dev/null +++ b/src/components/ContactList.js @@ -0,0 +1,83 @@ +import React, { + Component +} from 'react'; +import contactsJSON from '../data/contacts.json'; +import Contact from './Contact'; + +export default class ContactList extends Component { + + constructor() { + super(); + this.state = { + // Start with only 5 contacts + contacts: contactsJSON.slice(0, 5) + } + } + + // Get a random contact + addRandom = () => { + let randomIndex = Math.floor((Math.random() * contactsJSON.length) + 0); + this.state.contacts.push(contactsJSON[randomIndex]); + this.setState({ + contacts: this.state.contacts + }) + } + + // Sort by name + sortName = () => { + this.setState({ + contacts: this.state.contacts.sort((a, b) => a.name.localeCompare(b.name)) + }) + } + + // Sort by popularity + sortPopularity = () => { + this.setState({ + contacts: this.state.contacts.sort((a, b) => b.popularity - a.popularity) + }) + } + + // Delete contact + deleteContact = (name) => { + let newContacts = [...this.state.contacts]; + this.setState({ + contacts: newContacts.filter((contact) => { + return contact.name !== name + }) + }) + console.log('!') + } + + render () { + return ( +
+ + + + + + + + + + + + + + { + this.state.contacts.map((contact, index) => + + ) + } + +
PictureNamePopularityAction
+
+ ) + } +}