From 935bd94eda806984b49d8e80b78ead22f4ffbaa2 Mon Sep 17 00:00:00 2001 From: Jamila Date: Wed, 23 May 2018 11:28:04 -0700 Subject: [PATCH 1/7] forgot to commit at first, list of trips shows --- html.css | 0 index.html | 26 ++++++++++++++++++ index.js | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 html.css create mode 100644 index.html create mode 100644 index.js diff --git a/html.css b/html.css new file mode 100644 index 00000000..e69de29b diff --git a/index.html b/index.html new file mode 100644 index 00000000..bd479394 --- /dev/null +++ b/index.html @@ -0,0 +1,26 @@ + + + + + Trekitup + + + + + +
+

Get Trekkin!

+
+
+
+

See all trips

+
    + +
+
+ +
+ + + diff --git a/index.js b/index.js new file mode 100644 index 00000000..79ce6221 --- /dev/null +++ b/index.js @@ -0,0 +1,78 @@ + +const allTripsURL = 'https://ada-backtrek-api.herokuapp.com/trips' + +const reportStatus = (message) => { + $('#status-message').html(message); +}; + +const reportError = (message, errors) => { + let content = `

${message}

"; + reportStatus(content); +}; + + +const listallTrips = () => { + const tripsList = $('#tripList') + tripsList.empty(); + + axios.get(allTripsURL) + .then((response) => { + reportStatus(`Successfully loaded ${response.data.length} Wonders`); + console.log(response); + const result = response.data + result.forEach((place) => { + tripsList.append(`
  • ${place.name}
  • `); + }) + }) + .catch((error) => { + reportStatus(`Encountered an error while loading trips: ${error.message}`); + console.log(error); + }); + +}; //end of listallTrips + +const tripDetails = (trip) => { + singleTripUrl = 'https://ada-backtrek-api.herokuapp.com/trips/' + console.log(trip); + + axios.get(singleTripUrl + trip.id) + .then((response) => { + reportStatus(`Successfully loaded ${response.data.length} Wonders`); + console.log(response); + const result = response.data + for (attr in result) { + } + }((place) => { + tripsList.append(`
  • ${place.name}
  • `); + }) + .catch((error) => { + reportStatus(`Encountered an error while loading trips: ${error.message}`); + console.log(error); + }); + +}); + +}; //end of Trip details + + + +$(document).ready(() => { + $('#load').click(listallTrips); + + $('ul').on('click', 'li', function(){ + + const trip = this + + tripDetails(trip); + + + + }); + +}); From 012a906367b04934cfca2f5f6219863036000c7b Mon Sep 17 00:00:00 2001 From: Jamila Date: Wed, 23 May 2018 16:32:50 -0700 Subject: [PATCH 2/7] individual trips functional --- index.html | 66 +++++++++++++++++++++++++++++++++++++----------------- index.js | 45 +++++++++++++++++++++++++++++++------ 2 files changed, 84 insertions(+), 27 deletions(-) diff --git a/index.html b/index.html index bd479394..e828d3dc 100644 --- a/index.html +++ b/index.html @@ -1,26 +1,52 @@ - - - Trekitup - - - -
    -

    Get Trekkin!

    -
    -
    -
    -

    See all trips

    -
      - -
    -
    - -
    - - + + diff --git a/index.js b/index.js index 79ce6221..95e50803 100644 --- a/index.js +++ b/index.js @@ -23,7 +23,7 @@ const listallTrips = () => { axios.get(allTripsURL) .then((response) => { - reportStatus(`Successfully loaded ${response.data.length} Wonders`); + reportStatus(`Successfully loaded ${response.data.length}`); console.log(response); const result = response.data result.forEach((place) => { @@ -38,28 +38,51 @@ const listallTrips = () => { }; //end of listallTrips const tripDetails = (trip) => { - singleTripUrl = 'https://ada-backtrek-api.herokuapp.com/trips/' + + const aboutTrip = $('#details') + const singleTripUrl = 'https://ada-backtrek-api.herokuapp.com/trips/' console.log(trip); axios.get(singleTripUrl + trip.id) .then((response) => { - reportStatus(`Successfully loaded ${response.data.length} Wonders`); + reportStatus(`Successfully loaded ${response.data.length}`); console.log(response); const result = response.data for (attr in result) { + aboutTrip.append(`
  • ${result[attr]}
  • `); } - }((place) => { - tripsList.append(`
  • ${place.name}
  • `); + }) .catch((error) => { reportStatus(`Encountered an error while loading trips: ${error.message}`); console.log(error); }); -}); - }; //end of Trip details +const createReservation = (reservation, trip) => { + console.log(reservation); + console.log(trip); + + const reservationURL = 'https://ada-backtrek-api.herokuapp.com/trips/1/reservations' + + axios.get(singleTripUrl + trip.id) + .then((response) => { + reportStatus(`Successfully loaded ${response.data.length}`); + console.log(response); + const result = response.data + for (attr in result) { + aboutTrip.append(`
  • ${result[attr]}
  • `); + } + + }) + .catch((error) => { + reportStatus(`Encountered an error while loading trips: ${error.message}`); + console.log(error); + }); + +}; //end of createReservation + $(document).ready(() => { @@ -71,8 +94,16 @@ $(document).ready(() => { tripDetails(trip); + $('form').submit( function(event) { + event.preventDefault(); + const reservation = this + console.log(trip); + createReservation(reservation, trip); + + }); }); + }); From 44468faeea821ffe236388075ee10dff15565c64 Mon Sep 17 00:00:00 2001 From: Jamila Date: Wed, 23 May 2018 17:46:12 -0700 Subject: [PATCH 3/7] can create a reservation --- index.html | 6 +++--- index.js | 23 ++++++++++++----------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/index.html b/index.html index e828d3dc..37d063ee 100644 --- a/index.html +++ b/index.html @@ -18,7 +18,7 @@

    See all trips