mtgcsv/js/storage.js
2024-08-21 18:03:33 -04:00

25 lines
633 B
JavaScript

// storage.js
export function saveCollection(cardList) {
localStorage.setItem('cardList', JSON.stringify(cardList));
}
export function loadCollection() {
const savedCollection = localStorage.getItem('cardList');
if (savedCollection) {
return JSON.parse(savedCollection);
}
return [];
}
export function updateCardDetails(cardData) {
const cardList = loadCollection();
cardList.push(cardData);
saveCollection(cardList);
}
export function clearCollection(cardList) {
cardList.length = 0; // Clear the cardList array
saveCollection(cardList); // Save the empty list to localStorage
}