mirror of
https://github.com/cse110-fa22-group29/cse110-fa22-group29.git
synced 2025-09-09 16:17:22 +00:00
updated crud features to work better
Co-authored-by: look-its-ashton <look-its-ashton@users.noreply.github.com> Co-authored-by: Kara Hoagland <KH-Cl@users.noreply.github.com> Co-authored-by: Gavyn Ezell <ezellgavyn@gmail.com>
This commit is contained in:
@@ -2,11 +2,19 @@
|
||||
* @returns {Array<Object>} An array of reviews found in localStorage
|
||||
*/
|
||||
export function getReviewsFromStorage() {
|
||||
let result = JSON.parse(localStorage.getItem("reviews"));
|
||||
if (result) {
|
||||
return result;
|
||||
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));
|
||||
}
|
||||
return new Array(0);
|
||||
//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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -15,5 +23,5 @@ export function getReviewsFromStorage() {
|
||||
* @param {Array<Object>} reviews An array of reviews
|
||||
*/
|
||||
export function saveReviewsToStorage(reviews) {
|
||||
localStorage.setItem("reviews", JSON.stringify(reviews));
|
||||
localStorage.setItem(`review${reviewId}`, JSON.stringify(reviews));
|
||||
}
|
||||
|
Reference in New Issue
Block a user