Skip to content
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
Empty file added index.css
Empty file.
26 changes: 26 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</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="index.js"></script>
</head>
<body>
<h1>TREK... TODAY!</h1>

<section class="status"></section>

<button id="load-trips">Load Trips</button>

<section id="trip-list"></section>

<section id="trip-details"></section>

<input type="submit" name="reserve-trip" value="Reserve Trip" />
</body>
</html>
73 changes: 73 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const URL = "https://trektravel.herokuapp.com/trips/";

// const ATRIPID = 'https://trektravel.herokuapp.com/trips/';

const reportStatus = (message) => {
$('#status-message').html(message);
};
const loadTrips = () => {
reportStatus('Loading trips...');

const tripList = $('#trip-list');
tripList.empty();

axios.get(URL)
.then((response) => {
reportStatus(`Successfully loaded ${response.data.length} trips`);
response.data.forEach((trip) => {
tripList.append(`<p>${trip.name}</p>`);

const showTripDetails = (trip) => {
const pleaseWork = () => {
console.log("showing details for trip", trip.id);
const tripEach = $('#trip-details');
tripEach.empty();

axios.get(URL + trip.id)
.then((response) => {
reportStatus(`Successfully loaded ${response.data.id} trips`);
tripEach.html(
`<h1>Trip Details</h1><h2>Name: ${response.data.name}</h2>Continent: ${response.data.continent}<h3>Category: ${response.data.category}</h3><h4>Weeks: ${response.data.weeks}</h4><h4>Cost: ${response.data.cost}</h4><h4>About:</h4><p>${response.data.about}</p>`
)
})
.catch((error) => {
reportStatus(`Encountered an error while loading trips: ${error.message}`);
console.log(error);
})
};
return pleaseWork;
};
const thisTrip = showTripDetails(trip)
$('p:last').click(thisTrip)
})
})
}
const displayStatus = (message) => {
$('#status-message').html(message);
}

const handleApiError = (error) => {
console.log("encountered error when posting", error);

let errorHtml = `<p>${error.message}</p><ul>`;
// TODO: politely report this error to the user
}

// TODO: Wave 2
// display trip details and the trip reservation form

const reserveTrip = (trip) => {
console.log("reserving trip", trip)

// TODO: Wave 2
// reserve a spot on the trip when the form is submitted
}

$(document).ready(() => {
$("#load-trips").click(loadTrips);

$('#-form').submit((event) => {
event.preventDefault();
reserveTrip();
});
});