Skip to content
Open

done #42

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 53 additions & 25 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,66 @@
body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
margin: 0;
padding: 0;
}

.App {
max-width: 800px;
margin: 20px auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 5px;
}

h1 {
color: #343a40;
text-align: center;
}
button {
display: inline-block;
margin: 10px;
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
cursor: pointer;
}

button:hover {
background-color: #0056b3;
}

button.delete {
background-color: #dc3545;
}

button.delete:hover {
background-color: #c82333;
}

.App-logo {
height: 40vmin;
pointer-events: none;
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
th, td {
padding: 10px;
border: 1px solid #dee2e6;
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;
th {
background-color: #f1f1f1;
}

.App-link {
color: #61dafb;
tr:nth-child(even) {
background-color: #f8f9fa;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
img {
border-radius: 5px;
}
81 changes: 66 additions & 15 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,74 @@
import logo from './logo.svg';
import { useState } from 'react';
import './App.css';
import contacts from './contacts.json';

function App() {
const initialContacts = contacts.slice(0, 10);

const [contactList, setContactList] = useState(initialContacts);

const addRandomContact = () => {
const remainingContacts = contacts.filter(contact => !contactList.includes(contact));

if (remainingContacts.length === 0) {
alert('No mreo contacts to add!');
return;
}

const randomContact = remainingContacts[Math.floor(Math.random() * remainingContacts.length)];

setContactList([...contactList, randomContact]);
};

const sortByName = () => {
const sortedContacts = [...contactList].sort((a, b) => a.name.localeCompare(b.name));
setContactList(sortedContacts);
};

const sortByPopularity = () => {
const sortedContacts = [...contactList].sort((a, b) => b.popularity - a.popularity);
setContactList(sortedContacts);
};

const deleteContact = (id) => {
const updatedContacts = contactList.filter(contact => contact.id !== id);
setContactList(updatedContacts);
}

return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<h1>Contact List</h1>
<button onClick={addRandomContact}>Add Random Contact</button>
<button onClick={sortByName}>Sort by Name</button>
<button onClick={sortByPopularity}>Sort by Popularity</button>
<table>
<thead>
<tr>
<th>Picture</th>
<th>Name</th>
<th>Popularity</th>
<th>Won an Oscar</th>
<th>Won an Emmy</th>
</tr>
</thead>
<tbody>
{contactList.map(contact => (
<tr key={contact.id}>
<td>
<img src={contact.pictureUrl} alt={contact.name} width="100" />
</td>
<td>{contact.name}</td>
<td>{contact.popularity.toFixed(2)}</td>
<td>{contact.wonOscar ? '🏆' : ''}</td>
<td>{contact.wonEmmy ? '🏆' : ''}</td>
<td>
<button className="delete" onClick={() => deleteContact(contact.id)}>Delete</button>
</td>
</tr>
))}
</tbody>
</table>

</div>
);
}
Expand Down