2022-11-10 01:35:41 +00:00
|
|
|
/**
|
|
|
|
* @returns {Array<Object>} An array of reviews found in localStorage
|
|
|
|
*/
|
2022-11-10 21:22:32 +00:00
|
|
|
export function getReviewsFromStorage() {
|
2022-11-18 02:45:53 +00:00
|
|
|
if (!(localStorage.getItem("activeIDS"))) {
|
|
|
|
// we wanna init the active ID array and start the nextID count
|
|
|
|
localStorage.setItem("activeIDS", JSON.stringify([]));
|
|
|
|
localStorage.setItem("nextID", JSON.stringify(0));
|
2022-11-10 01:35:41 +00:00
|
|
|
}
|
2022-11-18 02:45:53 +00:00
|
|
|
//iterate thru activeIDS
|
|
|
|
let activeIDS = JSON.parse(localStorage.getItem("activeIDS"));
|
|
|
|
let reviews = []
|
|
|
|
for (let i = 0; i < activeIDS.length; i++) {
|
|
|
|
let currReview = JSON.parse(localStorage.getItem('review'+activeIDS[i]));
|
|
|
|
reviews.push(currReview);
|
|
|
|
}
|
|
|
|
return reviews;
|
2022-11-10 01:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Takes in an array of reviews, converts it to a string, and then
|
|
|
|
* saves that string to 'reviews' in localStorage
|
|
|
|
* @param {Array<Object>} reviews An array of reviews
|
|
|
|
*/
|
2022-11-10 21:22:32 +00:00
|
|
|
export function saveReviewsToStorage(reviews) {
|
2022-11-18 02:45:53 +00:00
|
|
|
localStorage.setItem(`review${reviewId}`, JSON.stringify(reviews));
|
2022-11-11 20:07:58 +00:00
|
|
|
}
|