From 782c88d082a05d9d8d339efb0a33a6a4dd0801da Mon Sep 17 00:00:00 2001 From: Fluffy-Bean Date: Sat, 27 Apr 2024 19:23:06 +0100 Subject: [PATCH] Add fake API to allow for testing of requests --- front/src/App.svelte | 34 +++++--------------- front/src/lib/api.js | 2 +- front/src/lib/test-api.js | 30 ++++++++++++++++++ front/src/lib/{testData.js => test-data.js} | 23 ++++++++++++-- front/src/pages/PageIndex.svelte | 6 ++-- front/src/pages/PageItem.svelte | 2 +- front/src/pages/PageMenu.svelte | 35 +++++++++++++-------- 7 files changed, 86 insertions(+), 46 deletions(-) create mode 100644 front/src/lib/test-api.js rename front/src/lib/{testData.js => test-data.js} (70%) diff --git a/front/src/App.svelte b/front/src/App.svelte index dd7a050..63e85df 100644 --- a/front/src/App.svelte +++ b/front/src/App.svelte @@ -48,38 +48,20 @@ diff --git a/front/src/lib/api.js b/front/src/lib/api.js index f507e62..3f170d8 100644 --- a/front/src/lib/api.js +++ b/front/src/lib/api.js @@ -1,4 +1,4 @@ -import Items from '%/lib/testData.js'; +import Items from '%/lib/test-data.js'; export async function getPopularToday() { const res = await fetch("/api/items") diff --git a/front/src/lib/test-api.js b/front/src/lib/test-api.js new file mode 100644 index 0000000..91f43fa --- /dev/null +++ b/front/src/lib/test-api.js @@ -0,0 +1,30 @@ +import Items from '%/lib/test-data.js'; + +async function fakeDelay(timeout = 1000) { + await new Promise(resolve => setTimeout(resolve, timeout)); +} + +export async function getPopularToday() { + const data = Items; + await fakeDelay(2000) + return data; +} + +export async function getMenuItems() { + const data = [ + { + name: "Main Menu", + items: Items, + }, + { + name: "Breakfast", + items: [], + }, + { + name: "Seasonal", + items: Items, + }, + ]; + await fakeDelay(2000) + return data; +} diff --git a/front/src/lib/testData.js b/front/src/lib/test-data.js similarity index 70% rename from front/src/lib/testData.js rename to front/src/lib/test-data.js index 225d03d..d39da43 100644 --- a/front/src/lib/testData.js +++ b/front/src/lib/test-data.js @@ -1,53 +1,72 @@ // "vegan", "fish", "nut", "spicy", "gluten" -let Items; -export default Items = [ +const Items = [ + // soap: { { + uuid: "soap", name: "Bar of Soap", price: 69.99, labels: ["vegan", "spicy"], }, + // sock: { { + uuid: "sock", name: "Sock", price: 21, labels: ["vegan", "fish", "nut", "spicy"], }, + // brick: { { + uuid: "brick", name: "Brick", price: 0, labels: ["spicy"], }, + // toast: { { + uuid: "toast", name: "Toast", price: 4382749832743, labels: ["gluten"], }, + // water: { { + uuid: "water", name: "water", price: 1, labels: ["fish"], }, + // mouldy_bread: { { + uuid: "mouldy_bread", name: "half eaten mouldy bread", price: -99, labels: ["nut"], }, + // gwagwa: { { + uuid: "gwagwa", name: "GwaGwa", price: "Priceless", labels: ["nut"], image: "/dab.jpg", }, + // hogmelon: { { + uuid: "hogmelon", name: "Hogermellon", price: "1111", labels: ["fish"], image: "/wathog.jpg", }, + // bluhog: { { + uuid: "bluhog", name: "Blue HOGGGGG", price: "ARUGH", labels: ["nut", "gluten", "spicy"], image: "/sonichog.jpg", }, ]; + +export default Items; diff --git a/front/src/pages/PageIndex.svelte b/front/src/pages/PageIndex.svelte index b0e2353..64b26f1 100644 --- a/front/src/pages/PageIndex.svelte +++ b/front/src/pages/PageIndex.svelte @@ -5,7 +5,7 @@ import { ArrowUpRight } from "phosphor-svelte"; import MenuList from "%/components/MenuList.svelte"; - import { getPopularToday } from "%/lib/api.js"; + import { getPopularToday } from "%/lib/test-api.js"; import BannerImage from '/BannerExampleImage.jpg'; let items = getPopularToday(); @@ -35,8 +35,8 @@
-

Some Title

-

Example text

+

Opening Times

+

Please make sure to checkout our full calendar, as we have different times during public holiday

diff --git a/front/src/pages/PageItem.svelte b/front/src/pages/PageItem.svelte index f056617..172ad78 100644 --- a/front/src/pages/PageItem.svelte +++ b/front/src/pages/PageItem.svelte @@ -1,7 +1,7 @@ @@ -139,15 +140,21 @@
DayOpeningClosing