Skip to content

Commit

Permalink
Feat(JS) Added local storage
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorSvertoka committed Dec 17, 2023
1 parent 2744c13 commit 5c9f4ad
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/js/02-quote.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,25 @@ const apiService = new APIService();
quote();

async function quote() {
const quoteData = JSON.parse(localStorage.getItem('quoteDay'));
const currentDate = new Date();

currentDate.setDate(currentDate.getDate());

const newData = currentDate.toISOString().split('T')[0];

if (quoteData?.currentDate === newData) {
return;
}

try {
const data = await apiService.getQuote();
const combinedData = {
data: data,
currentDate: newData,
};

localStorage.setItem('quoteDay', JSON.stringify(combinedData));
displayQuote(data);
} catch (error) {
console.log(error);
Expand Down

0 comments on commit 5c9f4ad

Please sign in to comment.