Conversation
TREKWhat We're Looking For
|
|
|
||
| const loadTrips = () => { | ||
| reportStatus('Loading trips...'); | ||
|
|
There was a problem hiding this comment.
Looks like your editor is set up to make 4-space tabs in JavaScript. At Ada we recommend 2-spaces, which will be important when you start working on pair projects. Please update this setting.
| tripList.append(`<li id='${trip.id}'><a href=#>${trip.name}</a></li><hr />`); | ||
| $(`#${trip.id}`).click(function () { | ||
| showTrip(trip.id); | ||
| }); |
There was a problem hiding this comment.
Good use of a callback here to track the trip ID.
| .then((response) => { | ||
| $('#form-section').removeClass('hidden'); | ||
| $('#trip-form').submit(function (event) { | ||
| $('#tripID').val(response.data.id); |
There was a problem hiding this comment.
The work being done here is complex enough that it might be worthwhile to break it out into its own function.
| const makeReservation = () => { | ||
| $('#status-message').html(''); | ||
| const tripID = $('#tripID').val(); | ||
|
|
There was a problem hiding this comment.
Using a hidden HTML field feels like an appropriate way to track the trip ID here.
| $('#trip-form').submit(function (event) { | ||
| $('#tripID').val(response.data.id); | ||
| event.preventDefault(); | ||
| makeReservation(); |
There was a problem hiding this comment.
When reserving a second trip, your site makes two POST requests. To reproduce:
- Open page
- Open chrome dev tools to the "Network" tab
- Click See All Trips
- Click on the first trip (Cairo to Zanzibar)
- Make a reservation and submit
- Click on the second trip (Everest Base Camp Trek)
- Make a reservation and submit
- Observe that on submit, 2 POST requests were made to trek API's /reservations endpoint
The reason for this is that you reuse the same reservation form for each trip, but re-attach the submit handler every time you show details for a trip.
TREK
Congratulations! You're submitting your assignment!
Comprehension Questions
Tripin the list by its ID field. Would it be advantageous to keep the list in order by the id field? Explain why or why not.