forked from AdaGold/trek
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Carets - Maria - Trek #38
Open
ghost
wants to merge
12
commits into
Ada-C8:master
Choose a base branch
from
unknown repository
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
12 commits
Select commit
Hold shift + click to select a range
3f37928
initial set up index.html page
mariamcgrew 5dd0bd1
get response listing all trips
mariamcgrew 612893a
added .empty() to click event to reset trips on each click
mariamcgrew 751055b
added .text function to click
mariamcgrew 3319e1c
updated load trips to tripsInfo
mariamcgrew b5faf66
added callback functions to response for tripsInfo
mariamcgrew 9456e2f
refactored loadTrips for airbnb linter
mariamcgrew efcaed9
trip details appearing on page
mariamcgrew 6366449
appended trip details to trip by id
mariamcgrew 343bdeb
added form to individual trip
mariamcgrew fe3a1d6
added post action for reservation form
mariamcgrew cae53ba
added some css styling
mariamcgrew 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 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,32 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>TREK</title> | ||
<link href="https://cdnjs.cloudflare.com/ajax/libs/foundation/6.4.3/css/foundation-float.css" rel="stylesheet"> | ||
<link href="trek.css" media="screen" rel="stylesheet" type="text/css"> | ||
<link href="https://fonts.googleapis.com/css?family=Amatic+SC" rel="stylesheet"> | ||
</head> | ||
<body> | ||
<header class="header row"> | ||
<h1>TREK</h1> | ||
<div id="fail"></div> | ||
<button id="load" class="button"> Get trips! </button> | ||
</header> | ||
|
||
<h3></h3> | ||
<div class="small-12 columns"> | ||
<div id="trips"> | ||
<ul></ul> | ||
</div> | ||
</div> | ||
|
||
<script | ||
src="https://code.jquery.com/jquery-3.2.1.min.js" | ||
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" | ||
crossorigin="anonymous"></script> | ||
|
||
<script type="text/javascript" src="index.js"> | ||
</script> | ||
</body> | ||
</html> |
This file contains 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,87 @@ | ||
$(document).ready(() => { | ||
|
||
const loadTrips = function loadTrips() { | ||
$.get( | ||
'https://trektravel.herokuapp.com/trips', | ||
(response) => { | ||
response.forEach((trip) => { | ||
const tripsInfo = `<li id="trip-${trip.id}"><p id="${trip.id}">${trip.name}</p></li>`; | ||
$('#trips ul').append(tripsInfo); | ||
}); | ||
}, | ||
) | ||
.fail(() => { | ||
$('#fail').html('<p>Request was unsuccessful</p>'); | ||
}).always(() => { | ||
console.log('Function: loadTrips (plural)'); | ||
}); | ||
}; // end of loadTrips | ||
|
||
const loadTrip = function loadTrip(id) { | ||
$.get(`https://trektravel.herokuapp.com/trips/${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. This parameter is long enough it should probably be in a separate line. |
||
(response) => { | ||
const tripInfo = | ||
`<div> | ||
<p> Trip name: ${response.name}</p> | ||
<p> Category: ${response.category}</p> | ||
<p> Continent: ${response.continent}</p> | ||
<p> Description: ${response.about}</p> | ||
<p> Duration: ${response.weeks} weeks</p> | ||
<p> Cost: ${response.cost}</p> | ||
</div>`; | ||
|
||
const reservation = `<form id="form" action="https://trektravel.herokuapp.com/trips/${id}/reservations" method="post"> | ||
<section> | ||
<label>Name</label> | ||
<input type="text" id="name" name="name"></input> | ||
</section> | ||
|
||
<section> | ||
<label>Email</label> | ||
<input type="text" id="email" name="email"></input> | ||
</section> | ||
|
||
<section class="button"> | ||
<button type="submit">Reserve Trip</button> | ||
</section> | ||
</form>`; | ||
|
||
$('#trips ul li > div').hide(); | ||
$(`#trips ul li#trip-${id}`).append(tripInfo); | ||
$(`#trips ul li#trip-${id}`).append(reservation); | ||
}, | ||
).fail(() => { | ||
$('#fail').html('<p>Could not find</p>'); | ||
}).always(() => { | ||
console.log('Function: loadTrip (single)'); | ||
}); | ||
}; // end of loadTrip | ||
|
||
$('#trips ul').on('click', 'p', function() { | ||
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 name this event handler: |
||
const tripID = $(this).attr('id'); | ||
loadTrip(tripID); | ||
}); | ||
|
||
$('#load').click(() => { | ||
loadTrips(); | ||
$('h3').text('Select a Trip'); | ||
$('#trips ul').empty(); | ||
}); | ||
|
||
$('body').on('submit', 'form', function (e) { | ||
e.preventDefault(); | ||
|
||
const url = $(this).attr('action'); // this refers to the jquery object selected on it -- the specific form doing the submit | ||
const formData = $(this).serialize(); | ||
|
||
console.log(formData); | ||
|
||
$.post(url, formData, () => { // on submit the js is doing this post request | ||
$('#form').html('<p> Reservation added </p>'); | ||
}).fail(() => { | ||
$('#form').html('<p> Reservation failed </p>'); | ||
}).always(() => { | ||
console.log("you're doing alright"); | ||
}); | ||
}); | ||
}); // end of doc ready |
This file contains 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,44 @@ | ||
header { | ||
text-align: center; | ||
} | ||
|
||
h1 { | ||
font-family: 'Amatic SC', cursive; | ||
font-size: 6em; | ||
} | ||
|
||
#load { | ||
background-color: white; | ||
color: black; | ||
font-family: 'Amatic SC', cursive; | ||
font-size: 2em; | ||
} | ||
|
||
body { | ||
background-color: #7DBEA5; | ||
} | ||
|
||
h3 { | ||
text-align: center; | ||
font-family: 'Amatic SC', cursive; | ||
} | ||
|
||
li { | ||
background-color: white; | ||
list-style: none; | ||
border: solid; | ||
border-color: #C0C0C0; | ||
text-align: center; | ||
} | ||
|
||
p { | ||
font-family: 'Amatic SC', cursive; | ||
} | ||
|
||
#form { | ||
font-family: 'Amatic SC', cursive; | ||
} | ||
|
||
.button { | ||
background-color: #C0C0C0; | ||
} |
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.
This blank line isn't needed.