Open joshuaferr1s opened 4 years ago
Submitted for project description review.
⭐️⭐️⭐️⭐️⭐️
Awesome!! Project description looks great.
Feel free to get started.
Landing page is complete except for actual links to other pages which don't exist yet. Attached are some screenshots.
I believe it is complete! Woot! It is available here
Sweet! Would you like UI feedback or a code review?
UI feedback would be good. I just chatted with the API maintainers and they gave me a cool idea for an addition to functionality 😄
Cool!
Some feedback:
I updated the launch date picker UI and functionality on data return.
I like it! It's a much nicer experience to at least get some result back.
Yeah, I like what is has become. Actually useful and functional.
Would love a UI/UX and code review :smile:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
'
or "
, don't mix.
makeRocketElement
function is a little offfetchRocketData
has quite a few long linesfetchRocketData
could pottentially be split into 1 or 2 functions.fetchRocketData
function name is confusing compared with makeRocketFetch
, fetchRocketData
technically doesn't fetch
it handles all the logic. Might think of a better name. @sk1nni in the chat suggests: prepareRocketLauch
allBirthdayLaunchesPagination
is unused.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);
};
Thanks for the review! I have addressed the concerns you raised (hopefully) and updated the pagination display so it is easier on the eyes.
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: