-
Notifications
You must be signed in to change notification settings - Fork 38
React Eval #21
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
JoeCarnahan42
wants to merge
9
commits into
projectshft:main
Choose a base branch
from
JoeCarnahan42: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
React Eval #21
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8292577
Install eslint-wesbos
JoeCarnahan42 2671ad0
Add mock json data
JoeCarnahan42 de63f06
Remove global css
JoeCarnahan42 2c4a21e
Install bootstrap
JoeCarnahan42 37d3d57
Add test image/render list of test data
JoeCarnahan42 5273607
Change state control component for list. Add TODO's
JoeCarnahan42 52813a0
Complete functionality of adding new contact. Add custom css. Add TOD…
JoeCarnahan42 4da97ec
Initial Completion. Add individual contact viewing. Adjusted styling.
JoeCarnahan42 cbfc7ef
Various Changes Based On CR
JoeCarnahan42 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 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,62 @@ | ||
| 'use client' | ||
| import 'bootstrap/dist/css/bootstrap.css' | ||
| import Image from "next/image" | ||
| import Link from 'next/link' | ||
|
|
||
| export default function ContactList({ prop }) { | ||
| const link = () => { | ||
| alert('Sorry, but this does not function!') | ||
| } | ||
|
|
||
| return ( | ||
| <div className='container'> | ||
| <div className='row text-center'> | ||
| <div className="col"> | ||
| <div className="border-0 list-group-item"><u>Profile Picture</u></div> | ||
| </div> | ||
| <div className="col"> | ||
| <div className="border-0 list-group-item"><u>Name</u></div> | ||
| </div> | ||
| <div className="col"> | ||
| <div className="border-0 list-group-item"><u>Email</u></div> | ||
| </div> | ||
| <div className="col"> | ||
| <div className="border-0 list-group-item"><u>Phone Number</u></div> | ||
| </div> | ||
| <div className="col"> | ||
| <div className="border-0 list-group-item"><u>Actions</u></div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <br /> | ||
|
|
||
| {prop.map((c) => ( | ||
| <div className="row text-center p-1" key={c.id}> | ||
| <div className="col"> | ||
| <div className="border-0 list-group-item"> | ||
| <Image width={40} height={40} alt="unc" src={c.image_url} /> | ||
| </div> | ||
| </div> | ||
| <div className="col"> | ||
| <div className="border-0 list-group-item"> | ||
| <Link id={c.id} href={{ pathname: '/contacts/contact', query: { id: c.id } }}> | ||
| {c.name} | ||
| </Link> | ||
| </div> | ||
| </div> | ||
| <div className="col"> | ||
| <div className="border-0 list-group-item">{c.email}</div> | ||
| </div> | ||
| <div className="col"> | ||
| <div className="border-0 list-group-item">{c.phone_number}</div> | ||
| </div> | ||
| <div className="col"> | ||
| <div className="border-0 list-group-item"> | ||
| <button onClick={link} className='btn btn-link'>Edit/Delete</button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ) | ||
| } |
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,49 @@ | ||
| const Data = { | ||
| contacts: [ | ||
| { | ||
| "id": 1, | ||
| "name": "John Doe", | ||
| "image_url": "/media/JohnDoe.jpg", | ||
| "email": "john.doe@example.com", | ||
| "phone_number": "+1-555-123-4567" | ||
| }, | ||
| { | ||
| "id": 2, | ||
| "name": "Jane Smith", | ||
| "image_url": "/media/JaneSmith.jpg", | ||
| "email": "jane.smith@example.com", | ||
| "phone_number": "+1-555-234-5678" | ||
| }, | ||
| { | ||
| "id": 3, | ||
| "name": "Michael Johnson", | ||
| "image_url": "/media/MichaelJohnson.jpg", | ||
| "email": "michael.johnson@example.com", | ||
| "phone_number": "+1-555-345-6789" | ||
| }, | ||
| { | ||
| "id": 4, | ||
| "name": "Emily Davis", | ||
| "image_url": "/media/EmilyDavis.jpg", | ||
| "email": "emily.davis@example.com", | ||
| "phone_number": "+1-555-456-7890" | ||
| }, | ||
| { | ||
| "id": 5, | ||
| "name": "Chris Lee", | ||
| "image_url": "/media/ChrisLee.jpg", | ||
| "email": "chris.lee@example.com", | ||
| "phone_number": "+1-555-567-8901" | ||
| } | ||
| ], | ||
| addContact: function (id, name, image_url, email, phone_number) { | ||
| this.contacts.push({id, name, image_url, email, phone_number }) | ||
| }, | ||
| get: function (id) { | ||
| const isContact = (c) => c.id === id | ||
| return this.contacts.find(isContact) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| export default Data; | ||
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,2 @@ | ||
| // TODO | ||
| // Create dynamic contact display here |
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,33 @@ | ||
| 'use client' | ||
| import Data from "@/app/Data/page"; | ||
| import Image from "next/image"; | ||
| import Link from "next/link"; | ||
| import 'bootstrap/dist/css/bootstrap.css' | ||
|
|
||
|
|
||
|
|
||
| export default function Contact(prop) { | ||
| const id = JSON.parse(prop.searchParams.id) | ||
|
|
||
| const contact = Data.get(id) | ||
|
|
||
| if (!contact) { | ||
| return ( | ||
| <div className="text-center"> | ||
| <h1>Error: Contact Not Found</h1> | ||
| <Link href={'/contacts'}>Back</Link> | ||
| </div> | ||
| ) | ||
| } else { | ||
| return ( | ||
| <div className="text-center"> | ||
| <h1>Contact Info</h1> | ||
| <Link href={'/contacts'}>Back</Link> | ||
| <h1>{contact.name}</h1> | ||
| <Image src={contact.image_url} alt="Profile Picture" height={300} width={300} /> | ||
| <h1>{contact.email}</h1> | ||
| <h1>{contact.phone_number}</h1> | ||
| </div> | ||
| ) | ||
| } | ||
| } |
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,73 @@ | ||
| 'use client'; | ||
| import Link from "next/link"; | ||
| import { useState, useRef } from "react"; | ||
| import { useRouter } from "next/navigation"; | ||
| import Data from "@/app/Data/page"; | ||
| import 'bootstrap/dist/css/bootstrap.css'; | ||
|
|
||
| export default function NewContact() { | ||
| const nameInput = useRef(''); | ||
| const imgInput = useRef(''); | ||
| const emailInput = useRef(''); | ||
| const phoneInput = useRef(''); | ||
|
|
||
| const router = useRouter(); | ||
|
|
||
| const [isDisabled, setIsDisabled] = useState(true) | ||
| const [errorMessage, setErrorMessage] = useState('') | ||
|
|
||
| const addCon = (e) => { | ||
| e.preventDefault() | ||
| const id = Math.round(Math.random() * 100) | ||
|
|
||
| Data.addContact(id, nameInput.current.value, imgInput.current.value, emailInput.current.value, phoneInput.current.value); | ||
|
|
||
| nameInput.current.value = ''; | ||
| imgInput.current.value = ''; | ||
| emailInput.current.value = ''; | ||
| phoneInput.current.value = ''; | ||
|
|
||
| alert('Contact Added') | ||
|
|
||
| router.push('/contacts') | ||
| } | ||
| const renderInputs = (label, type, ref) => { | ||
| return ( | ||
| <div className="form-group"> | ||
| <label><u>{label}</u></label> | ||
| <br /> | ||
| <input onChange={enableSubmit} required ref={ref} className="input-group-text m-auto" type={type}></input> | ||
| <br /> | ||
| </div> | ||
| ) | ||
| } | ||
| const enableSubmit = () => { | ||
| const urlValid = imgInput.current.checkValidity(); | ||
|
|
||
| if (nameInput.current.value === '' || urlValid === false || emailInput.current.value === '' || phoneInput.current.value === '' || imgInput.current.value === '') { | ||
| setIsDisabled(true) | ||
| if (imgInput.current.value.trim() !== '' && urlValid === false) { | ||
| setErrorMessage('Please use a valid image url') | ||
| } else { | ||
| setErrorMessage('') | ||
| } | ||
| } else { | ||
| setIsDisabled(false) | ||
| } | ||
| } | ||
| return ( | ||
| <> | ||
| <h1 className="text-center p-3">Add New Contact</h1> | ||
| <form className="text-center p-3 mx-auto border rounded w-25 p-3"> | ||
| {renderInputs('Name', 'text', nameInput)} | ||
| {renderInputs('Image URL', 'url', imgInput)} | ||
| {renderInputs('Email', 'email', emailInput)} | ||
| {renderInputs('Phone Number', 'text', phoneInput)} | ||
| <button className="btn btn-primary" disabled={isDisabled} onClick={addCon}>Add Contact</button> | ||
| <br /> | ||
| <Link href='/contacts'>Cancel</Link> | ||
| <h3 style={{ color: "red" }}>{errorMessage}</h3> | ||
| </form> | ||
| </> | ||
| ) | ||
| } |
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,35 @@ | ||
| 'use client'; | ||
| import Link from "next/link"; | ||
| import ContactList from "../ContactList/page"; | ||
| import { useState } from 'react' | ||
| import Data from "../Data/page"; | ||
|
|
||
|
|
||
| export default function Contacts() { | ||
| const [search, setSearch] = useState(Data.contacts) | ||
| const searchCon = (e) => { | ||
| const normData = e.target.value.toLowerCase() | ||
| if (e.target.value.trim() === '') { | ||
| setSearch(Data.contacts) | ||
| } else { | ||
| const newList = Data.contacts.filter((c) => { | ||
| return c.name.toLowerCase().includes(normData)// Normalizes Input and Response | ||
| }) | ||
| setSearch(newList) | ||
| } | ||
| }; | ||
| return ( | ||
| <main> | ||
| <div className='text-center'> | ||
| <h1 className='display-4'>All Contacts</h1> | ||
| <Link className='btn btn-primary' href='/contacts/new'>Add Contact</Link> | ||
| </div> | ||
| <br /> | ||
| <div > | ||
| <input id="con-search" onChange={searchCon} className="input-group-text m-auto" placeholder="Search Contacts By Name" type="text"></input> | ||
| <br /> | ||
| <ContactList prop={search} /> | ||
| </div> | ||
| </main> | ||
| ); | ||
| }; |
This file was deleted.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| import { Inter } from 'next/font/google' | ||
| import './globals.css' | ||
|
|
||
| const inter = Inter({ subsets: ['latin'] }) | ||
|
|
||
|
|
||
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.
what is the difference between this and get all contacts?