From 16939b11309ad3d829bb01eb57b5cdf4ef66b68f Mon Sep 17 00:00:00 2001 From: IanNgacha Date: Fri, 2 Aug 2024 11:18:03 +0300 Subject: [PATCH] done --- src/App.css | 78 ++++++++++++++++++++++++++++++++++----------------- src/App.js | 81 +++++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 119 insertions(+), 40 deletions(-) diff --git a/src/App.css b/src/App.css index 74b5e05..2183e93 100644 --- a/src/App.css +++ b/src/App.css @@ -1,38 +1,66 @@ +body { + font-family: Arial, sans-serif; + background-color: #f8f9fa; + margin: 0; + padding: 0; +} + .App { + max-width: 800px; + margin: 20px auto; + padding: 20px; + background-color: #fff; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); + border-radius: 5px; +} + +h1 { + color: #343a40; text-align: center; } +button { + display: inline-block; + margin: 10px; + padding: 10px 20px; + background-color: #007bff; + color: #fff; + border: none; + border-radius: 5px; + cursor: pointer; +} + +button:hover { + background-color: #0056b3; +} + +button.delete { + background-color: #dc3545; +} + +button.delete:hover { + background-color: #c82333; +} -.App-logo { - height: 40vmin; - pointer-events: none; +table { + width: 100%; + border-collapse: collapse; + margin-top: 20px; } -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } +th, td { + padding: 10px; + border: 1px solid #dee2e6; + text-align: left; } -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; +th { + background-color: #f1f1f1; } -.App-link { - color: #61dafb; +tr:nth-child(even) { + background-color: #f8f9fa; } -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } +img { + border-radius: 5px; } diff --git a/src/App.js b/src/App.js index 3784575..925b507 100644 --- a/src/App.js +++ b/src/App.js @@ -1,23 +1,74 @@ -import logo from './logo.svg'; +import { useState } from 'react'; import './App.css'; +import contacts from './contacts.json'; function App() { + const initialContacts = contacts.slice(0, 10); + + const [contactList, setContactList] = useState(initialContacts); + + const addRandomContact = () => { + const remainingContacts = contacts.filter(contact => !contactList.includes(contact)); + + if (remainingContacts.length === 0) { + alert('No mreo contacts to add!'); + return; + } + + const randomContact = remainingContacts[Math.floor(Math.random() * remainingContacts.length)]; + + setContactList([...contactList, randomContact]); + }; + + const sortByName = () => { + const sortedContacts = [...contactList].sort((a, b) => a.name.localeCompare(b.name)); + setContactList(sortedContacts); + }; + + const sortByPopularity = () => { + const sortedContacts = [...contactList].sort((a, b) => b.popularity - a.popularity); + setContactList(sortedContacts); + }; + + const deleteContact = (id) => { + const updatedContacts = contactList.filter(contact => contact.id !== id); + setContactList(updatedContacts); + } + return (
-
- logo -

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

- - Learn React - -
+

Contact List

+ + + + + + + + + + + + + + + {contactList.map(contact => ( + + + + + + + + + ))} + +
PictureNamePopularityWon an OscarWon an Emmy
+ {contact.name} + {contact.name}{contact.popularity.toFixed(2)}{contact.wonOscar ? '🏆' : ''}{contact.wonEmmy ? '🏆' : ''} + +
+
); }