mtgcsv/js/storage.js

25 lines
633 B
JavaScript
Raw Permalink Normal View History

2024-08-22 00:03:33 +02:00
// 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
}