Skip to content
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

&& Brittany Jones Ampers #45

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions foundation.css

Large diffs are not rendered by default.

Empty file added index.css
Empty file.
55 changes: 55 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Ada Trek</title>
<!-- <link rel="stylesheet" href="foundation.css"> -->
<!-- <link rel="stylesheet" href="index.css"> -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/foundation.min.css" integrity="sha256-GSio8qamaXapM8Fq9JYdGNTvk/dgs+cMLgPeevOYEx0= sha384-wAweiGTn38CY2DSwAaEffed6iMeflc0FMiuptanbN4J+ib+342gKGpvYRWubPd/+ sha512-QHEb6jOC8SaGTmYmGU19u2FhIfeG+t/hSacIWPpDzOp5yygnthL3JwnilM7LM1dOAbJv62R+/FICfsrKUqv4Gg==" crossorigin="anonymous">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

</head>

<body>
<section id="fail"></section>
<button id="all-trips" class="button">View All Trips</button>

<!-- All Trips -->
<section id="trips" class="all-trip-list">
<ul><h4></h4></ul>
</section>

<!-- Single Trip view -->
<article id="trip" class="trip-info-list">
<h1 id="trip-name"></h1>
<ul id="trip-summary"></ul>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've styled the single trip to show at the bottom rather than to the right.

</article>


<!-- Reserve a trip -->

<div id="reserve-trip" class="reserve-trip-form">
<form action="#" method="post" id="reservation-form">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your JavaScript should hide this form until there's a trip to submit details about.

<section>
<label>Name: </label>
<input type="text" id="name" name="name"></input>
</section>
<section>
<label>Age: </label>
<input type="number" id="age" name="age"></input>
</section>
<section>
<label>Email: </label>
<input type="text" id="email" name="email"></input>
</section>

<button id="submit-reservation" type="submit" class="button">Make Reservation</button>
</form>
</div>


<!-- Script tags -->
<script
src="https://code.jquery.com/jquery-3.2.1.min.js">
</script>
<script type="text/javascript" src="index.js"></script>
</body>
</html>
99 changes: 99 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@

$(document).ready(()=>{





// get the trips list from api, turn it into a list
let viewTripsList = function viewTripsList() {
$.get('https://ada-backtrek-api.herokuapp.com/trips',
(response) => {
response.forEach(function(trip) {
let tripInfo =
`<li data-id=${trip.id}><a>${trip.name}</a></li>`
$('#trips ul').append(tripInfo);
console.log('Trips list: success');
});
})
// If unable to load trips, give html response.
.fail(function(response){
$('fail').html('<p>Trips List: unsuccessful</p>')
console.log(response);
});
};



// Get trip information from API, and show info
let viewTrip = function viewTrip(id){
$.get(`https://ada-backtrek-api.herokuapp.com/trips/${id}`,
(response) => {
let tripName =
`Trip ${response.id}: ${response.name}`;
let tripSummary = `<li>Continent: ${response.continent}</li>
<li>Category: ${response.category}</li>
<li>Weeks: ${response.weeks}</li>
<li>Trip Cost: $${response.cost}</li>
<li>About: ${response.about}</li>`;
let showReserveBtn = `<button class="button secondary hollow">Reserve Trip</button>`;
$('#trip-name').html(tripName);
$('#trip-summary').html(tripSummary);
$('#show-reserve-btn').html(showReserveBtn);
$('#reservation-form').attr('action', 'https://ada-backtrek-api.herokuapp.com/trips/' + response.id + '/reservations/');

console.log('single trip: success');

$("#show-reserve-btn").click(function(){
$("#reserve-trip").slideDown();
});

})

.fail(function(response){
$('fail').html('<p>Single trip: error</p>')

/// console.log(); ///
console.log(response);
console.log('single trip: error');
});
};


// When all trips button is clicked, get the list of trips
$('#all-trips').on('click', function(){
viewTripsList();
});

// click event for single trip
$('#trips ul').on('click', 'li', function(){
let tripID = $(this).attr('data-id');
viewTrip(tripID);
});



$('form').submit(function(e) {
e.preventDefault();

const url = $(this).attr('action');
const formData = $(this).serialize();

$.post(url, formData, (response) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you using jQuery to do post requests rather than using Axios like we did in class?

$('#confirmation-msg').html('<p>Made Reservation: ' + $('#trip-name').html() + '!</p>');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This id #confirmation-msg does not exist in the HTML page.


/// console.log(); ///
console.log(url);
console.log(formData);
console.log('reservation: success!');
})
.fail(function(response){
$('#fail').html('<p>Something went wrong!</p>')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should output the validation errors like we did in class.


/// console.log(); ///
console.log(response);
console.log('reservation: error!');
});
});

});