Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4af750f7a7 |
@@ -29,7 +29,7 @@ const Main = ({ brdcum, bgimg }) => {
|
||||
// Set a time out for the blog data to be deleted from local storage
|
||||
setTimeout(() => {
|
||||
localStorage.removeItem("myFit--blogData");
|
||||
}, 3600);
|
||||
}, 3600000);
|
||||
} catch (error) {
|
||||
console.log("Error from blog data ", error);
|
||||
}
|
||||
|
||||
@@ -19,33 +19,14 @@ const Main = ({ brdcum }) => {
|
||||
}, [blogData]);
|
||||
|
||||
const getBlogData = async () => {
|
||||
/*
|
||||
The reason for this, is because of the breaking I had when building the blog
|
||||
I decided to save to the local storage for an hour so that it won't need to be going to the server again but I can change this
|
||||
*/
|
||||
// Saving it locally to avoid interfering with server
|
||||
if (localStorage.getItem("myFit--blogData") == null) {
|
||||
try {
|
||||
let res = await api_call.blogData();
|
||||
|
||||
// Set the blog data to local storage
|
||||
localStorage.setItem("myFit--blogData", JSON.stringify(res.data));
|
||||
setBlogData(res.data);
|
||||
// Set a time out for the blog data to be deleted from local storage
|
||||
setTimeout(() => {
|
||||
localStorage.removeItem("myFit--blogData");
|
||||
}, 3600);
|
||||
|
||||
} catch (error) {
|
||||
console.log("Error from blog data ", error);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
let data = JSON.parse(localStorage.getItem("myFit--blogData"));
|
||||
setBlogData(data);
|
||||
} catch (error) {
|
||||
console.error("Error parsing JSON data: ", error);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user