From da3e1500e201b8519b313f94be5ba475e95bf9e4 Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 20 Dec 2025 10:00:42 +0000 Subject: [PATCH 1/2] complete App.js --- src/App.js | 103 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 87 insertions(+), 16 deletions(-) diff --git a/src/App.js b/src/App.js index 3784575..714dc5a 100644 --- a/src/App.js +++ b/src/App.js @@ -1,23 +1,94 @@ -import logo from './logo.svg'; -import './App.css'; +// src/App.js + +import "./App.css"; +import { useState } from "react"; +import contactsData from "./contacts.json"; function App() { + // Iteration 1: store first 5 contacts in state + const [contacts, setContacts] = useState(contactsData.slice(0, 5)); + + // Iteration 3: add random contact + const addRandomContact = () => { + const remainingContacts = contactsData.filter( + (contact) => !contacts.some((c) => c.id === contact.id) + ); + + if (remainingContacts.length === 0) return; + + const randomIndex = Math.floor(Math.random() * remainingContacts.length); + const randomContact = remainingContacts[randomIndex]; + + setContacts([...contacts, randomContact]); + }; + + // Iteration 4: sort by name + const sortByName = () => { + const sorted = [...contacts].sort((a, b) => + a.name.localeCompare(b.name) + ); + setContacts(sorted); + }; + + // Iteration 4: sort by popularity + const sortByPopularity = () => { + const sorted = [...contacts].sort( + (a, b) => b.popularity - a.popularity + ); + setContacts(sorted); + }; + + // Iteration 5: delete contact + const deleteContact = (id) => { + const filtered = contacts.filter((contact) => contact.id !== id); + setContacts(filtered); + }; + return (
-
- logo -

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

- - Learn React - -
+

IronContacts

+ +
+ + + +
+ + + + + + + + + + + + + + + {contacts.map((contact) => ( + + + + + + + + + ))} + +
PictureNamePopularityWon an OscarWon an EmmyActions
+ {contact.name} + {contact.name}{contact.popularity.toFixed(2)}{contact.wonOscar && "🏆"}{contact.wonEmmy && "🏆"} + +
); } From 6227587fd67312f82d52301817c25935ce0aba8c Mon Sep 17 00:00:00 2001 From: SiyaM108 Date: Sat, 20 Dec 2025 10:02:40 +0000 Subject: [PATCH 2/2] complete App.css --- src/App.css | 40 +++++++++++----------------------------- 1 file changed, 11 insertions(+), 29 deletions(-) diff --git a/src/App.css b/src/App.css index 74b5e05..14b5af9 100644 --- a/src/App.css +++ b/src/App.css @@ -1,38 +1,20 @@ .App { text-align: center; + padding: 20px; } -.App-logo { - height: 40vmin; - pointer-events: none; +table { + margin: 0 auto; + border-collapse: collapse; } -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } +th, td { + border: 1px solid #ccc; + padding: 10px; } -.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; -} - -.App-link { - color: #61dafb; -} - -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } +button { + margin: 5px; + padding: 6px 12px; + cursor: pointer; }