diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..2ba986f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://localhost:8080", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/src/App.css b/src/App.css index 74b5e05..da200ce 100644 --- a/src/App.css +++ b/src/App.css @@ -1,38 +1,92 @@ .App { text-align: center; + } .App-logo { - height: 40vmin; - pointer-events: none; -} -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; + transform: rotate(360deg); } -} - -.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); + .container { + max-width: 800px; + margin: 0 auto; + padding: 20px; + text-align: center; } - to { - transform: rotate(360deg); + + /* Button styles */ + button { + margin: 5px; + padding: 10px 20px; + background-color: #007bff; + color: white; + border: none; + border-radius: 5px; + cursor: pointer; } -} + + button:hover { + background-color: #0056b3; + } + + /* Table styles */ + .contacts-table { + width: 100%; + border-collapse: collapse; + margin-top: 20px; + } + + .contacts-table th, .contacts-table td { + padding: 10px; + border-bottom: 1px solid #ccc; + } + + .contacts-table th { + background-color: #f2f2f2; + font-weight: bold; + } + + .contacts-table img { + max-width: 50px; + border-radius: 50%; + } + + + .contacts-table { + width: 100%; + border-collapse: collapse; + margin-top: 20px; + } + + .contacts-table th, + .contacts-table td { + padding: 10px; + border-bottom: 1px solid #ccc; + } + + .contacts-table th { + background-color: #f2f2f2; + font-weight: bold; + } + + .contacts-table img { + max-width: 50px; + border-radius: 50%; + } + + + .contacts-table .delete-btn { + margin: 0; + padding: 5px 10px; + background-color: #dc3545; + color: white; + border: none; + border-radius: 3px; + cursor: pointer; + transition: background-color 0.3s; + } + + .contacts-table .delete-btn:hover { + background-color: #c82333; + } \ No newline at end of file diff --git a/src/App.js b/src/App.js index 3784575..7bcc793 100644 --- a/src/App.js +++ b/src/App.js @@ -1,7 +1,54 @@ import logo from './logo.svg'; import './App.css'; +import React, { useState } from 'react'; +import contactsData from './contacts.json'; function App() { + const initialContacts = contactsData.slice(0, 5); + const initialRemainingContacts = contactsData.slice(5); + + const [displayedContacts, setDisplayedContacts] = useState(initialContacts); + const [remainingContacts, setRemainingContacts] = useState(initialRemainingContacts); + + const addRandomContact = () => { + if (remainingContacts.length > 0) { + const randomIndex = Math.floor(Math.random() * remainingContacts.length); + const randomContact = remainingContacts[randomIndex]; + + setDisplayedContacts((prevContacts) => [...prevContacts, randomContact]); + + const updatedRemainingContacts = remainingContacts.filter( + (contact) => contact.id !== randomContact.id + ); + + setRemainingContacts(updatedRemainingContacts); + } else { + console.log('No more contacts to add!'); + } + }; + + const deleteContact = (id) => { + const updatedDisplayedContacts = displayedContacts.filter((contact) => contact.id !== id); + setDisplayedContacts(updatedDisplayedContacts); + + const deletedContact = displayedContacts.find((contact) => contact.id === id); + if (deletedContact) { + setRemainingContacts((prevRemaining) => [...prevRemaining, deletedContact]); + } + }; + + const sortByName = () => { + const sortedContacts = [...displayedContacts].sort((a, b) => + a.name.localeCompare(b.name) + ); + setDisplayedContacts(sortedContacts); + }; + + const sortByPopularity = () => { + const sortedContacts = [...displayedContacts].sort((a, b) => b.popularity - a.popularity); + setDisplayedContacts(sortedContacts); + }; + return (
| Picture | +Name | +Popularity | +Won an Oscar | +Won an Emmy | +Action | +
|---|---|---|---|---|---|
|
+ |
+ {contact.name} | +{contact.popularity.toFixed(2)} | +{contact.wonOscar ? '🏆' : '-'} | +{contact.wonEmmy ? '🏆' : '-'} | ++ + | +