forked from AdaGold/trek
-
Notifications
You must be signed in to change notification settings - Fork 42
Brenda Rios - Trek - Octos #30
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
brendarios
wants to merge
14
commits into
Ada-C9:master
Choose a base branch
from
brendarios: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
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
5e7dd80
Added loadTrips function and is loading trips successfully.
brendarios 7888be9
Added function to load a trip details and is working.
brendarios 4ae18fe
Added catch error to the function of loading a trip details.
brendarios 49f68a0
Refactored individual trip sintax.
brendarios a846a0b
Added form fields to reserve a trip.
brendarios d898262
Refactored to append the reservation form.
brendarios 5e1c7f0
Added css
brendarios f85e941
Post for reservations working.
brendarios ff77716
Adding CSS for the forms.
brendarios 7c2e05b
Improving the styling.
brendarios b2a38dc
Added styling to the trip details.
brendarios d0859b6
Last styling details.Changed background picture.
brendarios cc42bb3
Fixed indentation.
brendarios 38374bc
Increased size of picture.
brendarios 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,74 @@ | ||
| body { | ||
| background-color: #e6e6e6; | ||
| font-family: Arial; | ||
| margin-left: 3%; | ||
| margin-right: 3%; | ||
| } | ||
|
|
||
|
|
||
| main { | ||
| padding: 4vh 0; | ||
| margin-bottom: 0; | ||
| display: grid; | ||
| grid-template-columns: 1fr 1fr; | ||
| grid-template-rows: .6fr .3fr .1fr; | ||
| grid-gap: 1em; | ||
| } | ||
|
|
||
| .trips { | ||
| grid-area: 2/1/4/2; | ||
|
|
||
| } | ||
|
|
||
|
|
||
| #trips-list { | ||
| max-height: 80vh; | ||
| overflow-x: scroll; | ||
|
|
||
|
|
||
| } | ||
|
|
||
| .welcome { | ||
| grid-area: 1/1/2/3; | ||
| text-align: center; | ||
| padding-top: 10vh; | ||
| font-size: 50pt; | ||
| font-family: Luckiest Guy; | ||
| color: #cccc00; | ||
| background: url("road.jpg") no-repeat; | ||
| background-size: 100% 100%; | ||
| } | ||
|
|
||
| #trip { | ||
| display: grid; | ||
| grid-area: 2/2/3/3; | ||
| padding-top: 10vh; | ||
| height: 30vh; | ||
| overflow: scroll; | ||
|
|
||
| } | ||
|
|
||
| .trip-details { | ||
| background-color: #f3ffcc; | ||
| border-style: solid; | ||
| border-width:thin; | ||
| } | ||
|
|
||
| .new-reservation { | ||
| grid-area: 3/2/4/3; | ||
|
|
||
| } | ||
|
|
||
| .reservation { | ||
| margin-left: 30%; | ||
| } | ||
|
|
||
| button#load, input[type="submit"] { | ||
| background-color: #cccc00; | ||
| border-style: solid; | ||
| border-radius: 5pt; | ||
| margin: 0 auto 1em auto; | ||
| font-size: 1em; | ||
| padding: 5px 30px; | ||
|
|
||
| } |
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,42 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en" dir="ltr"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>Trek</title> | ||
| <script | ||
| src="https://code.jquery.com/jquery-3.3.1.js"></script> | ||
| <script src="https://unpkg.com/axios/dist/axios.min.js"></script> | ||
|
|
||
| <link rel="stylesheet" href="index.css"> | ||
| <link href="https://fonts.googleapis.com/css?family=Luckiest+Guy" rel="stylesheet"> | ||
| </head> | ||
| <body> | ||
|
|
||
| <section id="status-message"></section> | ||
|
|
||
| <main> | ||
| <header class="welcome">Find your next adventure!</header> | ||
|
|
||
| <section class="trips"> | ||
| <h1>Amazing Trips</h1> | ||
| <button id="load">Get trips!</button> | ||
| <ul id="trips-list"></ul> | ||
| </section> | ||
|
|
||
| <section > | ||
| <table id = "trip"></table> | ||
| </section> | ||
|
|
||
| <section class="new-reservation"> | ||
| <form id="reservation-form"></form> | ||
| </section> | ||
|
|
||
|
|
||
| </main> | ||
|
|
||
| <script src="https://code.jquery.com/jquery-3.3.1.js"></script> | ||
| <script src="https://unpkg.com/axios/dist/axios.min.js"></script> | ||
| <script type="text/javascript" src="trek.js"></script> | ||
|
|
||
| </body> | ||
| </html> |
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,155 @@ | ||
| const URL = 'https://ada-backtrek-api.herokuapp.com/trips/'; | ||
|
|
||
| const reportStatus = (message) => { | ||
| $('#status-message').html(message); | ||
| }; | ||
|
|
||
| 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); | ||
| }; | ||
|
|
||
| const loadTrips = () => { | ||
| reportStatus('Loading trips...'); | ||
|
|
||
| const tripList = $('#trips-list'); | ||
| tripList.empty(); | ||
|
|
||
| axios.get(URL) | ||
| .then((response) => { | ||
| console.log(response); | ||
| reportStatus(`Successfully loaded ${response.data.length} trips`); | ||
| response.data.forEach((trip) => { | ||
| tripList.append(`<li id="${trip.id}">${trip.name}</li>`); | ||
| }); | ||
| }) | ||
| .catch((error) => { | ||
| reportStatus(`Encountered an error while loading trips: ${error.message}`); | ||
| console.log(error); | ||
| }); | ||
| }; | ||
|
|
||
| const individualTrip = (id) => { | ||
| console.log(id); | ||
| reportStatus("Loading trip details..."); | ||
| const reserve = $('#reservation-form'); | ||
| const trip = $('#trip'); | ||
| trip.empty(); | ||
| reserve.empty(); | ||
|
|
||
| let urlTrip = URL + id; | ||
| axios.get(urlTrip) | ||
| .then((response) => { | ||
|
|
||
| reportStatus(`Successfully loaded trip to: ${response.data.name}`); | ||
|
|
||
| trip.append( | ||
| ` | ||
| <tr><th>Trip Details:</th></tr> | ||
| <tr><th>Name: ${response.data.name}</th></tr> | ||
| <tr><th>Continent:</th><td>${response.data.continent}</td></tr> | ||
| <tr><th>Category:</th><td>${response.data.category}</td></tr> | ||
| <tr><th>Cost:</th><td>${response.data.cost}</td></tr> | ||
| <tr><th>Weeks:</th><td>${response.data.weeks}</td></tr> | ||
| <tr><th>About:</th><td>${response.data.about}</td></tr> | ||
| ` | ||
| ); | ||
| $('#trip').addClass('trip-details'); | ||
| reserve.addClass(id); | ||
| reserve.html( | ||
| `<h1>Reservation</h1> | ||
| <div> | ||
| <label for="name">Name</label> | ||
| <input type="text" name="name" /> | ||
| </div> | ||
|
|
||
| <div> | ||
| <label for="email">Email</label> | ||
| <input type="text" name="email" /> | ||
| </div> | ||
|
|
||
| <input type="submit" name="add-reservation" value="Submit Reservation" /> | ||
| ` | ||
| ); | ||
| $('#reservation-form').addClass('reservation'); | ||
|
|
||
|
|
||
| $('#reservation-form').submit(function(event) { | ||
| console.log(event); | ||
| event.preventDefault(); | ||
| createReservation(urlTrip); | ||
|
|
||
| }); | ||
| }) | ||
| .catch((error) => { | ||
| reportStatus(`Encountered an error while loading this trip: ${error.message}`); | ||
| console.log(error); | ||
| }); | ||
| }; | ||
|
|
||
| const FORM_FIELDS = ['name', 'email']; | ||
| const inputField = name => $(`#reservation-form input[name="${name}"]`); | ||
|
|
||
| const readFormData = () => { | ||
| const getInput = name => { | ||
| const input = inputField(name).val(); | ||
| return input ? input : undefined; | ||
| }; | ||
|
|
||
| const formData = {}; | ||
| FORM_FIELDS.forEach((field) => { | ||
| formData[field] = getInput(field); | ||
| }); | ||
|
|
||
| return formData; | ||
|
|
||
| }; | ||
|
|
||
|
|
||
| const clearForm = () => { | ||
| FORM_FIELDS.forEach((field) => { | ||
| inputField(field).val(''); | ||
| }); | ||
| } | ||
|
|
||
| const createReservation = (urlTrip) => { | ||
|
|
||
| const reservationData = readFormData(); | ||
| console.log(reservationData); | ||
|
|
||
| reportStatus('Doing your reservation...'); | ||
|
|
||
| let urlReservation = urlTrip + '/reservations' | ||
| axios.post(urlReservation, reservationData) | ||
|
|
||
| .then((response) => { | ||
| console.log(response); | ||
| reportStatus(`Successfully added a reservation for ${response.data.name}!`); | ||
| clearForm(); | ||
| }) | ||
| .catch((error) => { | ||
| console.log(error.response); | ||
| if (error.response.data && error.response.data.errors) { | ||
| reportError( | ||
| `Encountered an error while trying to reserve the trip: ${error.message}`, | ||
| error.response.data.errors | ||
| ); | ||
| } else { | ||
| reportStatus(`Was not able to reserve your trip: ${error.message}`); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| $(document).ready(() => { | ||
| $('#load').click(loadTrips); | ||
| $(`#trips-list`).on(`click`, `li`, function(){ | ||
| individualTrip(this.id); | ||
| }); | ||
|
|
||
| }); | ||
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.
It might make sense to break the code to render trip details out into a separate function - as is, this function is doing two things (making the request, and rendering data). See also http://callbackhell.com/