-
Notifications
You must be signed in to change notification settings - Fork 91
contact-list-wla #83
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
Open
Will9214
wants to merge
3
commits into
projectshft:main
Choose a base branch
from
Will9214: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
contact-list-wla #83
Changes from all commits
Commits
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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "contacts": [ | ||
| { | ||
| "id": 70219577, | ||
| "name": "Albert Einstein", | ||
| "image_url": "https://en.wikipedia.org/wiki/Albert_Einstein#/media/File:Einstein_1921_by_F_Schmutzer_-_restoration.jpg", | ||
| "email": "[email protected]", | ||
| "phone_number": "15555555555" | ||
| } | ||
| ] | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import React from "react"; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| //returning jsx to add new contact to contacts list | ||
| const Contact = ({contact, handleRowClick}) => { | ||
|
|
||
| return( | ||
| <tbody> | ||
| <tr id={contact.id} onClick={handleRowClick}> | ||
| <td className='col-md-3'><img src={contact.imageUrl} className='col-md-12 border' alt='' /></td> | ||
| <td>{contact.fullName}</td> | ||
| <td>{contact.email}</td> | ||
| <td>{contact.phoneNumber}</td> | ||
| </tr> | ||
| </tbody> | ||
| ) | ||
| }; | ||
|
|
||
| Contact.propTypes = { | ||
| contact: PropTypes.object.isRequired, | ||
| } | ||
|
|
||
| export default Contact; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import React from 'react'; | ||
| import { Link, useNavigate } from 'react-router-dom'; | ||
| import Contact from './Contact'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| const ContactsList = ({contacts}) => { | ||
| //navigate to individual contact page (ShowContact component) when a contact is clicked | ||
| const navigate = useNavigate(); | ||
| const handleRowClick = (e) => { | ||
| const contactId = e.currentTarget.id; | ||
| navigate(`/contacts/${contactId}`); | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <h1 className='text-center'>Contacts List</h1> | ||
| <table className='table offset-md-1 table-bordered table-hover' style={{"width" : "80%"}}> | ||
| <thead> | ||
| <tr> | ||
| <th key="pic" scope='col' className=''>Profile Pic</th> | ||
| <th key='name' scope='col' className=''>Name</th> | ||
| <th key='email' scope='col' className=''>Email</th> | ||
| <th key='phoneNumber' scope='col' className=''>Phone Number</th> | ||
| </tr> | ||
| </thead> | ||
|
|
||
| {/* maps through contacts and displays each contact */} | ||
| {contacts.map(contact => { | ||
| return( | ||
| <Contact contact={contact} handleRowClick={handleRowClick} /> | ||
| ) | ||
| })} | ||
|
|
||
| </table> | ||
| <Link to='/new' className='btn btn-primary offset-md-1'>Add Contact</Link> | ||
| </div> | ||
| ) | ||
| }; | ||
| //PropType for the contacts prop being passed in | ||
| ContactsList.propTypes = { | ||
| contacts: PropTypes.array | ||
| } | ||
|
|
||
| export default ContactsList; | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import React, { useState } from 'react'; | ||
| import { useNavigate, Link } from 'react-router-dom'; | ||
|
|
||
| const NewContact = ({onSubmit}) => { | ||
| const navigate = useNavigate(); | ||
|
|
||
| //creating individual states for each user input | ||
| const [fullName, setFullName] = useState(''); | ||
| const [email, setEmail] = useState(''); | ||
| const [phoneNumber, setPhoneNumber] = useState(''); | ||
| const [imageUrl, setImageUrl] = useState(''); | ||
|
|
||
| //id generator to give unique id for each contact created | ||
| const generateId = () => Math.round(Math.random() * 1000000000); | ||
|
|
||
| //creating contact object that will be added to the contacts state in index.js. Clicking will also result in navigating back to ContactsList | ||
| const handleSubmit = () => { | ||
| const contact = { | ||
| id: generateId(), | ||
| fullName, | ||
| email, | ||
| phoneNumber, | ||
| imageUrl | ||
| }; | ||
|
|
||
| onSubmit(contact); | ||
| navigate('/'); | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <h1 className='text-center'>Add Contact</h1> | ||
| <div className='row offset-md-3 col-md-6'> | ||
| <div>Full Name</div> | ||
| <input className='form-control' onChange={(e) => setFullName(e.target.value)}></input> | ||
| <div>Email Address</div> | ||
| <input className='form-control' onChange={(e) => setEmail(e.target.value)}></input> | ||
| <div>Phone Number</div> | ||
| <input className='form-control' onChange={(e) => setPhoneNumber(e.target.value)}></input> | ||
| <div>Image URL</div> | ||
| <input className='form-control' onChange={(e) => setImageUrl(e.target.value)}></input> | ||
| <hr /> | ||
| </div> | ||
|
|
||
| <button to='/contacts' className='btn btn-primary offset-md-3' onClick={handleSubmit}>Add Contact</button> | ||
| <Link to='/' className='btn btn-primary offset-md-4'>Back</Link> | ||
| </div> | ||
| ) | ||
| }; | ||
|
|
||
| export default NewContact; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import React from "react" | ||
| import { Link, useLocation, matchPath } from 'react-router-dom'; | ||
| import PropTypes from 'prop-types'; | ||
|
|
||
| const ShowContact = ({contacts}) => { | ||
| //matching id of the path to id of the contact object that was clicked so the correct individual contact is shown. | ||
| //There seems like there could be an easier way to do this? | ||
| const location = useLocation(); | ||
| const path = matchPath("/contacts/:id", location.pathname); | ||
| const pathId = parseInt(path.params.id); | ||
| const contact = contacts.find(obj => obj.id === pathId); | ||
|
|
||
| return ( | ||
| <div> | ||
| <h1 className="text-center">Contact</h1> | ||
| <br /> | ||
| <div className='col-md-2 offset-md-5 border'> | ||
| <img src={contact.imageUrl} className='col-md-12' alt=""/> | ||
| <div className='text-center'> | ||
| <h4><strong>{contact.fullName}</strong></h4> | ||
| <div>{contact.email}</div> | ||
| <div><strong>{contact.phoneNumber}</strong></div> | ||
| </div> | ||
| </div> | ||
| <Link to='/' className='btn btn-primary offset-md-5'>Back</Link> | ||
| </div> | ||
| ) | ||
| }; | ||
|
|
||
| ShowContact.propTypes = { | ||
| contact: PropTypes.object, | ||
| } | ||
|
|
||
| export default ShowContact; |
This file contains hidden or 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,13 +1,25 @@ | ||
| body { | ||
| margin: 0; | ||
| font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', | ||
| 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', | ||
| font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", | ||
|
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. stay consistent in use of single quotes for strings |
||
| "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', | ||
| font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", | ||
| monospace; | ||
| } | ||
|
|
||
| input { | ||
| margin-bottom: 10px; | ||
| } | ||
|
|
||
| .btn { | ||
| margin-bottom: 10px; | ||
| } | ||
|
|
||
| .contact:hover { | ||
| background-color: lightgrey; | ||
| } | ||
This file contains hidden or 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,17 +1,40 @@ | ||
| import React from 'react'; | ||
| import 'bootstrap/dist/css/bootstrap.min.css'; | ||
| import React, { useState } from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import './index.css'; | ||
| import App from './App'; | ||
| import reportWebVitals from './reportWebVitals'; | ||
| import { BrowserRouter, Routes, Route } from 'react-router-dom'; | ||
| import ContactsList from './components/ContactsList'; | ||
| import NewContact from './components/NewContact'; | ||
| import ShowContact from './components/ShowContact'; | ||
|
|
||
| //App component | ||
| const App = () => ( | ||
| <div> | ||
| <Main /> | ||
| </div> | ||
| ) | ||
| //Create contacts state. An array that will have objects added to it. | ||
| const Main = () => { | ||
| const [contacts, setContacts] = useState([]); | ||
|
|
||
| const handleAddContacts = (contact) => { | ||
| setContacts(prevState => [...prevState, contact]) | ||
| } | ||
|
|
||
| return ( | ||
| <Routes> | ||
| <Route exact path="/" element={<ContactsList contacts={contacts} />} /> | ||
| <Route path="/new" element={<NewContact onSubmit={handleAddContacts}/>} /> | ||
| <Route path="/contacts/:number" element={<ShowContact contacts={contacts} />} /> | ||
| </Routes> | ||
| ) | ||
| } | ||
|
|
||
| ReactDOM.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 | ||
| // to log results (for example: reportWebVitals(console.log)) | ||
| // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals | ||
| reportWebVitals(); |
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.
Getting a warning
react-jsx-dev-runtime.development.js:117 Warning: Each child in a list should have a unique "key" prop.
Check the render method of
ContactsList. See https://reactjs.org/link/warning-keys for more information.