CodingGarden / seedling-school-01-frontend-project

For your first project, you will build a frontend website with HTML, CSS and JavaScript. The website will communicate and integrate with a 3rd party Web API.
MIT License
106 stars 14 forks source link

MyLaunch Project Submission #5

Open joshuaferr1s opened 4 years ago

joshuaferr1s commented 4 years ago

MyLaunch

Your Name / Title

Joshua Ferris

Project Description

For those interested in things that happened the day they were born this is perfect! Everyone loves space and so by entering your birthday (or any other date) you can find out if a rocket was launched the day you were born thanks to the Launch Library API

What 3rd Party Web API do you plan to use?

Which of the following describes you:

joshuaferr1s commented 4 years ago

Submitted for project description review.

w3cj commented 4 years ago

⭐️⭐️⭐️⭐️⭐️

Awesome!! Project description looks great.

Feel free to get started.

joshuaferr1s commented 4 years ago

Landing page is complete except for actual links to other pages which don't exist yet. Attached are some screenshots.

Screen Shot 2019-11-21 at 9 52 47 PM Screen Shot 2019-11-21 at 9 53 00 PM Screen Shot 2019-11-21 at 9 53 04 PM
joshuaferr1s commented 4 years ago

I believe it is complete! Woot! It is available here

w3cj commented 4 years ago

Sweet! Would you like UI feedback or a code review?

joshuaferr1s commented 4 years ago

UI feedback would be good. I just chatted with the API maintainers and they gave me a cool idea for an addition to functionality 😄

w3cj commented 4 years ago

Cool!

Some feedback:

joshuaferr1s commented 4 years ago
joshuaferr1s commented 4 years ago

I updated the launch date picker UI and functionality on data return.

w3cj commented 4 years ago

I like it! It's a much nicer experience to at least get some result back.

joshuaferr1s commented 4 years ago

Yeah, I like what is has become. Actually useful and functional.

joshuaferr1s commented 4 years ago

Would love a UI/UX and code review :smile:

w3cj commented 4 years ago

UI Review

Things I Like

Things to improve

Checklist

w3cj commented 4 years ago

Code Review Checklist

README

HTML

JavaScript

CSS

Suggested Refactor

A possible way to refactor the fetchRocketData function:


const makeRocketFetch = async (startDate, endDate, offset = 0) => {
  const response = await fetch(`${API_URL}${startDate}/${endDate}?limit=${FETCH_LIMIT}&offset=${offset}`);
  const data = await response.json();
  if (data.launches.length <= 0) {
    throw new Error(errorMessages.noLaunchesFoundForDate);
  }

  if (data.status === 'error' && data.msg === 'None found') {
    throw new Error(errorMessages.noLaunchesFoundLookBelow);
  }

  if (data.status === 'error') {
    throw new Error(data.msg);
  }

  if (data.launches.length <= 0) {
    throw new Error(errorMessages.noLaunchesFoundLookBelow);
  }
  return {
    ...data,
    startDate,
    endDate,
  };
};

const errorMessages = {
  noLaunchesFoundLookBelow: 'No launches found for your birthday. Look below however for every launch since your birthday.',
  noLaunchesFoundForDate: 'No launches found for that date.'
};

function getEndDate() {
  const curDate = new Date();
  const [year, month, day] = dateElement.value.split('-');
  const endDate = new Date(curDate.getFullYear(), curDate.getMonth(), curDate.getFullYear() === Number(year) && curDate.getMonth() + 1 === Number(month) ? Number(day) + 1 : Number(day));
  return endDate;
}

function addSearchResultToPage() {
  let nonMatches = 0;
  launchResponse.launches.forEach((launch) => {
    if (getFormattedDate(new Date(launch.net)) !== dateElement.value) {
      if (launchResponse.launches.length === 1) {
        throw new Error(errorMessages.noLaunchesFoundLookBelow);
      } else {
        nonMatches += 1;
        return;
      }
    } else {
      birthdayLaunchesContainer.innerHTML += makeRocketElement(launch);
    }
  });
  if (nonMatches === launchResponse.launches.length) throw new Error(errorMessages.noLaunchesFoundLookBelow);
}

const fetchRocketData = async () => {
  try {
    if (!dateElement.validity.valid) throw new Error(dateElement.validationMessage);
    logoElement.classList.toggle('animate', true);
    const endDate = getEndDate();
    launchResponse = await makeRocketFetch(dateElement.value, getFormattedDate(endDate));
    allLaunchesSince.style.display = '';
    updatePaginationButtons();
    updateDisplayedRockets();
    errorElement.classList.toggle('hidden', true);
    addSearchResultToPage();
  } catch (error) {
    birthdayLaunchesContainer.innerHTML = '';
    errorElement.classList.toggle('hidden', false);
    errorMessageElement.textContent = error.message;
  }
  logoElement.classList.toggle('animate', false);
};
joshuaferr1s commented 4 years ago

Thanks for the review! I have addressed the concerns you raised (hopefully) and updated the pagination display so it is easier on the eyes.