style: format code with Prettier

This commit fixes the style issues introduced in 6e31b44 according to the output
from Prettier.

Details: None
This commit is contained in:
deepsource-autofix[bot] 2024-05-04 15:26:36 +00:00 committed by GitHub
parent 6e31b44137
commit cd6fdf3b29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 131 additions and 105 deletions

View file

@ -1,13 +1,13 @@
import TestData from '%/lib/test-data.ts';
import TestData from "%/lib/test-data.ts";
export async function getPopularToday() {
const res = await fetch("/api/items")
const data = res.json()
const res = await fetch("/api/items");
const data = res.json();
if (res.ok) {
return data
return data;
} else {
throw new Error("Failed to fetch popular today")
throw new Error("Failed to fetch popular today");
}
}

View file

@ -1,9 +1,8 @@
import { type Writable, get, writable } from "svelte/store";
import {type CartItem, type Item } from './types';
import { type CartItem, type Item } from "./types";
import { getItemByUUID, postVerifyCart } from "./test-api";
// Load content from localstorage
let local: Record<string, CartItem> = {};
try {
@ -16,7 +15,7 @@ try {
throw error; // Hot potato style
});
} catch {
console.error("Failed to load cart")
console.error("Failed to load cart");
}
// Store function
@ -30,16 +29,17 @@ function createCartStore() {
return cart;
});
} else {
await getItemByUUID(uuid)
.then((data: Item) => {
cart.update((cart: Record<string, CartItem>) =>
Object.assign({}, cart, {[uuid]: {
await getItemByUUID(uuid).then((data: Item) => {
cart.update((cart: Record<string, CartItem>) =>
Object.assign({}, cart, {
[uuid]: {
uuid: uuid,
amount: amount,
data: data,
}})
);
});
},
})
);
});
}
cart.update((cart: Record<string, CartItem>) => {
@ -47,7 +47,7 @@ function createCartStore() {
delete cart[uuid];
}
return cart;
})
});
}
function getEntries(): [string, CartItem][] {
@ -69,7 +69,7 @@ function createCartStore() {
function getTotalPrice(): number {
let totalCartPrice: number = 0;
Object.values(get(cart)).forEach((item: CartItem) => {
totalCartPrice += (item.amount * item.data.price);
totalCartPrice += item.amount * item.data.price;
});
return totalCartPrice;
}
@ -78,7 +78,7 @@ function createCartStore() {
cart.update((cart) => {
delete cart[uuid];
return cart;
})
});
}
return {
@ -89,7 +89,7 @@ function createCartStore() {
getTotalLength,
getTotalPrice,
removeByUUID,
}
};
}
// Create store

View file

@ -1,18 +1,15 @@
import { type CartItem, type Item } from './types';
import TestData from './test-data';
import { type CartItem, type Item } from "./types";
import TestData from "./test-data";
let cache: Record<string, any> = {};
// @ts-ignore
async function fakeDelay(timeout: number = 1000) {
// @ts-ignore
await new Promise((resolve: TimerHandler) => setTimeout(resolve, timeout));
}
export async function getAnnouncements(): Promise<{image: string}> {
export async function getAnnouncements(): Promise<{ image: string }> {
if (cache["announcement_banner"] !== undefined) {
return cache["announcement_banner"];
}
@ -26,7 +23,6 @@ export async function getAnnouncements(): Promise<{image: string}> {
return data;
}
export async function getPopularToday(): Promise<Item[]> {
if (cache["popular_today"] !== undefined) {
return cache["popular_today"];
@ -39,8 +35,9 @@ export async function getPopularToday(): Promise<Item[]> {
return data;
}
export async function getMenuItems(): Promise<{name: string, items: Item[]}[]> {
export async function getMenuItems(): Promise<
{ name: string; items: Item[] }[]
> {
await fakeDelay(20);
return [
{
@ -58,7 +55,6 @@ export async function getMenuItems(): Promise<{name: string, items: Item[]}[]> {
];
}
export async function getItemsByUUID(items: string[]): Promise<Item[]> {
await fakeDelay(200);
@ -79,7 +75,6 @@ export async function getItemsByUUID(items: string[]): Promise<Item[]> {
return data;
}
export async function getItemByUUID(uuid: string): Promise<Item> {
let data: Item[];
@ -98,8 +93,11 @@ export async function getItemByUUID(uuid: string): Promise<Item> {
return data[0];
}
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);
if (!name) {
@ -117,7 +115,9 @@ export async function postContactEmail(name: string, email: string, message: str
return "Check your email to confirm the message!";
}
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[] = [];
await getItemsByUUID(Object.keys(currentCartData))

View file

@ -1,4 +1,4 @@
import type { Item } from './types';
import type { Item } from "./types";
import { Labels } from "./types";
const TestData: Item[] = [

View file

@ -7,18 +7,18 @@ export enum Labels {
}
export interface Item {
uuid: string,
name: string,
price: number,
detail?: string,
labels: Labels[],
image?: string,
uuid: string;
name: string;
price: number;
detail?: string;
labels: Labels[];
image?: string;
}
// UUID is stored in both Item and CartItem, this isn't the best, I don't like it
// But it's the simplest way of doing this shit
export interface CartItem {
uuid: string,
amount: number,
data: Item,
uuid: string;
amount: number;
data: Item;
}

View file

@ -1,6 +1,6 @@
export function expandOnTyping(element) {
element.oninput = (event) => {
event.target.style.height = "";
event.target.style.height = (event.target.scrollHeight + 2) + "px";
}
event.target.style.height = event.target.scrollHeight + 2 + "px";
};
}