smackeem / SkyLoom-Project-3

0 stars 0 forks source link

Glow Frontend: Service & Api Utility, Design, Protective Routes, Logic #4

Open smackeem opened 10 months ago

smackeem commented 10 months ago

My favorite part of every project is always the small helper functions that I keep having to create to convert the data from the API to something users can read. So my AJAX calls and helper functions like my processFlights service are what I am most proud of from the frontend. As well as the design. I wanted to get more practice with styling libraries and I did very much that. I have grown more in that area and I am proud of that. The project is very simple, in my opinion, but the logic behind every click and page render is so complex. And that too makes me smile.

I had to create this utility service to filter through the API response to get the data I needed

const processFlights = (apiResponse) => {
    const processedFlights = [];

    for (const flight of apiResponse.data) {
      const itineraries = flight.itineraries;
      const price = `${flight.price.total} ${flight.price.currency}`;
      const validatingAirlineCodes = flight.validatingAirlineCodes; 
      const numberOfBookableSeats = flight.numberOfBookableSeats

      const flightDetails = {
        price,
        numberOfBookableSeats,
        itineraries,
        validatingAirlineCodes,
        segments: [],
      };

      for (const itinerary of itineraries) {

        const segments = itinerary.segments;

        for (const segment of segments) {
          const departure = segment.departure;
          const arrival = segment.arrival;
          const duration = segment.duration;
          const isNonStop = segment.numberOfStops === 0;

          const segmentDetails = {
            departureDateTime: departure.at,
            duration,
            isNonStop,
            originLocation: apiResponse.dictionaries.locations[departure.iataCode],
            destinationLocation: apiResponse.dictionaries.locations[arrival.iataCode],
          };

          flightDetails.segments.push(segmentDetails);
        }
      }
      processedFlights.push(flightDetails);
    }
    return processedFlights;
};
TimHuitt commented 10 months ago

Utilities

UI/UX

Protective Routes

Code Review