From b3f53a58b5c20e3288a0a2df7e16459b35b7b3ee Mon Sep 17 00:00:00 2001 From: Muhammad Irshad <85778819+Irshadmdk19@users.noreply.github.com> Date: Fri, 22 Nov 2024 20:01:04 +0530 Subject: [PATCH] Done all iterations --- src/App.js | 57 ++++++++++++++++++++++++---------- src/components/Buttons.js | 55 ++++++++++++++++++++++++++++++++ src/components/ContactRow.js | 37 ++++++++++++++++++++++ src/components/ContactTable.js | 38 +++++++++++++++++++++++ src/index.css | 13 -------- 5 files changed, 170 insertions(+), 30 deletions(-) create mode 100644 src/components/Buttons.js create mode 100644 src/components/ContactRow.js create mode 100644 src/components/ContactTable.js diff --git a/src/App.js b/src/App.js index 3784575..cc42754 100644 --- a/src/App.js +++ b/src/App.js @@ -1,23 +1,46 @@ -import logo from './logo.svg'; -import './App.css'; +import React, { useState } from "react"; +import contacts from "./contacts.json"; +import ContactTable from "./components/ContactTable"; +import Buttons from "./components/Buttons"; function App() { + const [contactList, setContactList] = useState(contacts.slice(0, 5)); + + function addRandomContact() { + const remainingContacts = contacts.filter( + (contact) => !contactList.includes(contact) + ); + if (remainingContacts.length > 0) { + const randomContact = + remainingContacts[Math.floor(Math.random() * remainingContacts.length)]; + setContactList([...contactList, randomContact]); + } + } + + function sortByName() { + const sorted = [...contactList].sort((a, b) => a.name.localeCompare(b.name)); + setContactList(sorted); + } + + function sortByPopularity() { + const sorted = [...contactList].sort((a, b) => b.popularity - a.popularity); + setContactList(sorted); + } + + function deleteContact(id) { + const filteredContacts = contactList.filter((contact) => contact.id !== id); + setContactList(filteredContacts); + } + return ( -
- Edit src/App.js and save to reload.
-
| + Picture + | ++ Name + | ++ Popularity + | ++ Won an Oscar + | ++ Won an Emmy + | ++ Actions + | +
|---|