Skip to content
Open

done #48

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
110 changes: 88 additions & 22 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,104 @@
/* App.css */

/* Basic reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
padding: 20px;
}

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

.App-logo {
height: 40vmin;
pointer-events: none;
/* Heading */
h1 {
font-size: 2.5rem;
color: #333;
margin-bottom: 20px;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
/* Table styling */
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
th, td {
padding: 12px;
text-align: center;
border-bottom: 1px solid #ddd;
}

th {
background-color: #4CAF50;
color: white;
font-weight: bold;
}

.App-link {
color: #61dafb;
tr:hover {
background-color: #f1f1f1;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
/* Image styling */
img {
border-radius: 50%;
width: 50px;
height: 50px;
object-fit: cover;
}

/* Button styling */
button {
padding: 10px 20px;
margin: 10px;
border: none;
border-radius: 5px;
background-color: #4CAF50;
color: white;
cursor: pointer;
transition: background-color 0.3s ease;
}

button:hover {
background-color: #45a049;
}

button:active {
background-color: #3e8e41;
}

/* Trophy icon styling */
.trophy {
font-size: 1.5rem;
color: gold;
}

/* Responsive design */
@media (max-width: 768px) {
table {
font-size: 0.9rem;
}
to {
transform: rotate(360deg);

.App {
padding: 10px;
}

button {
font-size: 0.9rem;
padding: 8px;
}
}
91 changes: 75 additions & 16 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,82 @@
import logo from './logo.svg';
import './App.css';
import React, { useState } from "react";
import contactsData from "./contacts.json";
import "./App.css";

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

// addong a random contact from the remaining contacts
const addRandomContact = () => {
const remainingContacts = contactsData.filter(
(contact) => !contacts.includes(contact)
);
if (remainingContacts.length === 0) return;
const randomContact =
remainingContacts[Math.floor(Math.random() * remainingContacts.length)];
setContacts([...contacts, randomContact]);
};

// sort contacts by name
const sortByName = () => {
const sortedByName = [...contacts].sort((a, b) =>
a.name.localeCompare(b.name)
);
setContacts(sortedByName);
};

//sort contacts by popularity
const sortByPopularity = () => {
const sortedByPopularity = [...contacts].sort(
(a, b) => b.popularity - a.popularity
);
setContacts(sortedByPopularity);
};

// delete a contact
const deleteContact = (contactId) => {
const updatedContacts = contacts.filter((contact) => contact.id !== contactId);
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>OpenContacts</h1>

{/* Buttons */}
<button onClick={addRandomContact}>Add Random Contact</button>
<button onClick={sortByName}>Sort by Name</button>
<button onClick={sortByPopularity}>Sort by Popularity</button>

{/* Contacts Table */}
<table>
<thead>
<tr>
<th>Picture</th>
<th>Name</th>
<th>Popularity</th>
<th>Won an Oscar</th>
<th>Won an Emmy</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{contacts.map((contact) => (
<tr key={contact.id}>
<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>
<button onClick={() => deleteContact(contact.id)}>Delete</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
);
}
Expand Down