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
11,934 changes: 11,934 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-rootcontacts": "file:",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
Expand Down
46 changes: 20 additions & 26 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,32 @@
.App {
text-align: center;
font-family: Arial, sans-serif;
padding: 20px;
}

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

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
th, td {
padding: 8px;
text-align: left;
border: 1px solid #ddd;
}

.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;
button {
padding: 5px 10px;
margin: 5px;
cursor: pointer;
}

.App-link {
color: #61dafb;
button:hover {
background-color: #f0f0f0;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
img {
width: 50px;
height: 50px;
object-fit: cover;
}
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';

// Table component to display individual contact details
const Table = ({ pictureUrl, name, popularity, wonOscar, wonEmmy, onDelete }) => {
return (
<tr>
<td><img src={pictureUrl} alt={name} /></td>
<td>{name}</td>
<td>{popularity}</td>
<td>{wonOscar ? <span>&#127942;</span> : " "}</td>
<td>{wonEmmy ? <span>&#127942;</span> : " "}</td>
<td><button onClick={onDelete}>Delete</button></td>
</tr>
);
}

function App() {
const [contactsList, setContactsList] = useState(contacts.slice(0, 5));

// Function to add a random contact
const addRandomContact = () => {
const remainingContacts = contacts.filter(contact => !contactsList.includes(contact));
const randomContact = remainingContacts[Math.floor(Math.random() * remainingContacts.length)];
setContactsList(prevContacts => [...prevContacts, randomContact]);
};

// Function to delete a contact
const deleteContact = (id) => {
setContactsList(prevContacts => prevContacts.filter(contact => contact.id !== id));
};

// Function to sort contacts by name
const sortByName = () => {
const sortedContacts = [...contactsList].sort((a, b) => a.name.localeCompare(b.name));
setContactsList(sortedContacts);
};

// Function to sort contacts by popularity
const sortByPopularity = () => {
const sortedContacts = [...contactsList].sort((a, b) => b.popularity - a.popularity);
setContactsList(sortedContacts);
};

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>
<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 Oscar</th>
<th>Won Emmy</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{contactsList.map(contact => (
<Table
key={contact.id}
{...contact}
onDelete={() => deleteContact(contact.id)}
/>
))}
</tbody>
</table>
</div>
);
}
Expand Down
8 changes: 0 additions & 8 deletions src/App.test.js

This file was deleted.

5 changes: 0 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
Expand All @@ -11,7 +10,3 @@ root.render(
</React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
13 changes: 0 additions & 13 deletions src/reportWebVitals.js

This file was deleted.