Fix loading of broken basket

This commit is contained in:
Michał Gdula 2024-05-06 14:57:39 +01:00
parent 503f47fd71
commit cf385e5875
2 changed files with 3 additions and 9 deletions

View file

@ -4,14 +4,7 @@ import { type CartItem, type Item } from "./types";
import { getItemByUUID, postVerifyCart } from "./test-api";
function getLocal(): Record<string, CartItem> {
let localData: Record<string, CartItem> = {};
try {
localData = JSON.parse(localStorage.getItem("basket"));
} catch (error) {
console.error("Could parse basket JSON:", error);
return localData;
}
let localData: Record<string, CartItem> = JSON.parse(localStorage.getItem("basket")) || {};
postVerifyCart(localData)
.then((data: Record<string, CartItem>) => {
@ -19,6 +12,7 @@ function getLocal(): Record<string, CartItem> {
})
.catch((error) => {
console.error("Could not load basket:", error);
return <Record<string, CartItem>>{};
});
return localData;