From f22b22b584c3bd4740073ac002f1440954769235 Mon Sep 17 00:00:00 2001 From: jaysonalfie Date: Thu, 25 Jan 2024 00:01:45 +0300 Subject: [PATCH 1/2] Jayson internship-done --- src/App.css | 34 +++++++++++++++++ src/App.js | 107 ++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 126 insertions(+), 15 deletions(-) diff --git a/src/App.css b/src/App.css index 74b5e05..45885f1 100644 --- a/src/App.css +++ b/src/App.css @@ -36,3 +36,37 @@ transform: rotate(360deg); } } +img{ + width: 200px; + height:300px +} +table{ + width: 1100px; + margin-inline: auto; + border-collapse: collapse; + margin-top: 20px; +} +th, td{ + font-size: 25px; + text-align: center; + vertical-align: bottom; + border-bottom: 1px solid #282c34; + padding:8px; +} +tr:nth-child(even){ +background-color: chocolate; +} +tr:hover{ + background-color:chartreuse; +} +button{ + background-color: #04AA6D; + font-size: 16px; + padding: 14px 40px; + border-radius: 8px; + transition-duration: 0.4s; + margin-right: 30px; +} +button:hover{ + color: white; +} \ No newline at end of file diff --git a/src/App.js b/src/App.js index 3784575..f237397 100644 --- a/src/App.js +++ b/src/App.js @@ -1,23 +1,100 @@ -import logo from './logo.svg'; +import React, { useState } from 'react'; import './App.css'; +import contacts from './contacts.json'; function App() { + const [contactsList, setContactsList] = useState(contacts.slice(0, 7)); + const remainingContacts = contacts.slice(5); + + //function to add a random contact + const addRandomContact = () => { + if (remainingContacts.length === 0) { + // Handling the case where there are no more remaining contacts + alert('No more remaining contacts'); + return; + } + + // Randomly selecting a contact from the remaining contacts + const randomIndex = Math.floor(Math.random() * remainingContacts.length); + const randomContact = remainingContacts[randomIndex]; + + // Adding the selected contact to the array in the state + setContactsList((prevContacts) => [...prevContacts, randomContact]); + + // Removing the selected contact from the remaining contacts + const updatedRemainingContacts = [ + ...remainingContacts.slice(0, randomIndex), + ...remainingContacts.slice(randomIndex + 1), + ]; + + // Updating the state of remaining contacts if needed + // setRemainingContacts(updatedRemainingContacts); + }; + //function to sort by name alphabetically + const sortByName = () => { + //create new array and updating state with sorted array + const sortedByName = [...contactsList].sort((a,b)=> a.name.localeCompare(b.name)); + setContactsList(sortedByName); + } + //fucntion to sort by popularity in descending order + const sortByPopularity = () => { + //create new array and updating state with sorted array + const sortedByPopularity = [...contactsList].sort((a,b)=> b.popularity - a.popularity); + setContactsList(sortedByPopularity); + } + + const removeContact = (id) =>{ + //finding the index of the contact with the given ID + const contactIndex =contactsList.findIndex((contact) => contact.id === id); + + if (contactIndex !== -1){ + //creating a new array exluding the contact to be removed + const updateContactsList = [ + ...contactsList.slice(0, contactIndex), + ...contactsList.slice(contactIndex + 1) + ]; + + //updating the stae variable with the modified new array of contacts list + setContactsList(updateContactsList) + } + + + } + return (
-
- logo -

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

- - Learn React - -
+

Contacts List

+ + + + + + + + + + + + + + + + {contactsList.map((contact, index) => ( + + + + + + + + + ))} + +
PictureNamePopularityWon an OscarWon an EmmyAction
+ {contact.name} + {contact.name}{contact.popularity}{contact.wonOscar ? '🏆' : ''}{contact.wonEmmy ? '🏆' : ''} + +
); } From ddd1ca090ad0cc2b8fbf7e2a2726222c2f12a9df Mon Sep 17 00:00:00 2001 From: jaysonalfie Date: Thu, 25 Jan 2024 00:11:32 +0300 Subject: [PATCH 2/2] done --- src/App.css | 1 + 1 file changed, 1 insertion(+) diff --git a/src/App.css b/src/App.css index 45885f1..bd53550 100644 --- a/src/App.css +++ b/src/App.css @@ -1,5 +1,6 @@ .App { text-align: center; + } .App-logo {