Fix loading of broken basket

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

View file

@ -14,7 +14,7 @@ tmp_dir = "tmp"
follow_symlink = false
full_bin = ""
include_dir = ["front", "api", "cmd"]
include_ext = ["go", "tpl", "tmpl", "html", "js", "svelte", "scss"]
include_ext = ["go", "tpl", "tmpl", "html", "js", "ts", "svelte", "scss"]
include_file = []
kill_delay = "0s"
log = "build-errors.log"

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;