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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ TREK is an application that displays information on travel packages and allows u

This is a [stage 2](https://github.com/Ada-Developers-Academy/pedagogy/blob/master/rule-of-three.md) individual project.

The project is due **Tuesday May 29th before 9am**.
The project is due **Tuesday May 29th before 9am**.

## Learning Goals

Expand Down
Binary file added images/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Trek</title>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/foundation/6.2.3/foundation.min.css">
<link rel="stylesheet" href="style.css">
</head>

<body>
<header>
<h1>Trek the World</h1>
<button id="load" class="button">See All Trips</button>
</header>

<section id="status-message"></section>

<main class="row">
<section class="small-6 columns trips-container">
<table id="table">
<thead>
<tr>
<th>Trip Id</th>
<th>Trip Name</th>
</tr>
</thead>
<tbody id="tbody"></tbody>
</table>
</section>

<section class="small-6 columns trips-container">
<table id="details">
<thead>
<tr>
<th>
Trip Details
</th>
</tr>
</thead>
<tbody id="trip-info"></tbody>
</table>

<button id="reservation-form" class="button">Reserve Trip</button>

</section>
</main>

<footer>
<h5>Nicoleta Brandolini @2018</h5>
</footer>

<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="trek.js"></script>
</body>
</html>
45 changes: 45 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.trip-details cell medium-8 medium-cell-block-y {

}

body {
text-align: center;
padding: 2rem;
height: 100%;
background-image: url('images/background.png');
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}

#status-message {
font-size: 1rem;
color: white;
padding-bottom: 20px;
}

h1 {
font-size: 4rem;
color: #077b93;
}

th {
color: #077b93
}

.button {
font-size: 1rem;
background-color: #077b93;
margin: 15px;
padding: 10px;
}

footer {
color: white;
padding: 20px 0 10px 0;
}

.submit-container {
color: #077b93
}
108 changes: 108 additions & 0 deletions trek.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
const URL = 'https://ada-backtrek-api.herokuapp.com/trips';

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

// LOAD TRIPS
const loadTrips = () => {
const tripsList = $('#tbody');
tripsList.empty();

reportStatus('Loading trips! Please wait...');
$('#table').show();
Copy link

Choose a reason for hiding this comment

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

same comment as below, but: the ID #table isn't a very helpful ID name! Which table is it?


axios.get(URL)
.then((response) => {
response.data.forEach((trip) => {
tripsList.append(`<tr id="${trip.id}"><td>${trip.id}</td>
<td>${trip.name}</td></tr>`);
});
reportStatus('Trips Loaded!');
})
.catch((error) => {
reportStatus('Error: ${error.message}');
});
};

// LOAD ONE TRIP

const loadTrip = (id) => {
const tripInfo = $('#trip-info');
tripInfo.empty();
const reservationForm = $('#reservation-form');
reservationForm.empty();

reportStatus('Loading trip info! Please wait...');
$('#details').show();

// GET TRIP DETAILS FROM API

axios.get(URL + `/${id}`)
.then((response) => {
// console.log(response);
tripInfo.append(`<tr><td><strong>Name: </strong> ${response.data.name}</td></tr>
<tr><td><strong>Trip ID: </strong>${response.data.id}</td></tr>
<tr><td><strong>Continent: </strong>${response.data.continent}</td></tr>
<tr><td><strong>Category: </strong>${response.data.category}</td></tr>
<tr><td><strong>Weeks: </strong>${response.data.weeks}</td></tr>
<tr><td><strong>Cost: </strong>${response.data.cost.toFixed(2)}</td></tr>
<tr><td><strong>About: </strong></br>${response.data.about}</td></tr>`);
reportStatus('Trip Info Loaded!');
reservationForm.append(`<div >
<label for="name">Trip:${response.data.name}</label>
</div>`);
reservationForm.append(`<div>
<label for="name">Name: </label>
<input type="text" name="user-name" />
</div>
<div>
<label for="email">Email: </label>
<input type="text" name="email" />
</div>
<div class="submit-container">
<input type="submit" name="add-reservation" value="Reserve" class="reserve" id="reserve${response.data.id}"/>
Copy link

Choose a reason for hiding this comment

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

Out of curiosity, why do you make the id="reserve..."? Why not just id="${response.data.id}"? Because of this you need to add the .substr(7) part on line 105

</div>`);

})
.catch((error) => {
reportStatus('Error: ${error.message}');
});
};

//RESERVE TRIP

const reserveTrip = (id) => {
reportStatus('');
Copy link

Choose a reason for hiding this comment

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

Do you need this?

reportStatus('Reserving The Trip...');

let userData = {
'name': $('input[name="user-name"]').val(),
'email': $('input[name="email"]').val(),
};
Copy link

Choose a reason for hiding this comment

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

Since this is JavaScript, all property names (keys) are assumed to be strings, so you can write this as:

  let userData = {
    name: $('input[name="user-name"]').val(),
    email: $('input[name="email"]').val(),
  };


axios.post(URL + `/${id}/reservations`, userData)
.then((response) => {
reportStatus(`Successfully reserved this trip with the name ${response.data.name}`);
})
.catch((error) => {
reportStatus(`Encountered an error: ${error.message}`);
});

$('input[name="user-name"]').val('');
$('input[name="email"]').val('');
};

// ACTION
$(document).ready(() => {
$('#load').click(loadTrips);
$('#tbody').on('click', 'tr', function () {
Copy link

Choose a reason for hiding this comment

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

something with the ID tbody doesn't make much sense 😆 because tbody doesn't help me understand what is unique about it, and IDs are to help me know what the unique identifier is. Also, it's on an element tbody

let id = $(this).attr('id');
loadTrip(id);
});

$('#reservation-form').on('click', '.reserve', function () {
let id = $(this).attr('id').substr(7);
reserveTrip(id);
});
});