From 0ac9aa5731fa82a68cb906d566118b2aa13ca67f Mon Sep 17 00:00:00 2001 From: Gemini Sharma Date: Sun, 11 Feb 2024 01:12:19 +0530 Subject: [PATCH] done --- src/App.css | 74 ++++++++++++++++++++++++++++++----------------- src/App.js | 68 +++++++++++++++++++++++++++++++++---------- src/contacts.json | 8 ++--- 3 files changed, 105 insertions(+), 45 deletions(-) diff --git a/src/App.css b/src/App.css index 74b5e05..36ff3de 100644 --- a/src/App.css +++ b/src/App.css @@ -1,38 +1,60 @@ -.App { +body { + font-family: Arial, sans-serif; + background-color: #f0f0f0; + margin: 0; + padding: 0; +} + +.container { + max-width: 800px; + margin: 20px auto; + padding: 20px; + background-color: #fff; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); +} + +h1 { text-align: center; + margin-bottom: 20px; +} + +button { + margin: 10px 10px 10px 10px; + padding: 8px 16px; + font-size: 16px; + background-color: #007bff; + color: #fff; + border: none; + border-radius: 4px; + cursor: pointer; +} + +button:hover { + background-color: #0056b3; } -.App-logo { - height: 40vmin; - pointer-events: none; +table { + width: 100%; + border-collapse: collapse; } -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } +table th, +table td { + padding: 10px; + border-bottom: 1px solid #ddd; + 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; +table th { + background-color: #f2f2f2; } -.App-link { - color: #61dafb; +table td img { + width: 100px; + border-radius: 50%; } -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } +.action-btn { + background-color: #dc3545; } diff --git a/src/App.js b/src/App.js index 3784575..2f1c296 100644 --- a/src/App.js +++ b/src/App.js @@ -1,23 +1,61 @@ -import logo from './logo.svg'; +// src/App.js + +import React, { useState } from 'react'; import './App.css'; +import contactsData from './contacts.json'; function App() { + const [contacts, setContacts] = useState(contactsData.slice(0, 5)); + const addRandomContact = () => { + const remainingContacts = contactsData.filter(contact => !contacts.map(c => c.id).includes(contact.id)); + const randomIndex = Math.floor(Math.random() * remainingContacts.length); + const randomContact = remainingContacts[randomIndex]; + setContacts(prevContacts => [...prevContacts, randomContact]); + }; + const sortByName = () => { + const sortedContacts = [...contacts].sort((a, b) => a.name.localeCompare(b.name)); + setContacts(sortedContacts); + }; + + const sortByPopularity = () => { + const sortedContacts = [...contacts].sort((a, b) => b.popularity - a.popularity); + setContacts(sortedContacts); + }; + + const deleteContact = (id) => { + const updatedContacts = contacts.filter(contact => contact.id !== id); + setContacts(updatedContacts); + }; + return (
-
- logo -

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

- - Learn React - -
+

Contacts List

+ + + + + + + + + + + + + + + {contacts.map((contact, index) => ( + + + + + + + + + ))} + +
PictureNamePopularityWon an OscarWon an Emmy
{contact.name}{contact.name}{contact.popularity.toFixed(2)}{contact.wonOscar ? '🏆' : null}{contact.wonEmmy ? '🏆' : null}
); } diff --git a/src/contacts.json b/src/contacts.json index f8551e5..7b8582a 100644 --- a/src/contacts.json +++ b/src/contacts.json @@ -4,7 +4,7 @@ "pictureUrl": "https://image.tmdb.org/t/p/w500/d9NkfCwczP0TjgrjpF94jF67SK8.jpg", "popularity": 11.622713, "id": "11731993-0604-4bee-80d5-67ad845d0a38", - "wonOscar": false, + "wonOscar": true, "wonEmmy": false }, { @@ -13,15 +13,15 @@ "popularity": 15.656534, "id": "7dad00f7-3949-477d-a7e2-1467fd2cfc06", "wonOscar": false, - "wonEmmy": false + "wonEmmy": true }, { "name": "Monica Bellucci", "pictureUrl": "https://image.tmdb.org/t/p/w500/qlT4904d8oi2NIs28RrgnIZDFZB.jpg", "popularity": 16.096436, "id": "0ad5e441-3084-47a1-9e9b-b917539bba71", - "wonOscar": false, - "wonEmmy": false + "wonOscar": true, + "wonEmmy": true }, { "name": "Gal Gadot",