mirror of
https://github.com/Fluffy-Bean/TastyBites.git
synced 2025-05-21 02:44:55 +00:00
Update test api to TypeScript for better type handling
This commit is contained in:
parent
04f7d40e52
commit
4f0ecd33e4
7 changed files with 26 additions and 31 deletions
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { getAnnouncements } from '%/lib/test-api.js';
|
import { getAnnouncements } from '%/lib/test-api.ts';
|
||||||
|
|
||||||
let announcement = getAnnouncements();
|
let announcement = getAnnouncements();
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
import Items from '%/lib/test-data.js';
|
import Items from '%/lib/test-data.js';
|
||||||
|
|
||||||
|
|
||||||
let cache = {};
|
let cache = {
|
||||||
|
announcement_banner: null,
|
||||||
|
popular_today: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
async function fakeDelay(timeout = 1000) {
|
async function fakeDelay(timeout: number = 1000) {
|
||||||
await new Promise(resolve => setTimeout(resolve, timeout));
|
await new Promise(resolve => setTimeout(resolve, timeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function getAnnouncements() {
|
export async function getAnnouncements() {
|
||||||
if (cache.announcement_banner !== undefined) {
|
if (cache.announcement_banner) {
|
||||||
return cache.announcement_banner;
|
return cache.announcement_banner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +27,7 @@ export async function getAnnouncements() {
|
||||||
|
|
||||||
|
|
||||||
export async function getPopularToday() {
|
export async function getPopularToday() {
|
||||||
if (cache.popular_today !== undefined) {
|
if (cache.popular_today) {
|
||||||
return cache.popular_today;
|
return cache.popular_today;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,26 +58,7 @@ export async function getMenuItems() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function getItemByUUID(uuid) {
|
export async function getItemsByUUID(items: string[]) {
|
||||||
let data;
|
|
||||||
|
|
||||||
Items.forEach((item) => {
|
|
||||||
if (item.uuid === uuid) {
|
|
||||||
data = item;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await fakeDelay(200)
|
|
||||||
|
|
||||||
if (!data) {
|
|
||||||
throw new Error("Resource could not be found");
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
export async function getItemsByUUID(items) {
|
|
||||||
let data = [];
|
let data = [];
|
||||||
|
|
||||||
Items.forEach((itemInDatabase) => {
|
Items.forEach((itemInDatabase) => {
|
||||||
|
@ -95,7 +79,18 @@ export async function getItemsByUUID(items) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function postContactEmail(name, email, message) {
|
export async function getItemByUUID(uuid: string) {
|
||||||
|
let data = await getItemsByUUID([uuid]);
|
||||||
|
|
||||||
|
if (data.length != 1) {
|
||||||
|
throw new Error("Resource could not be found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return data[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export async function postContactEmail(name: string, email: string, message: string) {
|
||||||
await fakeDelay(200)
|
await fakeDelay(200)
|
||||||
|
|
||||||
if (!name) {
|
if (!name) {
|
|
@ -1,7 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { link } from 'svelte-spa-router';
|
import { link } from 'svelte-spa-router';
|
||||||
|
|
||||||
import { getItemsByUUID } from "%/lib/test-api.js";
|
import { getItemsByUUID } from "%/lib/test-api.ts";
|
||||||
import LoadingBar from "%/components/LoadingBar.svelte";
|
import LoadingBar from "%/components/LoadingBar.svelte";
|
||||||
import Cart from '%/lib/cart.ts';
|
import Cart from '%/lib/cart.ts';
|
||||||
import MenuList from "%/components/MenuList.svelte";
|
import MenuList from "%/components/MenuList.svelte";
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { PaperPlaneRight, SealWarning, SealCheck } from "phosphor-svelte";
|
import { PaperPlaneRight, SealWarning, SealCheck } from "phosphor-svelte";
|
||||||
|
|
||||||
import DropDown from "%/components/DropDown.svelte";
|
import DropDown from "%/components/DropDown.svelte";
|
||||||
import { postContactEmail } from "%/lib/test-api.js";
|
import { postContactEmail } from "%/lib/test-api.ts";
|
||||||
import { expandOnTyping } from "%/lib/utils.js";
|
import { expandOnTyping } from "%/lib/utils.js";
|
||||||
|
|
||||||
const minMessageLength = 150;
|
const minMessageLength = 150;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import { ArrowUpRight } from "phosphor-svelte";
|
import { ArrowUpRight } from "phosphor-svelte";
|
||||||
import L from 'leaflet';
|
import L from 'leaflet';
|
||||||
|
|
||||||
import { getPopularToday } from "%/lib/test-api.js";
|
import { getPopularToday } from "%/lib/test-api.ts";
|
||||||
import LoadingBar from "%/components/LoadingBar.svelte";
|
import LoadingBar from "%/components/LoadingBar.svelte";
|
||||||
import AnnouncementBanner from "%/components/AnnouncementBanner.svelte";
|
import AnnouncementBanner from "%/components/AnnouncementBanner.svelte";
|
||||||
import MenuList from "%/components/MenuList.svelte";
|
import MenuList from "%/components/MenuList.svelte";
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { SmileySad } from "phosphor-svelte";
|
import { SmileySad } from "phosphor-svelte";
|
||||||
|
|
||||||
import Cart from "%/lib/cart.ts";
|
import Cart from "%/lib/cart.ts";
|
||||||
import { getPopularToday, getItemByUUID } from "%/lib/test-api.js";
|
import { getPopularToday, getItemByUUID } from "%/lib/test-api.ts";
|
||||||
import MenuList from "%/components/MenuList.svelte";
|
import MenuList from "%/components/MenuList.svelte";
|
||||||
import LoadingBar from "%/components/LoadingBar.svelte";
|
import LoadingBar from "%/components/LoadingBar.svelte";
|
||||||
import LoadingImage from "/MenuItemLoading.svg";
|
import LoadingImage from "/MenuItemLoading.svg";
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import LoadingBar from "%/components/LoadingBar.svelte";
|
import LoadingBar from "%/components/LoadingBar.svelte";
|
||||||
import MenuList from "%/components/MenuList.svelte";
|
import MenuList from "%/components/MenuList.svelte";
|
||||||
import DropDown from "%/components/DropDown.svelte";
|
import DropDown from "%/components/DropDown.svelte";
|
||||||
import { getMenuItems } from "%/lib/test-api.js";
|
import { getMenuItems } from "%/lib/test-api.ts";
|
||||||
|
|
||||||
let items = getMenuItems();
|
let items = getMenuItems();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue