forked from AdaGold/trek
-
Notifications
You must be signed in to change notification settings - Fork 42
Ampers - Sara S - Trek #32
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
CheerOnMars
wants to merge
4
commits into
Ada-C9:master
Choose a base branch
from
CheerOnMars: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
4 commits
Select commit
Hold shift + click to select a range
d834b08
set up files, Click button or link to show all trips
CheerOnMars b8c8dae
add functionality to view single trip
CheerOnMars 4ece9e1
added css, started reserve functionality
CheerOnMars 97d07b3
update css, complete add reservation feature
CheerOnMars 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
Binary file not shown.
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,48 @@ | ||
| body { | ||
| font-family: sans-serif; | ||
| } | ||
|
|
||
| main { | ||
| display: grid; | ||
| grid-template-columns: 1fr 1fr; | ||
| padding: 2rem; | ||
| } | ||
|
|
||
| h1 { | ||
| border-bottom: 1px solid #424242; | ||
| font-size: 3em; | ||
| text-align: center; | ||
| } | ||
|
|
||
| h3 { | ||
| border-bottom: .75px solid #424242; | ||
| text-align: center; | ||
| padding-bottom: .5em; | ||
| } | ||
|
|
||
| button { | ||
| background-color: #26A69A; | ||
| padding: 0.85em 1em; | ||
| color: white; | ||
| font-size: .75em; | ||
| font-weight: bold; | ||
| } | ||
|
|
||
| ul { | ||
| list-style-type: none; | ||
| } | ||
|
|
||
| .current-trips li { | ||
| border: .5px solid black; | ||
| text-align: center; | ||
| padding: 2em; | ||
| margin-right: .5em; | ||
| margin-left: .5em; | ||
| } | ||
|
|
||
| section { | ||
| margin-right: .5em; | ||
| margin-left: .5em; | ||
| padding-left: .5em; | ||
| padding-right: .5em; | ||
| } |
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,48 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>Trek</title> | ||
| <link href="index.css" media="screen" rel="stylesheet" type="text/css"/> | ||
| </head> | ||
| <body> | ||
|
|
||
| <nav> | ||
| </nav> | ||
|
|
||
| <header> | ||
| <section id="status-message"></section> | ||
| <h1>Trek</h1> | ||
| <button id="load">See All Trips</button> | ||
| </header> | ||
|
|
||
| <main> | ||
|
|
||
| <section class="current-trips" class="hidden"> | ||
| <ul id="trip-list"></ul> | ||
| </section> | ||
|
|
||
| <section id="trip-location"> | ||
| <div id="trip-details"> </div> | ||
| <button id="reserve-trip"> Reserve Trip </button> | ||
|
|
||
| <div id="new-reservation" class="hidden"> | ||
| <h3>Make a reservation</h3> | ||
| <form id="reservation-form"> | ||
| <label for="name">Name</label> | ||
| <input type="text" name="name" /> | ||
| <label for="email">Email</label> | ||
| <input type="text" name="email" /> | ||
| <input type="submit" name="add-reservation" value="Add Reservation" /> | ||
| </form> | ||
| </div> | ||
|
|
||
| </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="index.js"></script> | ||
| </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,148 @@ | ||
| 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 = $('#trip-list'); | ||
| tripList.empty(); | ||
|
|
||
| axios.get(URL) | ||
| .then((response) => { | ||
| reportStatus(`Successfully loaded ${response.data.length} trips`); | ||
| tripList.append(`<h3>All Trips</h3>`) | ||
| response.data.forEach((trip) => { | ||
| tripList.append(`<li trip-id="${trip.id}"><a>${trip.name}</a></li>`); | ||
| }); | ||
| }) | ||
|
|
||
| .catch((error) => { | ||
| reportStatus(`Encountered an error while loading trips: ${error.message}`); | ||
| console.log(error); | ||
| }); | ||
|
|
||
| }; | ||
|
|
||
| const viewTrip = (id) => { | ||
| reportStatus('Loading trip...'); | ||
|
|
||
| const tripDetail = $('#trip-details'); | ||
| tripDetail.empty(); | ||
|
|
||
| axios.get(URL + '/' + id) | ||
| .then((response) => { | ||
| if (response.status == 200) { | ||
| console.log(); | ||
| reportStatus(`Successfully loaded trip #${id}`); | ||
| let trip = response.data; | ||
| let tripID_res = 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. What does this variable do? |
||
| // console.log(`res id`); | ||
| // console.log(tripID_res); | ||
| let tripDetails = ` | ||
| <h3> ${trip.name} - Trip Details (ID <span>${trip.id}</span>) </h3> | ||
| <p> Continent: ${trip.continent} </p> | ||
| <p> Category: ${trip.category} </p> | ||
| <p> Duration: ${trip.weeks} weeks</p> | ||
| <p> Cost: $${trip.cost.toFixed(2)} </p> | ||
| <p> ${trip.about} </p> | ||
|
|
||
| `; | ||
| // $('span').hide() | ||
| $('#trip-details').append(tripDetails); | ||
| } else { | ||
| reportStatus(`Encountered an error while loading trip: ${error.message}`); | ||
| } | ||
| }) | ||
|
|
||
| .catch((error) => { | ||
| reportStatus(`Encountered an error while loading 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 reserveTrip = (event) => { | ||
| event.preventDefault(); | ||
|
|
||
| const tripId = $('#trip-details span').text(); | ||
| // const tripId = $('#trip-id'); | ||
| const reservationURL = URL + '/' + tripId + '/reservations'; | ||
| const reservationData = readFormData(); | ||
| console.log(); | ||
|
|
||
| reportStatus('Reserving trip...'); | ||
|
|
||
| axios.post(reservationURL, reservationData) | ||
| .then((response) => { | ||
| reportStatus(`Successfully added a reservation with ID ${tripId}!`); | ||
| clearForm(); | ||
| }) | ||
| .catch((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}`); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| $(document).ready(() => { | ||
| $("#trip-location").hide(); | ||
|
|
||
| $('#load').click(loadtrips) | ||
|
|
||
| $('ul').on('click', 'li', function() { | ||
| let tripID = $(this).attr('trip-id'); | ||
| viewTrip(tripID); | ||
| $('#trip-location').show(); | ||
| $("#reserve-trip").show(); | ||
| $("#new-reservation").hide(); | ||
| }); | ||
| $('#reserve-trip').click(function(){ | ||
| $("#reserve-trip").hide(); | ||
| $("#new-reservation").show(); | ||
| let tripID = $(this).attr('trip-id'); | ||
| }); | ||
| $('#reservation-form').submit(reserveTrip); | ||
| }); | ||
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.
should be camel case!