Skip to content

Commit

Permalink
Refactor customQuote validation logic for improved efficiency and cla…
Browse files Browse the repository at this point in the history
…rity (#131)
  • Loading branch information
marceloams committed Dec 4, 2024
1 parent 8d91674 commit d8d23d8
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/api/services/quotesService.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,26 @@ const getQuote = async (quoteObj) => {

if (apiResponse.length > 0) {
apiResponse = apiResponse[Math.floor(getQuoteIndex(apiResponse.length, quoteType))];
if (!apiResponse.quote && !apiResponse.author) {
apiResponse = await requestApi(url);
} else {

if (apiResponse.quote && apiResponse.author) {
isCustomQuote = true;
}
} else {
apiResponse = await requestApi(url);
}
}
else if (quoteCategory) {
apiResponse = quoteFromCategory[quoteCategory];
apiResponse = apiResponse[Math.floor(getQuoteIndex(apiResponse.length, quoteType))];
isCustomQuote = true;
}
else {

if(!isCustomQuote) {
apiResponse = await requestApi(url);
apiResponse = apiResponse[Math.floor(getQuoteIndex(apiResponse.length, quoteType))];
}

const template = new Template();
template.setTheme(theme);
template.setData(isCustomQuote ? apiResponse : apiResponse[Math.floor(getQuoteIndex(apiResponse.length, quoteType))]);
template.setData(apiResponse);
template.setFont(font);
template.setAnimation(animation);
template.setBorderColor(borderColor);
Expand Down

0 comments on commit d8d23d8

Please sign in to comment.