diff --git a/src/App.js b/src/App.js
index 3784575..cc42754 100644
--- a/src/App.js
+++ b/src/App.js
@@ -1,23 +1,46 @@
-import logo from './logo.svg';
-import './App.css';
+import React, { useState } from "react";
+import contacts from "./contacts.json";
+import ContactTable from "./components/ContactTable";
+import Buttons from "./components/Buttons";
function App() {
+ const [contactList, setContactList] = useState(contacts.slice(0, 5));
+
+ function addRandomContact() {
+ const remainingContacts = contacts.filter(
+ (contact) => !contactList.includes(contact)
+ );
+ if (remainingContacts.length > 0) {
+ const randomContact =
+ remainingContacts[Math.floor(Math.random() * remainingContacts.length)];
+ setContactList([...contactList, randomContact]);
+ }
+ }
+
+ function sortByName() {
+ const sorted = [...contactList].sort((a, b) => a.name.localeCompare(b.name));
+ setContactList(sorted);
+ }
+
+ function sortByPopularity() {
+ const sorted = [...contactList].sort((a, b) => b.popularity - a.popularity);
+ setContactList(sorted);
+ }
+
+ function deleteContact(id) {
+ const filteredContacts = contactList.filter((contact) => contact.id !== id);
+ setContactList(filteredContacts);
+ }
+
return (
-
-
+
+
IronContacts
+
+
);
}
diff --git a/src/components/Buttons.js b/src/components/Buttons.js
new file mode 100644
index 0000000..4a6edf5
--- /dev/null
+++ b/src/components/Buttons.js
@@ -0,0 +1,55 @@
+import React from "react";
+
+function Buttons({ onAddRandom, onSortByName, onSortByPopularity }) {
+ return (
+
+
+
+
+
+ );
+}
+
+export default Buttons;
diff --git a/src/components/ContactRow.js b/src/components/ContactRow.js
new file mode 100644
index 0000000..8fddd24
--- /dev/null
+++ b/src/components/ContactRow.js
@@ -0,0 +1,37 @@
+import React from "react";
+
+function ContactRow({ contact, onDelete }) {
+ return (
+
+
+
+ |
+ {contact.name} |
+ {contact.popularity.toFixed(2)} |
+ {contact.wonOscar ? "🏆" : ""} |
+ {contact.wonEmmy ? "🏆" : ""} |
+
+
+ |
+
+ );
+}
+
+export default ContactRow;
diff --git a/src/components/ContactTable.js b/src/components/ContactTable.js
new file mode 100644
index 0000000..a851063
--- /dev/null
+++ b/src/components/ContactTable.js
@@ -0,0 +1,38 @@
+import React from "react";
+import ContactRow from "./ContactRow";
+
+function ContactTable({ contacts, onDelete }) {
+ return (
+
+
+
+ |
+ Picture
+ |
+
+ Name
+ |
+
+ Popularity
+ |
+
+ Won an Oscar
+ |
+
+ Won an Emmy
+ |
+
+ Actions
+ |
+
+
+
+ {contacts.map((contact) => (
+
+ ))}
+
+
+ );
+}
+
+export default ContactTable;
diff --git a/src/index.css b/src/index.css
index ec2585e..e69de29 100644
--- a/src/index.css
+++ b/src/index.css
@@ -1,13 +0,0 @@
-body {
- margin: 0;
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
- 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
- sans-serif;
- -webkit-font-smoothing: antialiased;
- -moz-osx-font-smoothing: grayscale;
-}
-
-code {
- font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
- monospace;
-}