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
91 changes: 53 additions & 38 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,53 @@
.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;
}
}

.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);
}
to {
transform: rotate(360deg);
}
}
.App {
text-align: center;
display: flex;
flex-direction: column;
align-items: center;
font-family: "Courier New", Courier, monospace;
font-weight: 700;
}

.single-contact img {
width: 80px;
height: auto;
border: 2px solid #ffd700;
margin: 2px;
}

table {
border-collapse: collapse;
border: 2px solid #ffd700;
margin: 20px;
}
table th {
background-color: #ffd700;
color: #ffffff;
padding: 10px 20px;
font-size: 24px;
}

h1 {
color: #ffd700;
}

.buttons button {
color: #ffffff;
background-color: #ffd700;
padding: 10px;
margin: 10px;
border-radius: 15px;
border: none;
font-family: "Courier New", Courier, monospace;
font-weight: 900;
font-size: 20px;
cursor: pointer;
}

.del-button {
padding: 10px;
border-radius: 15px;
border: none;
font-family: "Courier New", Courier, monospace;
font-weight: 900;
cursor: pointer;
}
106 changes: 81 additions & 25 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,81 @@
import logo from './logo.svg';
import './App.css';

function App() {
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>
</div>
);
}

export default App;
import './App.css';
import contactsData from "./contacts.json";
import { useState } from "react";

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

let contactList = contacts.map((contact) => (
<tr key={contact.id} className="single-contact">
<td>
<img src={contact.pictureUrl} alt={contact.name} />
</td>
<td>{contact.name}</td>
<td>{contact.popularity.toFixed(2)}</td>
<td>{contact.wonOscar ? "🏆" : "-"}</td>
<td>{contact.wonEmmy ? "🏆" : "-"}</td>
<td id={contact.id}>
<button onClick={contactDelete} className="del-button">
Delete
</button>
</td>
</tr>
));

let addRandomContact = () => {
let contactsID = contacts.map((contact) => contact.id);
let otherContacts = contactsData.filter(
(contact) => !contactsID.includes(contact.id)
);
let randomIndex = Math.floor(Math.random() * otherContacts.length);
setContacts([...contacts, otherContacts[randomIndex]]);
};

let sortByPopularity = () => {
let contactList = [...contacts];
contactList.sort((a, b) => b.popularity - a.popularity);
setContacts(contactList);
};

let sortByName = () => {
let contactList = [...contacts];
contactList.sort((a, b) => {
if (b.name > a.name) return -1;
if (b.name < a.name) return 1;
return 0;
});
setContacts(contactList);
};

function contactDelete(e) {
let cID = e.target.parentNode.id;
let contactList = contacts.filter((contact) => contact.id !== cID);
setContacts(contactList);
}
return (
<div className="App">
<h1>🌟CONTACTS🌟</h1>
<div className="buttons">
<button onClick={addRandomContact}>Add Random Contact</button>
<button onClick={sortByPopularity}>Sort by popularity</button>
<button onClick={sortByName}>Sort by name</button>
</div>
<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>{contactList}</tbody>
</table>

</div>
);
}

export default App;
16 changes: 8 additions & 8 deletions src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { render, screen } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
import { render, screen } from '@testing-library/react';
import App from './App';
test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
expect(linkElement).toBeInTheDocument();
});
Loading