diff --git a/index.css b/index.css new file mode 100644 index 00000000..cb8274af --- /dev/null +++ b/index.css @@ -0,0 +1,42 @@ +body { + padding: 10px; + background-color: gainsboro; + text-align: center; +} + +main { + display: grid; + grid-template-columns: 1fr 1fr; +} + +ul { + list-style: none; +} + +.status-message { + font-weight: 600; + padding: 10px; + font-size: 1rem; +} + +.trip-list { + padding-top: 10px; +} + +.trip-info { + height: 50vh; + overflow: scroll; +} + +.current-trips { + grid-column: 1 / 2; +} + +.trip-detail { + grid-column: 2 / 3; +} + +#reserve-form { + text-align: center; + padding-top: 20px; +} diff --git a/index.html b/index.html new file mode 100644 index 00000000..0f17fc00 --- /dev/null +++ b/index.html @@ -0,0 +1,36 @@ + + +
+ +${capitalize(field)}: ${problem}
`); + } + } +}; + +const displayNoContentError = (response) => { + reportStatus(`Request failed with status code ${response.status}: ${response.statusText}.`); +}; + +const capitalize = (string) => { + return string.replace(/^\w/, c => c.toUpperCase()); +} + +const sendGetRequest = (id) => { + const buildGetRequest = () => { + reportStatus('Loading...'); + axios.get(URL + id) + .then((response) => { + if (response.status === 204) { + displayNoContentError(response); + } else { + let callback = response.data.length ? parseTripCollection : parseIndividualTrip + parseGetResponse(response, callback) + } + }) + .catch((error) => { + displayError(error); + }); + }; + return buildGetRequest; +}; + +const parseGetResponse = (response, callback) => { + let tripData = response.data + let element = callback === parseTripCollection ? $('#trip-list') : $('#trip-detail-list') + element.empty(); + callback(tripData, element); +}; + +const parseTripCollection = (tripData, element) => { + reportStatus(`Successfully loaded ${tripData.length} trips.`) + $('.form-errors').empty(); + tripData.forEach((trip) => { + element.append( + ``); + }); +} + +const parseIndividualTrip = (tripData, element) => { + reportStatus(`Successfully loaded ${tripData.name}.`) + $('.form-errors').empty(); + element.append(`${tripData.about}
`) + appendResForm(tripData); +} + +const appendResForm = (tripData) => { + $('#reserve-form').empty(); + $('#reserve-form').append( + `