Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Tadjiev Codes
Tadjiev Codes
9,626 Points

Fetch API calls

Dear Folks, If anyone pls could help to understand how to work with this exercise.
I should make Ajax calls only when the “From/To” date selection changes, if dates have not changed I should not make another Ajax call to get the same data. I guess I need to familiarize myself with local storage to perform some validations. I tried to write some code but I need to check if item exists in local storage then just don't run another async Fetch call. advance)

8 Answers

Tadjiev Codes
Tadjiev Codes
9,626 Points

When I add this inside the returndates function within the loop there

 for (let j = 0; j < dataList.length; j++) {
            let dataListDate = dataList[j].date;

            if (dataListDate != data) {
                localStorage.setItem('recentDates', JSON.stringify(dataListDate));
            } else {
                localStorage.getItem('recentDates', JSON.parse(dataListDate));
            }



        } // inner loop

I get actually the date string but only the last date string not all of them

Tadjiev Codes
Tadjiev Codes
9,626 Points

So the only thing I need now is to realize how to target the whole collection of date strings instead of the last one

Tadjiev Codes
Tadjiev Codes
9,626 Points

Dear Mr.Steven Steven Parker .Could you suggest any way to achieve this ? Maybe even without the local storage I could do a validation if the data exists in the array then just don’t run another Fetch call. Thanks

Tadjiev Codes
Tadjiev Codes
9,626 Points

I watched the local storage course yesterday and coded that along with the video. But I don't seem to understand how to set that validation yet.

Tadjiev Codes
Tadjiev Codes
9,626 Points

And is there a limit with space of 5 MBS in LocalStorage? Cuz when I run it some images load super slowly or don't even load at first. I heard there's a limit of 5 MBS somewhere up to 100 MBS it's said. So it's a bit confusing. And that for production this is not really good as the browser can't do anything while loading it. But anyway this is just an exercise. It's not a production.

Tadjiev Codes
Tadjiev Codes
9,626 Points

What I realized now that I shouldn't actually store the whole nasaDays array in the local storage.
But only the data that's received in the input of the date picker lets say from 01 till 05 which comes back as a string and then if the same string is there just don't make another Fetch API call. Though how to achieve still remains a big question

Tadjiev Codes
Tadjiev Codes
9,626 Points

Because if I send the whole data images, videos. That would be stupid I guess. It would occupy unnecessary space in the LocalStorage. Just by storing date strings, I would save on the space for sure

Tadjiev Codes
Tadjiev Codes
9,626 Points

Steven Parker Mr.Steven, are you still here? I just wanted ur little suggestion