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