Skip to content
Open
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
74 changes: 48 additions & 26 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -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;
}
68 changes: 53 additions & 15 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -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 (
<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>Contacts 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 >
{contacts.map((contact, index) => (
<tr key={index}>
<td><img src={contact.pictureUrl} alt={contact.name} width={100} /></td>
<td>{contact.name}</td>
<td>{contact.popularity.toFixed(2)}</td>
<td>{contact.wonOscar ? '🏆' : null}</td>
<td>{contact.wonEmmy ? '🏆' : null}</td>
<td><button onClick={() => deleteContact(contact.id)}>Delete</button></td>
</tr>
))}
</tbody>
</table>
</div>
);
}
Expand Down
8 changes: 4 additions & 4 deletions src/contacts.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
{
Expand All @@ -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",
Expand Down