-
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
Eval submission #90
Open
jordanccox
wants to merge
24
commits into
projectshft:main
Choose a base branch
from
jordanccox: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
Eval submission #90
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
eb29383
run npm audit fix
jordanccox 37e0345
basic layout done
jordanccox 843ae0e
routes added, responsive styling fix
jordanccox e1aded5
useSearchParams to pass state to new contact
jordanccox 4ee2f1f
get basic contact matching functionality working
jordanccox 241129b
NewContact, Contact, ContactList, ContactListItem
jordanccox d0dbf1d
contact state issue fixed + styling fixed
jordanccox 4a9bf58
add contact working
jordanccox b68abe3
proptypes
jordanccox 3208af8
react phone number input
jordanccox 43c5d39
format phone number
jordanccox 472da83
edit functionality works
jordanccox 2107ccb
delete button works
jordanccox 56713b2
bug fixes
jordanccox eac44f2
finishing touches
jordanccox eeedd89
update search feature
jordanccox 80b5b26
refine code
jordanccox 624da71
StartHere component
jordanccox 772c40c
readme
jordanccox b88bb4a
readme
jordanccox ef3146c
eslint and prettier
jordanccox 962c9f6
generateId function
jordanccox 1b83e76
refine code
jordanccox 86cf413
fix bug
jordanccox 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,34 @@ | ||
## Contact List | ||
# Contact List | ||
|
||
This project has been created by a student at Parsity, an online software engineering course. The work in this repository is wholly of the student based on a sample starter project that can be accessed by looking at the repository that this project forks. | ||
Hey! This is a contact list app that I built using React and React Router. | ||
|
||
If you have any questions about this project or the program in general, visit [parsity.io](https://parsity.io/) or email [email protected]. | ||
## Run locally | ||
|
||
As a prerequisite, make sure you have [Node](https://nodejs.org/en) installed on your machine. | ||
|
||
To run locally, fork and clone this repository. | ||
|
||
In the directory you want to install this app in, run the following commands in your bash terminal: | ||
|
||
``` | ||
git clone [repo link here] | ||
cd contact-list | ||
npm install | ||
npm start | ||
``` | ||
|
||
That's it! Now you should be able to use the app at `http://localhost:3000/`. | ||
|
||
## Features | ||
|
||
To get started, click "New" to create a new contact. | ||
|
||
Fill out as much (or as little) information about your contact as you would like. If you leave your contact blank, they will show up as No Name in your contacts sidebar. | ||
|
||
To edit a contact once you've created it, click "Edit" and change whichever fields you would like. | ||
|
||
Once you have a number of contacts created, you might want to search for one in your contacts search bar. This will sort through your contacts and display any that match your search term. | ||
|
||
If you find yourself on a page that doesn't exist, you will run into a 404 error page and be redirected back here. | ||
|
||
⚠ Note: Right now, this app does not utilize local storage, so if you reload the browser, your contacts will be lost. |
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
Binary file not shown.
Binary file not shown.
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
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 |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { useLocation, useNavigate } from 'react-router-dom'; | ||
import PropTypes from 'prop-types'; | ||
import { | ||
formatPhoneNumber, | ||
parsePhoneNumber, | ||
formatPhoneNumberIntl, | ||
} from 'react-phone-number-input'; | ||
import NotFound from './NotFound'; | ||
|
||
export default function Contact({ getContact, deleteContact }) { | ||
const navigate = useNavigate(); | ||
const location = useLocation(); | ||
|
||
const currentContactId = location.pathname.replace(/^\//, ''); | ||
|
||
if (!getContact(currentContactId)) { | ||
return <NotFound />; | ||
} | ||
|
||
const contact = getContact(currentContactId); | ||
let displayPhoneNumber = ''; | ||
|
||
if (contact.phone) { | ||
const phoneNumber = parsePhoneNumber(contact.phone); | ||
displayPhoneNumber = formatPhoneNumberIntl(phoneNumber.number); | ||
|
||
if (phoneNumber.country === 'US') { | ||
displayPhoneNumber = formatPhoneNumber(phoneNumber.number); | ||
} | ||
} | ||
|
||
const handleDelete = () => { | ||
if ( | ||
window.confirm( | ||
'Are you sure you want to delete this contact? This action cannot be undone.' | ||
) | ||
) { | ||
deleteContact(contact); | ||
navigate('/'); | ||
} | ||
}; | ||
|
||
const noName = <i>No Name</i>; | ||
|
||
return ( | ||
<div className="d-flex flex-wrap"> | ||
<div className="p-2"> | ||
<img | ||
src={ | ||
contact.profilePicture || | ||
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. nice way to set a default |
||
'https://cdn.pixabay.com/photo/2015/10/05/22/37/blank-profile-picture-973460_1280.png' | ||
} | ||
alt="contact" | ||
className="img-thumbnail custom-img" | ||
/> | ||
</div> | ||
<div className="p-2"> | ||
<h1>{contact.name || noName}</h1> | ||
<h3>{displayPhoneNumber}</h3> | ||
{contact.email ? ( | ||
<p> | ||
<strong>Email: </strong> | ||
<a href={`mailto:${contact.email}`}>{contact.email}</a> | ||
</p> | ||
) : ( | ||
'' | ||
)} | ||
<div className="d-flex flex-wrap"> | ||
<button | ||
type="button" | ||
className="btn btn-success me-2 mt-2" | ||
onClick={() => | ||
navigate(`/${contact.contactId}/edit`, { state: contact }) | ||
} | ||
> | ||
Edit | ||
</button> | ||
<button | ||
type="button" | ||
className="btn btn-danger mt-2" | ||
onClick={handleDelete} | ||
> | ||
Delete | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
Contact.propTypes = { | ||
getContact: PropTypes.func, | ||
deleteContact: PropTypes.func, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* eslint-disable no-shadow */ | ||
import { NavLink } from 'react-router-dom'; | ||
import PropTypes from 'prop-types'; | ||
import ContactListItem from './ContactListItem'; | ||
|
||
export default function ContactList({ allContacts, sortedContacts }) { | ||
let contactList = allContacts(); | ||
|
||
const sortContacts = (contactList, value) => { | ||
const regex = value.toLowerCase(); | ||
|
||
const contacts = contactList | ||
.map((contact) => { | ||
const clone = { ...contact }; | ||
return clone; | ||
}) | ||
.filter((contact) => { | ||
if (contact.name.toLowerCase().match(regex)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}); | ||
|
||
return contacts; | ||
}; | ||
|
||
if (sortedContacts !== null && sortedContacts.length > 0) { | ||
contactList = sortContacts(contactList, sortedContacts); | ||
} | ||
|
||
if (contactList.length <= 0) { | ||
return ( | ||
<div className="list-group border-0 rounded-0 text-md-start"> | ||
<NavLink | ||
to="/contacts/new" | ||
className="list-group-item border-end-0 d-inline-block text-truncate text-center" | ||
> | ||
<i>Add a new contact</i> | ||
</NavLink> | ||
</div> | ||
); | ||
} | ||
|
||
const contacts = contactList.map((contact, index) => ( | ||
<ContactListItem key={index} contact={contact} /> | ||
)); | ||
|
||
return ( | ||
<div className="list-group border-0 rounded-0 text-md-start"> | ||
{contacts} | ||
</div> | ||
); | ||
} | ||
|
||
ContactList.propTypes = { | ||
allContacts: PropTypes.func, | ||
sortedContacts: PropTypes.string, | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { NavLink } from 'react-router-dom'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export default function ContactListItem({ contact }) { | ||
const noName = <i>No Name</i>; | ||
|
||
return ( | ||
<NavLink | ||
to={`${contact.contactId}`} | ||
className="list-group-item border-end-0 d-inline-block text-truncate" | ||
> | ||
{contact.name || noName} | ||
</NavLink> | ||
); | ||
} | ||
|
||
ContactListItem.propTypes = { | ||
contact: PropTypes.object, | ||
}; |
Oops, something went wrong.
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.
nice job on the readme