diff --git a/src/App.css b/src/App.css index 74b5e05..65d4683 100644 --- a/src/App.css +++ b/src/App.css @@ -1,38 +1,104 @@ +/* App.css */ + +/* Basic reset */ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: Arial, sans-serif; + background-color: #f5f5f5; + padding: 20px; +} + .App { text-align: center; + margin: 0 auto; + max-width: 800px; + background-color: #fff; + padding: 20px; + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); + border-radius: 10px; } -.App-logo { - height: 40vmin; - pointer-events: none; +/* Heading */ +h1 { + font-size: 2.5rem; + color: #333; + margin-bottom: 20px; } -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } +/* Table styling */ +table { + width: 100%; + border-collapse: collapse; + margin-top: 20px; } -.App-header { - background-color: #282c34; - min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); +th, td { + padding: 12px; + text-align: center; + border-bottom: 1px solid #ddd; +} + +th { + background-color: #4CAF50; color: white; + font-weight: bold; } -.App-link { - color: #61dafb; +tr:hover { + background-color: #f1f1f1; } -@keyframes App-logo-spin { - from { - transform: rotate(0deg); +/* Image styling */ +img { + border-radius: 50%; + width: 50px; + height: 50px; + object-fit: cover; +} + +/* Button styling */ +button { + padding: 10px 20px; + margin: 10px; + border: none; + border-radius: 5px; + background-color: #4CAF50; + color: white; + cursor: pointer; + transition: background-color 0.3s ease; +} + +button:hover { + background-color: #45a049; +} + +button:active { + background-color: #3e8e41; +} + +/* Trophy icon styling */ +.trophy { + font-size: 1.5rem; + color: gold; +} + +/* Responsive design */ +@media (max-width: 768px) { + table { + font-size: 0.9rem; } - to { - transform: rotate(360deg); + + .App { + padding: 10px; + } + + button { + font-size: 0.9rem; + padding: 8px; } } diff --git a/src/App.js b/src/App.js index 3784575..a66ec76 100644 --- a/src/App.js +++ b/src/App.js @@ -1,23 +1,82 @@ -import logo from './logo.svg'; -import './App.css'; +import React, { useState } from "react"; +import contactsData from "./contacts.json"; +import "./App.css"; function App() { + // the first 5 contacts + const [contacts, setContacts] = useState(contactsData.slice(0, 5)); + + // addong a random contact from the remaining contacts + const addRandomContact = () => { + const remainingContacts = contactsData.filter( + (contact) => !contacts.includes(contact) + ); + if (remainingContacts.length === 0) return; + const randomContact = + remainingContacts[Math.floor(Math.random() * remainingContacts.length)]; + setContacts([...contacts, randomContact]); + }; + + // sort contacts by name + const sortByName = () => { + const sortedByName = [...contacts].sort((a, b) => + a.name.localeCompare(b.name) + ); + setContacts(sortedByName); + }; + + //sort contacts by popularity + const sortByPopularity = () => { + const sortedByPopularity = [...contacts].sort( + (a, b) => b.popularity - a.popularity + ); + setContacts(sortedByPopularity); + }; + + // delete a contact + const deleteContact = (contactId) => { + const updatedContacts = contacts.filter((contact) => contact.id !== contactId); + setContacts(updatedContacts); + }; + return (
- Edit src/App.js and save to reload.
-
| Picture | +Name | +Popularity | +Won an Oscar | +Won an Emmy | +Actions | +
|---|---|---|---|---|---|
|
+ |
+ {contact.name} | +{contact.popularity.toFixed(2)} | +{contact.wonOscar ? "🏆" : ""} | +{contact.wonEmmy ? "🏆" : ""} | ++ + | +