Skip to content

Commit

Permalink
Merge pull request #199 from starboardcoop/issue/198
Browse files Browse the repository at this point in the history
Issue/198 - Remove API caching
  • Loading branch information
dillonfagan authored Nov 28, 2022
2 parents 3d9783c + 0464043 commit 8a2e188
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 deletions.
22 changes: 19 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 1 addition & 20 deletions src/routes/_api/things.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,6 @@
async function getAll() {
let data;
let now = new Date();

let previousRefresh = new Date(localStorage.getItem("previousRefresh"));
if (Math.abs(now - previousRefresh) > 120000) {
data = _getAll();
localStorage.setItem("previousRefresh", now.toUTCString());
} else {
data = JSON.parse(localStorage.getItem("data"));

console.log('Previous data refreshed.');
}

return data;
}

async function _getAll() {
const getAll = async () => {
const result = await fetch(`/.netlify/functions/things`);
let data = await result.json();
localStorage.setItem("data", JSON.stringify(data));

data.things = data.things.filter(thing => thing.categories);

console.log('Refreshed data from API.');
Expand Down
Binary file removed static/2.png
Binary file not shown.
Binary file removed static/collaboration.png
Binary file not shown.
Binary file removed static/join.png
Binary file not shown.
Binary file removed static/maintenance.png
Binary file not shown.

0 comments on commit 8a2e188

Please sign in to comment.