Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contacts page w/ out extensions #89

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,26 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
38,623 changes: 9,098 additions & 29,525 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.10",
"@testing-library/react": "^11.2.6",
"@testing-library/user-event": "^12.8.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "4.0.3",
"web-vitals": "^1.1.1"
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"bootstrap": "^5.3.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.15.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
71 changes: 50 additions & 21 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,38 +1,67 @@


.App {
text-align: center;
background-color: #282c34;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
.header {
background-color: #282c34;
min-height: 100vh;
height: 8vw;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}
li {
display: inline-flex;
align-items: center;
justify-content: center;
}
li .item {
color: white;
font-size: 1.25vw;
background-color:#3f3f40;
height: 8vw;
padding-bottom: 1vw;
margin: 0.1vw;
display: inline-flex;
align-items: center;
justify-content: center;
border: solid 0.3vw white;
}
li .item-image {
object-fit: cover;
background-color: #3f3f40;
height: 8vw;
width: 8vw;
padding: 0;
margin: 0.1vw;
display: flex;
align-items: center;
border: solid 0.3vw white;
}

.inputs {
display: flex;
justify-content: center;
}

.item-contact {
color: white;
}

.App-link {
color: #61dafb;
.item-image-contact {
object-fit:cover;
border: solid white 0.2vw;
width: 10vw;
height: 10vw;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
hr {
display: block;
}

159 changes: 140 additions & 19 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,146 @@
import logo from './logo.svg';

import { Route, Routes, Link, useParams } from 'react-router-dom'
import PropTypes from 'prop-types'
import React from 'react';
import './App.css';
import 'bootstrap/dist/css/bootstrap.min.css';



const ContactsAPI = {
"contacts":[
{
"id": 12345678,
"name": "Max Blanton",
"phone-number": 1234567890,
"email": "[email protected]",
"image": "https://yt3.ggpht.com/vCrZhd5X3PDYaEVQK2c-sY4YCLR2ypfIMYI8fbfrpVfn5r9yKs7PUICwigkGBkt5nZJNMEJPEC0=s600-c-k-c0x00ffffff-no-rj-rp-mo"
}
],
"all": function() {
return this.contacts;
},

"get": function(id) {
const isContact = c => c.id === id;
return this.contacts.find(isContact);
}
};

const App = () => (
<div>
<Main />
</div>
);
const Home = () => (
<div class="App">
<h1 className="header">Home</h1>
<hr/>
<Link to="/contacts" className="btn btn-primary">Contacts</Link>
</div>
);

const Contacts = () => (
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to see some of this broken out into other component files

<div className="App">
<h2 className="header">Contact Page</h2>
<hr/>
<ul className="container">
{ContactsAPI.all().map(current => (

<li key={current.id} className="row" >

<img className="col-md-2 item-image" alt="" src={current.image}/>
<h4 className="col-md-2 item">{current.name}</h4>
<h4 className="col-md-2 item">{current["phone-number"]}</h4>
<h4 className="col-md-3 item">{current.email}</h4>
<Link className="col-md-2 btn btn-warning item" to={"/contacts/" + current.id}>View</Link>
</li>
))}
</ul>
<Link to="/contacts/new" className="btn btn-primary">Create New</Link>
</div>

);


function App() {
return (



const ContactCreate = ({ id, name, number, email, image }) => (
<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>
<h2 className="header">Create New Contact</h2>
<hr/>
<div className="inputs">
<input name="name" onChange={e => name = e.target.value} type="text" placeholder="Contact Name"/>
<input name="number" onChange={e => number = e.target.value} type="number" placeholder="Phone Number"/>
<input name="email" onChange={e => email = e.target.value} type="email" placeholder="Email"/>
<input name="image" onChange={e => image = e.target.value} alt="" type="url" placeholder="Image URL"/>
</div>
<Link to="/contacts" onClick={() => handleClick({ id, name, number, email, image })} className="btn btn-primary">+ Create New</Link>
<Link to="/contacts" className="btn btn-danger">Back</Link>
</div>
);
}
ContactCreate.propTypes = {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on propTypes

"id": PropTypes.number,
"name": PropTypes.string.isRequired,
"number": PropTypes.number.isRequired,
"email": PropTypes.string.isRequired,
"image": PropTypes.string.isRequired
};
ContactCreate.defaultProps = {
"id": undefined,
"name": 'N/A',
"number": 1234567890,
"email": 'N/A',
"image": 'https://cdn-icons-png.flaticon.com/512/1144/1144760.png'
};
const handleClick = (props) => {
const generateId = () => Math.round(Math.random() * 100000000)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing semi-colons at end of lines

props.id = generateId()
const contactLength = ContactsAPI.contacts.length
ContactsAPI.contacts[contactLength] = {
"id": props.id,
"name": props.name,
"phone-number": props.number,
"email": props.email,
"image": props.image
};
};

const Contact = () => {
const id = useParams();
const contact = ContactsAPI.get(parseInt(id.number));
if (!contact) {
alert("Invalid Number")
}
else {
return (
<div className="App">
<h2 className="header">{contact.name}</h2>
<hr/>
<div>
<img className="item-image-contact" alt="" src={contact.image}/>
<h4 className="item-contact text-center">Phone Number: {contact["phone-number"]}</h4>
<h4 className="item-contact text-center">Email: {contact.email}</h4>
</div>
<Link to="/contacts" className="btn btn-danger">Back</Link>
</div>

);
};
};



const Main = () => (
<main>
<Routes>
<Route exact path="/" element={<Home/>}/>
<Route path="/contacts" element={<Contacts/>}/>
<Route path={"/contacts/new"} element={<ContactCreate/>}/>
<Route path={"/contacts/:number"} element={<Contact/>}/>
</Routes>
</main>
);

export default App;
export default App;
6 changes: 6 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ body {
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;


}

html {
background-color: #282c34;
}

code {
Expand Down
11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import React from 'react';
import ReactDOM from 'react-dom';
import ReactDOM from 'react-dom/client';
import { BrowserRouter } from 'react-router-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';

ReactDOM.render(
const root = ReactDOM.createRoot(document.getElementById("root"))
root.render(
<React.StrictMode>
<App />
<BrowserRouter>
<App />
</BrowserRouter>
</React.StrictMode>,
document.getElementById('root')
);

// If you want to start measuring performance in your app, pass a function
Expand Down