diff --git a/src/App.css b/src/App.css index 74b5e05..38e646f 100644 --- a/src/App.css +++ b/src/App.css @@ -1,38 +1,84 @@ .App { + display: flex; + flex-flow: column nowrap; + text-align: center; } -.App-logo { - height: 40vmin; - pointer-events: none; +.appHeader { + display: flex; + justify-content: space-between; + + /* background-color: rgb(189, 189, 189); */ + /* background-color: rgb(242, 176, 190); */ + /* background-color: teal; */ + /* background-color: rgb(225, 173, 255); */ + background-image: url('./images/background.jpg'); + + padding-top: 25px; + padding-bottom: 25px; + box-sizing: border-box; +} + +.appHeading { + color: whitesmoke; + font-family: 'Baskerville', fantasy; + font-size: 50px; + + margin: 10px; +} + +.buttons { + padding-top: 12.5px; +} + +.button { + margin: 10px; } -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } +.contactsTable { + display: flex; + flex-flow: column nowrap; + justify-content: space-around; + + margin-top: 10px; } -.App-header { - background-color: #282c34; - min-height: 100vh; +.aRow { display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); + flex-flow: row nowrap; + justify-content: space-between; +} + +.tableHeader { + /* background-color: rgb(89, 0, 255); */ + /* background-color: rgb(15, 222, 233); */ + background-color: rgb(23, 159, 159); color: white; + + font-size: 20px; +} + + +.contactColumn { + margin: 5px; + width: 1300px; + text-align: center; +} + +.headerColumn { + width: 1300px; + text-align: center; + border: solid white 2px; } -.App-link { - color: #61dafb; +.contactRow { + margin: 5px; } -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } +.picture { + width: 50px; + height: auto; + + border-radius: 50%; } diff --git a/src/App.js b/src/App.js index 3784575..eaba1ce 100644 --- a/src/App.js +++ b/src/App.js @@ -1,23 +1,106 @@ +import { useState } from 'react'; + import logo from './logo.svg'; import './App.css'; +import contactsFile from './contacts.json'; function App() { + + const [contacts, setContacts] = useState(contactsFile.slice(0, 5)); + + function wonOscar(contact) { + const oscar = contact.wonOscar; + + return oscar; + } + + function wonEmmy(contact) { + const emmy = contact.wonEmmy; + + return emmy; + } + + function addRandomContact() { + //select a random contact from the remaining contacts + const randomIndex = Math.floor((Math.random()) * (contactsFile.length - 5)); + const randomContact = [...contactsFile.slice(5)][randomIndex]; + + setContacts((prevContacts) => [...prevContacts, randomContact]); + } + + function sortByPopularity() { + const sortedArrayByPopularity = contacts.toSorted((a, b) => { + return b.popularity - a.popularity; + }); + setContacts(sortedArrayByPopularity); + } + + function sortByName() { + const sortedArrayByName = contacts.toSorted((a, b) => { + return a.name.localeCompare(b.name); + }); + setContacts(sortedArrayByName); + } + + function deleteContact(event) { + const key = event.target.getAttribute('data-key'); + console.log(key); + let filteredArray = contacts.filter((contact) => { + return contact.id !== key; + }); + setContacts(filteredArray); + } + return (
-
- logo -

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

- - Learn React - -
+
+

Contact Manager

+
+ + + +
+
+ + + + + + + + + + + + + + + {contacts.map((contact) => { + return ( + +
+
+
+
+
+ +
+
+ +
+
+ + + ) + })} + +
PictureNamePopularityOscarEmmyAction
{contact.name}{contact.popularity} + {wonOscar(contact) ? '🏆' : ''} + + {wonEmmy(contact) ? '🏆' : ''} + + +
); }