mirror of
https://github.com/Fluffy-Bean/TastyBites.git
synced 2025-01-29 17:48:28 +00:00
Cache errors
Missing `;`
This commit is contained in:
parent
7f7fa3b3ab
commit
9761e4b0aa
|
@ -1,7 +1,6 @@
|
|||
import type { Writable } from "svelte/store";
|
||||
import { get, writable } from "svelte/store";
|
||||
import { type Writable, get, writable } from "svelte/store";
|
||||
|
||||
import { type CartItem } from './types';
|
||||
import {type CartItem, type Item } from './types';
|
||||
import { getItemByUUID, postVerifyCart } from "./test-api";
|
||||
|
||||
|
||||
|
@ -32,14 +31,14 @@ function createCartStore() {
|
|||
});
|
||||
} else {
|
||||
await getItemByUUID(uuid)
|
||||
.then((data) => {
|
||||
.then((data: Item) => {
|
||||
cart.update((cart: Record<string, CartItem>) =>
|
||||
Object.assign({}, cart, {[uuid]: {
|
||||
uuid: uuid,
|
||||
amount: amount,
|
||||
data: data,
|
||||
}})
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -2,10 +2,7 @@ import { type CartItem, type Item } from './types';
|
|||
import TestData from './test-data';
|
||||
|
||||
|
||||
let cache = {
|
||||
announcement_banner: undefined,
|
||||
popular_today: undefined,
|
||||
};
|
||||
let cache: Record<string, any> = {};
|
||||
|
||||
|
||||
// @ts-ignore
|
||||
|
@ -16,28 +13,28 @@ async function fakeDelay(timeout: number = 1000) {
|
|||
|
||||
|
||||
export async function getAnnouncements(): Promise<{image: string}> {
|
||||
if (cache.announcement_banner) {
|
||||
return cache.announcement_banner;
|
||||
if (cache["announcement_banner"] !== undefined) {
|
||||
return cache["announcement_banner"];
|
||||
}
|
||||
await fakeDelay(200)
|
||||
await fakeDelay(200);
|
||||
|
||||
const data = {
|
||||
image: "/BannerExampleImage.jpg",
|
||||
};
|
||||
cache.announcement_banner = data;
|
||||
cache["announcement_banner"] = data;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
export async function getPopularToday(): Promise<Item[]> {
|
||||
if (cache.popular_today) {
|
||||
return cache.popular_today;
|
||||
if (cache["popular_today"] !== undefined) {
|
||||
return cache["popular_today"];
|
||||
}
|
||||
await fakeDelay(200)
|
||||
await fakeDelay(200);
|
||||
|
||||
const data: Item[] = TestData;
|
||||
cache.popular_today = data;
|
||||
cache["popular_today"] = data;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
@ -63,7 +60,7 @@ export async function getMenuItems(): Promise<{name: string, items: Item[]}[]> {
|
|||
|
||||
|
||||
export async function getItemsByUUID(items: string[]): Promise<Item[]> {
|
||||
await fakeDelay(200)
|
||||
await fakeDelay(200);
|
||||
|
||||
let data: Item[] = [];
|
||||
|
||||
|
@ -103,7 +100,7 @@ export async function getItemByUUID(uuid: string): Promise<Item> {
|
|||
|
||||
|
||||
export async function postContactEmail(name: string, email: string, message: string): Promise<string> {
|
||||
await fakeDelay(200)
|
||||
await fakeDelay(200);
|
||||
|
||||
if (!name) {
|
||||
throw new Error("Name missing");
|
||||
|
@ -121,19 +118,20 @@ export async function postContactEmail(name: string, email: string, message: str
|
|||
}
|
||||
|
||||
export async function postVerifyCart(currentCartData: Record<string, CartItem>): Promise<Record<string, CartItem>> {
|
||||
let verifiedItems: Item[] = []
|
||||
let verifiedItems: Item[] = [];
|
||||
|
||||
await getItemsByUUID(Object.keys(currentCartData))
|
||||
.then((data) => {
|
||||
verifiedItems = data
|
||||
verifiedItems = data;
|
||||
})
|
||||
.catch(() => {
|
||||
return new Error("Could not collect new cart information")
|
||||
return new Error("Could not collect new cart information");
|
||||
});
|
||||
|
||||
let newCartData: Record<string, CartItem> = {};
|
||||
|
||||
Object.entries(currentCartData).forEach(([key, value]) => {
|
||||
verifiedItems.forEach((verifiedItem) => {
|
||||
verifiedItems.forEach((verifiedItem: Item) => {
|
||||
if (verifiedItem.uuid === key) {
|
||||
newCartData[key] = {
|
||||
uuid: value.uuid,
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
export let params;
|
||||
|
||||
$: item = getItemByUUID(params.uuid)
|
||||
$: item = getItemByUUID(params.uuid);
|
||||
$: popularToday = getPopularToday();
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Reference in a new issue