forked from AdaGold/trek
-
Notifications
You must be signed in to change notification settings - Fork 48
Sockets - Shubha #23
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
shubha-rajan
wants to merge
14
commits into
Ada-C11:master
Choose a base branch
from
shubha-rajan:master
base: master
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
Sockets - Shubha #23
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bd14d70
created html skeleton
shubha-rajan 72e7cd8
updated html/css skeleton
shubha-rajan c8df8f3
can display all trips on button click
shubha-rajan 45eef80
displays details and reservation form when a trip is selected
shubha-rajan c580726
can reserve trip & fixed bug so reloading doesn't make trips repeat
shubha-rajan 460bad7
refactored and added trip details
shubha-rajan c6b2d27
formatting
shubha-rajan 92a3855
ESLint style fixes and better error handling in axios requests
shubha-rajan 12202bb
refactored js to break up large functions
shubha-rajan 7bab49c
styling
shubha-rajan 6443641
more styling fixes
shubha-rajan 8afec16
validated html
shubha-rajan 098f00e
fixed styling bugs
shubha-rajan ee3b52e
added image attribution
shubha-rajan 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 |
|---|---|---|
| @@ -1 +1,6 @@ | ||
| .DS_Store | ||
| node_modules | ||
| .eslintrc.json | ||
| package.json | ||
| package-lock.json | ||
| .vscode |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,55 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"/> | ||
| <meta name="description" content="Reserve your spot on a trip"/> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"/> | ||
| <title>TREK</title> | ||
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" /> | ||
| <link href="https://fonts.googleapis.com/css?family=Karla:400,400i,700|Yesteryear&display=swap" rel="stylesheet"> | ||
| <link rel="stylesheet" href="trek.css"/> | ||
| <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js" integrity="sha256-S1J4GVHHDMiirir9qsXWc8ZWw74PHHafpsHp5PXtjTs=" crossorigin="anonymous"></script> | ||
| <script | ||
| src="https://code.jquery.com/jquery-3.4.1.slim.min.js" | ||
| integrity="sha256-pasqAKBDmFT4eHoN2ndd6lN370kFiGUFyTiUHWhU7k8=" | ||
| crossorigin="anonymous"></script> | ||
| <script src="trek.js"></script> | ||
| </head> | ||
| <body> | ||
| <header> | ||
| <hgroup> | ||
| <h1 id="page-title">Trek</h1> | ||
| <h2>Plan your next escape.</h2> | ||
| </hgroup> | ||
|
|
||
| </header> | ||
| <main> | ||
| <div id="status-message" class="hidden"></div> | ||
| <button id="main-button" class="centered">See All Trips</button> | ||
| <article> | ||
| <aside id="trips-list" class="hidden"> | ||
| <h2 id="trip-list-header">Available Trips</h2> | ||
| <ul id="trips-list-container"></ul> | ||
| </aside> | ||
| <section id="trip-details" class="hidden"></section> | ||
| <section id="reserve-trip" class="hidden"> | ||
| <h3 id="reserve-heading"></h3> | ||
| <div id="reserve-message" class="hidden"></div> | ||
| <form id="reserve-form" > | ||
| <div class="field"> | ||
| <label for="name-field">Name: </label> | ||
| <input id="name-field" type="text" name="name"> | ||
| </div> | ||
| <div class="field"> | ||
| <label for="email-field">Email: </label> | ||
| <input id="email-field" type="text" name="email"> | ||
| </div> | ||
| <input type="submit" value="Reserve" id="reserve-button"> | ||
|
|
||
| </form> | ||
| </section> | ||
| </article> | ||
| </main> | ||
| <footer>©Shubha Rajan, Ada Developers Academy 2019 | Photo by Leah Kelley from <a href="https://www.pexels.com/photo/close-up-of-pictures-185933/">Pexels</a></footer> | ||
| </body> | ||
| </html> |
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,146 @@ | ||
| body { | ||
| font-family:"Karla", sans-serif; | ||
| background-image: url('images/map-background.jpg'); | ||
| } | ||
|
|
||
| header h1, header h2 { | ||
| font-family: 'Yesteryear', cursive; | ||
| color:darkred; | ||
| text-shadow: 2px 2px white; | ||
| display:inline-block; | ||
| padding: 0 1em 0 1em; | ||
| } | ||
|
|
||
| h1 { | ||
| font-size:4em; | ||
| border-right: 2px solid darkred; | ||
| } | ||
|
|
||
| h2 { | ||
| font-size:2em; | ||
| } | ||
|
|
||
| ul { | ||
| padding: 10px; | ||
| list-style-type: none; | ||
| } | ||
| header { | ||
| text-align:center; | ||
| } | ||
|
|
||
|
|
||
| article { | ||
|
|
||
| width:80%; | ||
| margin:3em auto; | ||
| display:grid; | ||
| grid-template-rows: 1fr 1fr; | ||
| grid-template-columns: 2fr 2fr; | ||
| } | ||
|
|
||
| main { | ||
| text-align:center; | ||
| } | ||
|
|
||
| button, input[type="submit"] { | ||
| background-color:darkred; | ||
| color:white; | ||
| border:white 1px solid; | ||
| font-size:1.2em; | ||
| padding:10px; | ||
| } | ||
|
|
||
| section, aside { | ||
| background-color: blanchedalmond; | ||
| border-radius: 20px; | ||
| padding:20px; | ||
| margin:1em; | ||
| box-shadow: 10px 10px 5px 0px rgba(0,0,0,0.75); | ||
| } | ||
|
|
||
| details { | ||
| text-align:justify; | ||
| max-height:100px; | ||
| overflow-y:scroll; | ||
| margin:1em; | ||
| } | ||
|
|
||
| section>h3, aside>h3{ | ||
| color:darkred; | ||
| font-family: 'Yesteryear', cursive; | ||
| font-size:2em | ||
| } | ||
|
|
||
| #trips-list { | ||
| grid-column:1/2; | ||
| grid-row:1/3; | ||
| margin-right:3em; | ||
| } | ||
|
|
||
| #trips-list-container { | ||
| height:800px; | ||
| overflow-y:scroll; | ||
| padding:0; | ||
| margin:0; | ||
| border-top:solid 4px darkred; | ||
| border-bottom:solid 4px darkred; | ||
| } | ||
| #trip-details { | ||
| grid-column:2/3; | ||
| grid-row:1/2; | ||
|
|
||
| } | ||
|
|
||
| #reserve-trip { | ||
| grid-column:2/3; | ||
| grid-row:2/3; | ||
| } | ||
|
|
||
| #reserve-trip input{ | ||
| margin: 10px 5px; | ||
| } | ||
|
|
||
| #reserve-form .field{ | ||
| display:block; | ||
| } | ||
|
|
||
| .hidden { | ||
| visibility:hidden; | ||
| display:none; | ||
| } | ||
|
|
||
| .centered { | ||
| display:block; | ||
| margin: 20% auto; | ||
| font-size:2em; | ||
| } | ||
|
|
||
| #trip-list-header { | ||
| margin: 0; | ||
| text-align: center; | ||
| color:darkred; | ||
| font-family: 'Yesteryear', cursive; | ||
| background-color:blanchedalmond; | ||
| } | ||
|
|
||
|
|
||
| #cost{ | ||
| font-size:2em; | ||
| font-weight:bold; | ||
| color:darkred; | ||
| } | ||
|
|
||
| .selected { | ||
| color:white; | ||
| background-color:darkolivegreen; | ||
| padding:0.5em; | ||
| } | ||
|
|
||
| .error { | ||
| color:red; | ||
| } | ||
|
|
||
| .success { | ||
| color:green; | ||
| } | ||
|
|
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,131 @@ | ||
| const listErrors = (errors) => { | ||
| let errorList = '<ul>'; | ||
| for (const field in errors) { | ||
| for (const problem of errors[field]) { | ||
| errorList += `<li>${field}: ${problem}</li>`; | ||
| } | ||
| } | ||
| errorList += '</ul>'; | ||
| return errorList; | ||
| }; | ||
|
|
||
| const showMessage = (elementID, status) => { | ||
| $(elementID).addClass(status); | ||
| $(elementID).removeClass('hidden'); | ||
| }; | ||
|
|
||
| const handleReserveTrip = (tripID, continent) => { | ||
| const endpoint = `https://trektravel.herokuapp.com/trips/${tripID}/reservations`; | ||
| const name = $('#name-field').val(); | ||
| const email = $('#email-field').val(); | ||
|
|
||
| axios.post(endpoint, { name, email,}) | ||
| .then((response) => { | ||
| $('#reserve-form')[0].reset(); | ||
| showMessage('#reserve-message','success'); | ||
|
|
||
| const messageHTML = ( | ||
| `<h4>Congrats, ${name}, you're going to ${continent}!</h4>` | ||
| + `<p>Your reservation ID is ${response.data.id}.</p>` | ||
| ); | ||
| $('#reserve-message').html(messageHTML); | ||
|
|
||
| }) | ||
| .catch((error) => { | ||
| showMessage('#reserve-message','error'); | ||
| $('#reserve-message').html(`<h4> A problem occured: ${error.message} </h4>`); | ||
|
|
||
| if (error.response && error.response.data && error.response.data.errors) { | ||
| const errors = error.response.data.errors; | ||
| $('#reserve-message').append(listErrors(errors)); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| const changeSelected = (tripID) => { | ||
| $('.selected').removeClass('selected'); | ||
| $(`#trip-${tripID}`).addClass('selected'); | ||
| }; | ||
|
|
||
| const displayTripDescription = (tripID) => { | ||
| axios.get(`https://trektravel.herokuapp.com/trips/${tripID}`) | ||
| .then((response) => { | ||
| $('#trip-details').append(`<details>${response.data.about}</details>`); | ||
| }) | ||
| .catch((error) => { | ||
| $('#trip-details').append(`<p class="error">Failed to load trip details: ${error.message}</p>`); | ||
| }); | ||
| }; | ||
|
|
||
| const displayReservationForm = (tripName) => { | ||
| $('#reserve-heading').text(`Reserve a Spot on ${tripName}`); | ||
| $('#reserve-message').empty(); | ||
| $('#reserve-trip').removeClass('hidden'); | ||
| }; | ||
|
|
||
| const setReservationButtonHandler = (tripID, continent) => { | ||
| $('#reserve-button').off(); | ||
| $('#reserve-button').click((event) => { | ||
| event.preventDefault(); | ||
| handleReserveTrip(tripID, continent); | ||
| }); | ||
| }; | ||
|
|
||
| const displayTripDetails = (trip) => { | ||
| const tripDetails = ( | ||
| `<h3>${trip.name}</h3>` | ||
| + `<p id="continent">Continent: ${trip.continent}</p>` | ||
| + `<p id="category">Category: ${trip.category[0].toUpperCase() + trip.category.slice(1)}</p>` | ||
| + `<p id="weeks">${trip.weeks} ${(trip.weeks === 1) ? 'week' : 'weeks'}</p>` | ||
| + `<p id="cost">$${trip.cost.toFixed(2)}</p>` | ||
| ); | ||
| $('#trip-details').removeClass('hidden'); | ||
| $('#trip-details').html(tripDetails); | ||
| }; | ||
| const buildTripClickHandler = (trip) => { | ||
|
|
||
| const handler = () => { | ||
| changeSelected(trip.id); | ||
|
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. Good use of a closure to keep track of the trip data. |
||
| displayTripDetails(trip); | ||
| displayTripDescription(trip.id); | ||
| displayReservationForm(trip.name); | ||
| setReservationButtonHandler(trip.id, trip.continent); | ||
| }; | ||
| return handler; | ||
| }; | ||
|
|
||
| const moveButton = ()=>{ | ||
| $('#main-button').removeClass('centered'); | ||
| $('#main-button').text('Reload Trips'); | ||
| }; | ||
| const loadTrips = (tripData) => { | ||
| $('.selected').removeClass('selected'); | ||
| $('#trips-list').removeClass('hidden'); | ||
| $('#reserve-trip, #trip-details').addClass('hidden'); | ||
| $('#trip-details, #trips-list-container').empty(); | ||
|
|
||
| for (const trip of tripData) { | ||
| $('#trips-list-container').append(`<li id=trip-${trip.id}><h3>${trip.name}</h3></li>`); | ||
| const handleTripClick = buildTripClickHandler(trip); | ||
| $(`#trip-${trip.id}`).click(() => { handleTripClick(); }); | ||
| } | ||
| }; | ||
|
|
||
| const handleMainButtonClick = () => { | ||
| axios.get('https://trektravel.herokuapp.com/trips') | ||
| .then((response) => { | ||
| $('#status-message').empty(); | ||
| $('#status-message').addClass('hidden'); | ||
| moveButton(); | ||
| loadTrips(response.data); | ||
| }) | ||
| .catch((error) => { | ||
| $('#status-message').html(`Could not load trips: ${error.message}`); | ||
| showMessage('#status-message', error); | ||
| }); | ||
| }; | ||
|
|
||
| $('document').ready(() => { | ||
| $('#main-button').click(() => { handleMainButtonClick(); }); | ||
| $('#reserve-button').click(() => { handleReserveTrip(); }); | ||
| }); | ||
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.
Instead of a
clickon the button, you should listen for asubmitevent on the form itself. This will fire both when the button is clicked and when the user presses<enter>.Also, good catch turning off any previous event handler - this avoids a tricky bug with sending multiple POST requests.