-
Notifications
You must be signed in to change notification settings - Fork 48
Sockets - Kate N #33
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
base: master
Are you sure you want to change the base?
Sockets - Kate N #33
Changes from all commits
19ada00
9c4628d
3370a83
1cec18f
9f2dff3
c413aef
b48934d
5ee9eac
2e3b4e4
346f5ee
7b0f8b5
80dcf4c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #background { | ||
| width: 100%; | ||
| height: 100%; | ||
| position: fixed; | ||
| left: 0px; | ||
| top: 0px; | ||
| z-index: -1; | ||
| } | ||
|
|
||
| h1 { | ||
| text-align: center; | ||
| } | ||
|
|
||
| .stretch { | ||
| width:100%; | ||
| height:100%; | ||
| } | ||
|
|
||
| .load-btn{ | ||
| text-align: center; | ||
| background-color: white; | ||
| height:50px; | ||
| width:125px; | ||
| position: fixed; | ||
| } | ||
|
|
||
| .btn-container { | ||
| text-align:center; | ||
| } | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>Trek</title> | ||
| <script src="https://unpkg.com/axios/dist/axios.min.js"></script> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1"> | ||
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"> | ||
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> | ||
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script> | ||
| <script type="text/javascript" src="index.js"></script> | ||
| <link rel="stylesheet" href="index.css"> | ||
| </head> | ||
| <style> | ||
| .flex-container { | ||
| display: none; | ||
| flex-wrap: nowrap; | ||
| background-color: rgb(200, 230, 199); | ||
| } | ||
|
|
||
| .flex-container .box { | ||
| background-color: white; | ||
| width: 50%; | ||
| margin: 5px; | ||
| text-align: left; | ||
| line-height: 30px; | ||
| font-size: 15px; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <h1>Trek</h1> | ||
| <body> | ||
| <div id="background"> | ||
| <img src="https://i.ibb.co/RQjSQ7w/Screen-Shot-2019-05-31-at-1-28-37-PM.png" class="stretch" alt="" /> | ||
| </div> | ||
|
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. Watch your indentation ( |
||
|
|
||
| <div class="card"> | ||
| <div class="btn-container"> | ||
| <button id="load-trips">View All Trips</button> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="flex-container"> | ||
| <div class="box"> | ||
| <!-- <section id="status"></section> --> | ||
| <section class="all-trips"> | ||
| <div id="trip-list-container"> | ||
| <ul id="trip-list"></ul> | ||
| </div> | ||
| </div> | ||
| </section> | ||
| <div class="box"> | ||
| <section class="trip-details"> | ||
| <h2>Trip Details</h2> | ||
| <div id="trip-info"></div> | ||
| <div class="box"> | ||
| <div id="reservation-form"> | ||
| <p><h2>Book this trip!</h2></p> | ||
| <form> | ||
| <label for="your-name">Your Name:</label> | ||
| <input type="text" id="your-name" name="your-name" required> | ||
| <label for="email">Email:</label> | ||
| <input type="text" id="email" name="email" required> | ||
| <button type="submit">Submit</button> | ||
| </form> | ||
| </div> | ||
| </div> | ||
| </section> | ||
| </div> | ||
| </body> | ||
| </html> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| const tripsUrl = 'https://trektravel.herokuapp.com/trips'; | ||
|
|
||
| const displayStatus = (message) => { | ||
| $('#status').html(message); | ||
| }; | ||
|
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. This function tries to put messages in some element on the page that has ID |
||
|
|
||
| const reportError = (message, errors) => { | ||
| let content = `<p>${message}</p><ul>`; | ||
| for (const field in errors) { | ||
| for (const problem of errors[field]) { | ||
| content += `<li>${field}: ${problem}</li>`; | ||
| } | ||
| } | ||
| content += "</ul>"; | ||
| reportStatus(content); | ||
|
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. On line 15, do you mean |
||
| }; | ||
|
|
||
| const showTripDetails = id => { | ||
| const detailsUrl = tripsUrl + `/${id}`; | ||
| axios.get(detailsUrl) | ||
| .then(function(response) { | ||
| const trip = response.data; | ||
| let info = `<h3> ${trip.name}</h2> | ||
| <p>${trip.about}</p> | ||
| <ul> | ||
| <li><b>Continent</b>: ${trip.continent}</li> | ||
| <li><b>Category</b>: ${trip.category}</li> | ||
|
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. I don't know that I would use a |
||
| <li><b>Duration</b>: ${trip.weeks} weeks</li> | ||
| <li><b>Cost</b>: $${trip.cost}</li> | ||
| <li><b>Trip ID</b>: <span id="trip-id">${trip.id}</span></li> | ||
| </ul>`; | ||
| $("#trip-info").append(info); | ||
| $(document).scrollTop(0); | ||
| $('.trip-details').show(); | ||
| }) | ||
| .catch(function(error) { | ||
| console.log(error.response); | ||
| if (error.response.data && error.response.data.errors) { | ||
| reportError( | ||
| `Encountered an error: ${error.message}`, | ||
| error.response.data.errors | ||
| ); | ||
| } else { | ||
| reportStatus(`Encountered an error: ${error.message}`); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| const loadTrips = () => { | ||
| // displayStatus('Loading trips...'); | ||
| const tripList = $('#trip-list'); | ||
| tripList.empty(); | ||
|
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. This function's code feels very dense. Could you break it up with some empty lines? |
||
| $("#trip-info").empty(); | ||
| tripList.append(`<h2>All Trips</h2>`); | ||
| axios.get(tripsUrl) | ||
| .then(function (response) { | ||
| response.data.forEach((trip) => { | ||
| tripList.append(`<li><a href="" class="trip-link" id="${trip.id}">${trip.name}</a></li>`); | ||
| }); | ||
|
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. You should be using arrow functions for all of these callbacks. |
||
| console.log(response); | ||
| $('.flex-container').css('display', 'flex'); | ||
| }) | ||
| .catch(function (error) { | ||
| console.log(error.response); | ||
| if (error.response.data && error.response.data.errors) { | ||
| reportError( | ||
| `Encountered an error: ${error.message}`, | ||
| error.response.data.errors | ||
| ); | ||
| } else { | ||
| reportStatus(`Encountered an error: ${error.message}`); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| const reserveTrip = (trip) => { | ||
| console.log("reserving trip", trip) | ||
| } | ||
|
|
||
| $(document).on('submit', 'form', event => { | ||
| event.preventDefault(); | ||
| console.log("running submit"); | ||
| const trip_id = $("#trip-id").text(); | ||
|
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. This code might be easier to read if you moved some of it to the |
||
| const formData = { | ||
| trip_id: trip_id, | ||
| name: $("#your-name").val(), | ||
| email: $("#email").val() | ||
| }; | ||
| console.log(formData); | ||
| const resvUrl = tripsUrl + `/${trip_id}/reservations`; | ||
| axios | ||
| .post(resvUrl, formData) | ||
| .then(function(response) { | ||
| console.log(response); | ||
| }) | ||
| .catch(function(error) { | ||
| console.log(error); | ||
|
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. You should do something more than just |
||
| }); | ||
| $('input').val(''); | ||
| }); | ||
|
|
||
| $(document).on("click", "a", event => { | ||
| event.preventDefault(); | ||
| $("#trip-info").empty(); | ||
| const id = $(event.target).attr("id"); | ||
| console.log("loading " + id); | ||
| showTripDetails(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. I like the organization here, that this callback is focused on handling the DOM event and figuring out what was clicked, and |
||
| }); | ||
|
|
||
| $(document).on("click", "#load-trips", event => { | ||
| $('.trip-details').hide(); | ||
| loadTrips(); | ||
| }); | ||
|
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. All of these event handler registrations should be inside of |
||
|
|
||
| $(document).ready(() => { | ||
| $('.trip-details').hide(); | ||
| $('#load-trips').click(loadTrips); | ||
| }) | ||
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.
Why is this CSS in your HTML document? It should live in a separate
.cssfile.It looks like you do this for the rest of your styles... I am confused.