-
Notifications
You must be signed in to change notification settings - Fork 93
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
m8ximus
wants to merge
2
commits into
projectshft:main
Choose a base branch
from
m8ximus:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = () => ( | ||
<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 = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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