From 599a39ae1757d7ccf40a754e09cfdfc0c92f0533 Mon Sep 17 00:00:00 2001 From: juliacanas Date: Tue, 5 Nov 2019 21:31:25 +0100 Subject: [PATCH] done --- src/App.css | 45 ++++++++++++++++++++++++++ src/App.js | 92 +++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 121 insertions(+), 16 deletions(-) diff --git a/src/App.css b/src/App.css index b41d297ca..ad41354fd 100755 --- a/src/App.css +++ b/src/App.css @@ -31,3 +31,48 @@ transform: rotate(360deg); } } + + +.table { + margin: 20px auto; + border-spacing: 0; +} + +.btn { + border: 0; + margin: 20px 10px; + padding: 10px 50px; + background-color: rgb(216, 181, 24); + border-radius: 50px; + font-weight: bold; + cursor: pointer; +} + +.btn:hover { + color: white; +} + +th { + padding: 10px 0; + border-bottom: 2px solid rgb(216, 181, 24); +} + +td { + padding: 10px 50px; + border-bottom: 1px solid rgb(197, 163, 14); +} + +.btn-delete { + border: 0; + border: 2px solid rgb(197, 163, 14); + background-color: white; + border-radius: 50px; + padding: 10px 20px; + font-weight: bold; + cursor: pointer; +} + +.btn-delete:hover{ + background-color: rgb(197, 163, 14); + color: white; +} diff --git a/src/App.js b/src/App.js index 7e261ca47..65d4c3046 100755 --- a/src/App.js +++ b/src/App.js @@ -1,28 +1,88 @@ import React, { Component } from 'react'; -import logo from './logo.svg'; import './App.css'; +import contacts from './data/contacts.json' class App extends Component { - render() { + state = { + constactsList: contacts.slice(0, 5) + } + + + + randomContact = () => { + const copy = [...this.state.constactsList]; + let newContact = contacts[Math.floor(Math.random() * (contacts.length))]; + copy.unshift(newContact); + this.setState({ + constactsList: copy + }) + }; + + sortByName = () => { + const sortCopy = [...this.state.constactsList]; + const newArr = sortCopy.sort((a, b) => { + return a.nameb.name? 1:0; + }) + + this.setState({ + constactsList: newArr + }) + } + + sortByPopularity = () => { + const sortPop = [...this.state.constactsList]; + const orderPop = sortPop.sort((a, b) => { + return a.popularity < b.popularity ? -1 : a.popularity > b.popularity ? 1 : 0; + }) + + this.setState({ + constactsList: orderPop + }) + } + + deleteContact = (index) => { + const copyContact = [...this.state.constactsList]; + copyContact.splice(index, 1); + this.setState({ + constactsList: copyContact + }) + } + + render() { return (
-
- logo -

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

- - Learn React - -
+

IronContacts

+ + + + + + + + + + + + + + { + this.state.constactsList.map((oneContact, index) => { + return + + + + + + }) + } + +
PictureNamePopularityAction

{oneContact.name}

{oneContact.popularity}

); } } export default App; + + +