forked from AdaGold/trek
-
Notifications
You must be signed in to change notification settings - Fork 48
Sockets - Karla #43
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
kguadron
wants to merge
3
commits into
Ada-C11:master
Choose a base branch
from
kguadron: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 - Karla #43
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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,90 @@ | ||
| @import url("https://fonts.googleapis.com/css?family=Bangers&display=swap"); | ||
| @import url("https://fonts.googleapis.com/css?family=Muli&display=swap"); | ||
|
|
||
| body { | ||
| font-family: Muli; | ||
| background-image: url("https://tinyurl.com/y4labzbu"); | ||
| background-attachment: fixed; | ||
| /* background-position: center; */ | ||
| background-size: cover; | ||
| background-repeat: no-repeat; | ||
| } | ||
|
|
||
| main { | ||
| } | ||
|
|
||
| #title { | ||
| font-family: Bangers; | ||
| font-weight: 500; | ||
| font-size: 5rem; | ||
| } | ||
|
|
||
| #grid-container { | ||
| display: grid; | ||
| grid-template: auto 5em 1em / 50% auto; | ||
| } | ||
|
|
||
| #status-message { | ||
| grid-column: 1 / span 2; | ||
| grid-row: 1 / span 1; | ||
| border: solid; | ||
| border-color: orangered; | ||
| background-color: white; | ||
| opacity: 0.75; | ||
| } | ||
|
|
||
| #title { | ||
| grid-column: 1 / span 2; | ||
| grid-row: 2 / span 2; | ||
|
|
||
| justify-self: center; | ||
| } | ||
|
|
||
| #load { | ||
| border: solid; | ||
| border-color: orangered; | ||
| justify-self: end; | ||
| font-family: Muli; | ||
| font-size: 2em; | ||
| font-style: bold; | ||
| margin-top: 20%; | ||
| opacity: 0.75; | ||
| } | ||
|
|
||
| .current-treks { | ||
| grid-column: 1 / span 1; | ||
| grid-row: 3 / span 1; | ||
| justify-self: center; | ||
| padding-top: 10% | ||
| } | ||
|
|
||
| #trek-list { | ||
| list-style: none; | ||
| line-height: 30px; | ||
| text-align: center; | ||
| } | ||
|
|
||
| /* ul { | ||
| opacity: 0.75; | ||
| } */ | ||
|
|
||
| li { | ||
| background-color: white; | ||
| opacity: 0.75; | ||
| } | ||
|
|
||
| li:hover { | ||
| background-color: orangered; | ||
| color: white; | ||
| } | ||
|
|
||
| #details { | ||
| grid-column: 2 / span 1; | ||
| grid-row: 3 / span 1; | ||
| padding-top: 10%; | ||
| } | ||
|
|
||
| #details * { | ||
| background-color: white; | ||
| opacity: 0.75; | ||
| } |
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,31 @@ | ||
| <!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> | ||
| <script type="text/javascript" src="index2.js"></script> | ||
|
|
||
| <link rel="stylesheet" href="index.css"> | ||
| </head> | ||
|
|
||
| <body> | ||
|
|
||
| <main id="grid-container"> | ||
| <section id="status-message"></section> | ||
| <h1 id="title">Ready to Trek?</h1> | ||
| <section class="current-treks"> | ||
| <button id="load">See treks!</button> | ||
| <ul id="trek-list"></ul> | ||
| </section> | ||
|
|
||
| <section id="details"> | ||
| </section> | ||
| </main> | ||
|
|
||
| </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,99 @@ | ||
| 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 loadTreks = () => { | ||
| const trekList = $('#trek-list'); | ||
| trekList.empty(); | ||
|
|
||
| let URL = 'https://trektravel.herokuapp.com/trips' | ||
| axios.get(URL) | ||
| .then((response) => { | ||
| const theTreks = response.data; | ||
|
|
||
| theTreks.forEach((trek) => { | ||
| trekList.append(`<li id="trek">${trek.name}</li>`); | ||
|
|
||
| const showTrekDetails = (trip) => { | ||
| const trekDetail = () => { | ||
| let detailsURL = `https://trektravel.herokuapp.com/trips/${trip.id}` | ||
|
|
||
|
|
||
| axios.get(detailsURL) | ||
| .then((response) => { | ||
| const trekDeets = $('.indiv-trek'); | ||
| trekDeets.empty(); | ||
|
|
||
| trekDeets.html( | ||
| `<h1>${trip.name}</h1> | ||
| <h3>Continent: ${trip.continent}</h3> | ||
| <h3>Category: ${trip.category}</h3> | ||
| <h3>Weeks: ${trip.weeks}</h3> | ||
| <h3>Cost: $${trip.cost}</h3> | ||
| <h3>About: </h3> | ||
| <p>${response.data.about}</p>` | ||
| ) | ||
| // console.log(trip) | ||
| // console.log(response) | ||
| }) | ||
|
|
||
| .catch((error) => { | ||
| reportStatus(error); | ||
| }); | ||
| } | ||
| return trekDetail; | ||
| }; | ||
| const clickedTrek = showTrekDetails(trek); | ||
| $("li").click(clickedTrek); | ||
| }); | ||
| }) | ||
|
|
||
| .catch((error) => { | ||
| reportStatus(`Encountered an error while loading treks: ${error.message}`); | ||
| console.log(error); | ||
| }); | ||
| }; | ||
|
|
||
| $(document).ready(() => { | ||
| $('#load').click(loadTreks) | ||
| }); | ||
|
|
||
|
|
||
| // const showTrekDetails = (trip) => { | ||
| // let detailsURL = `https://trektravel.herokuapp.com/trips/${trip.id}` | ||
| // const trekDeets = $('#"trek-deets"'); | ||
|
|
||
| // axios.get(detailsURL) | ||
| // .then((response) => { | ||
| // trekDeets.append(`<h1>Trek Details</h1>`); | ||
| // trekDeets.append(`<li>${response.data[0].name}</li>`); | ||
| // console.log(response.data.name) | ||
| // }) | ||
| // .catch((error) => { | ||
| // reportStatus(`Encountered an error while loading treks: ${error.message}`); | ||
| // console.log(error); | ||
| // }); | ||
| // }; | ||
|
|
||
| // .catch((error) => { | ||
| // if (error.response.data && error.response.data.errors) { | ||
| //reportError('Encountered an errro while loading oets: ${error.message}, | ||
| // error.response.data.errors) | ||
| // } | ||
| // }) | ||
| // reportError('Encountered an errro while loading oets: ${error.message}, | ||
| // error.response.data.errors) | ||
|
|
||
|
|
||
| // https://picsum.photos/id/477/500/500 | ||
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,164 @@ | ||
| 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 loadTreks = () => { | ||
| const trekList = $('#trek-list'); | ||
| trekList.empty(); | ||
|
|
||
| let URL = 'https://trektravel.herokuapp.com/trips' | ||
| axios.get(URL) | ||
| .then((response) => { | ||
| reportStatus(`Successfully loaded ${response.data.length} trips`); | ||
| console.log('successfully loaded all trips'); | ||
|
|
||
| const theTreks = response.data; | ||
|
|
||
| theTreks.forEach((trek) => { | ||
| let thisTrek = $(`<li>${trek.name}</li>`); | ||
| thisTrek.addClass(`${trek.id}`); | ||
| trekList.append(thisTrek); | ||
| }) | ||
| }) | ||
|
|
||
| .catch((error) => { | ||
| reportStatus(`Encountered an error while loading treks: ${error.message}`); | ||
| console.log(error); | ||
| }) | ||
|
|
||
| const showTrekDetails = (event) => { | ||
| let trekId = event.target.className; | ||
| let detailsURL = `https://trektravel.herokuapp.com/trips/${trekId}`; | ||
|
|
||
| const detailSection = $('#details'); | ||
| detailSection.empty(); | ||
|
|
||
| axios.get(detailsURL) | ||
| .then((response) => { | ||
| reportStatus(`Successfully loaded trip ${trekId}`); | ||
| console.log('successfully loaded trip!'); | ||
|
|
||
| detailSection.html( | ||
| `<h1>${response.data.name}</h1> | ||
| <h3>Continent: ${response.data.continent}</h3> | ||
| <h3>Category: ${response.data.category}</h3> | ||
| <h3>Weeks: ${response.data.weeks}</h3> | ||
| <h3>Cost: $${response.data.cost}</h3> | ||
| <h3>About: </h3> | ||
| <p>${response.data.about}</p>` | ||
| // <button class=${trekId}> Make reservation </button>` | ||
| ) | ||
| reservationForm(); | ||
| $('#reservation-form').on('submit', makeReservation); | ||
| }) | ||
|
|
||
| .catch((error) => { | ||
| reportStatus(`Something went wrong with loading trip ${trekId}: ${error}`); | ||
| console.log(`Something went wrong with loading trip ${trekId}: ${error}`); | ||
| }); | ||
|
|
||
| const makeReservation = (event) => { | ||
| event.preventDefault(); | ||
| // const trekId = event.target.className; | ||
| console.log(`trek id: ${trekId}`) | ||
| let reservationURL = `https://trektravel.herokuapp.com/trips/${trekId}/reservations` | ||
|
|
||
| const trekData = readFormData(); | ||
|
|
||
| reportStatus('Sending trek data...'); | ||
|
|
||
| axios.post(reservationURL, trekData) | ||
| .then((response) => { | ||
| console.log(response); | ||
| reportStatus('Successfully reserved a trek!'); | ||
| clearForm(); | ||
| }) | ||
|
|
||
| .catch((error) => { | ||
| console.log(error.response); | ||
| // Make sure the server actually sent us errors. If | ||
| // there's a different problem, like a typo in the URL | ||
| // or a network error, the response won't be filled in. | ||
| if (error.response.data && error.response.data.errors) { | ||
| // User our new helper method | ||
| reportError(`Encountered an error: ${error.message}`, | ||
| error.response.data.errors | ||
| ); | ||
| } else { | ||
| // This is what we had before | ||
| reportStatus(`Encountered an error: ${error.message}`); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
|
|
||
| }; | ||
|
|
||
| const reservationForm = () => { | ||
| const detailSection = $('#details'); | ||
| detailSection.append('<h1>Make a Reservation</h1>') | ||
| detailSection.append('<form id="reservation-form">') | ||
| $('#reservation-form').append('<div>') | ||
| $('#reservation-form').append('<label for="name"> Name </label>') | ||
| $('#reservation-form').append('<input type="text" name="name" />') | ||
| // detailSection.append('</div>') | ||
| $('#reservation-form').append('<div>') | ||
| $('#reservation-form').append('<label for="email">Email</label>') | ||
| $('#reservation-form').append('<input type="text" name="email" />') | ||
| // detailSection.append('</div>') | ||
| $('#reservation-form').append('<div>') | ||
| $('#reservation-form').append('<label for="age">Age</label>') | ||
| $('#reservation-form').append('<input type="number" min="0" name="age" />') | ||
| // detailSection.append('</div>') | ||
| $('#reservation-form').append('<br>') | ||
| $('#reservation-form').append('<input type="submit" name="make-reservation" value="Reserve!!" />'); | ||
| // detailSection.append('</form>') | ||
| // $('#reservation-form').submit(makeReservation); | ||
| } | ||
|
|
||
| $("#trek-list").on('click', 'li', showTrekDetails); | ||
| // $("#details").on('click', 'button', reservationForm); | ||
| }; | ||
|
|
||
| const readFormData = () => { | ||
| let parsedFormData = {}; | ||
|
|
||
| const nameFromForm = $(`#reservation-form input[name="name"]`).val(); | ||
| parsedFormData['name'] = nameFromForm ? nameFromForm : undefined; | ||
|
|
||
| const ageFromForm = $(`#reservation-form input[name="age"]`).val(); | ||
| parsedFormData['age'] = ageFromForm ? ageFromForm : undefined; | ||
|
|
||
| const emailFromForm = $(`#reservation-form input[name="email"]`).val(); | ||
| parsedFormData['email'] = emailFromForm ? emailFromForm : undefined; | ||
|
|
||
| return parsedFormData; | ||
| }; | ||
|
|
||
| const clearForm = () => { | ||
| $(`#reservation-form input[name="name"]`).val(''); | ||
| $(`#reservation-form input[name="email"]`).val(''); | ||
| $(`#reservation-form input[name="age"]`).val(''); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| $(document).ready(() => { | ||
| $('#load').click(loadTreks); | ||
| // $('#reservation-form').submit(makeReservation); | ||
| }); | ||
|
|
||
| console.log('dee is here!'); | ||
|
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. Hi Dee! |
||
|
|
||
| // https://picsum.photos/id/477/500/500 | ||
Oops, something went wrong.
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.
So everytime I load the list of trips you add a new event handler to listen for events on the
lielements. This means, if I click onSee TREKS3 times and click on one of the trips it will callclickedTrek3 times.This is better to do with event delegation or use
$('li').off();to clear the event handlers before adding a new one.