Optimise Cart page

Yeet the last of the % imports, as they incorrectly displayed as syntax errors
This commit is contained in:
Michał Gdula 2024-05-03 14:09:48 +01:00
parent 6f97ad9a4c
commit c54c9c05a9
8 changed files with 40 additions and 34 deletions

View file

@ -22,10 +22,7 @@
* Typecheck JS in `.svelte` and `.js` files by default. * Typecheck JS in `.svelte` and `.js` files by default.
* Disable this if you'd like to use dynamic types. * Disable this if you'd like to use dynamic types.
*/ */
"checkJs": true, "checkJs": true
"paths": {
"%": ["./src"]
}
}, },
/** /**
* Use global.d.ts instead of compilerOptions.types * Use global.d.ts instead of compilerOptions.types

View file

@ -59,14 +59,14 @@ const TestData: Item[] = [
image: "/wathog.jpg", image: "/wathog.jpg",
detail: "Example", detail: "Example",
}, },
{ // {
uuid: "bluhog", // uuid: "bluhog",
name: "Blue HOGGGGG", // name: "Blue HOGGGGG",
price: 0, // price: 0,
labels: [Labels.nut, Labels.gluten, Labels.spicy], // labels: [Labels.nut, Labels.gluten, Labels.spicy],
image: "/sonichog.jpg", // image: "/sonichog.jpg",
detail: "Example", // detail: "Example",
}, // },
]; ];
export default TestData; export default TestData;

View file

@ -1,5 +1,5 @@
import '%/styles/main.scss' import './styles/main.scss'
import App from '%/App.svelte' import App from './App.svelte'
const app = new App({ const app = new App({
target: document.getElementById('app'), target: document.getElementById('app'),

View file

@ -1,6 +1,8 @@
<script lang="ts"> <script lang="ts">
import { link } from 'svelte-spa-router'; import { link } from 'svelte-spa-router';
import { Basket } from "phosphor-svelte";
import type { CartItem } from "../lib/types";
import { getPopularToday } from "../lib/test-api"; import { getPopularToday } from "../lib/test-api";
import Cart from "../lib/cart"; import Cart from "../lib/cart";
import MenuList from "../components/MenuList.svelte"; import MenuList from "../components/MenuList.svelte";
@ -8,8 +10,13 @@
let popularToday = getPopularToday(); let popularToday = getPopularToday();
$: items = $Cart; let items: CartItem[];
$: totalPrice = $Cart.map((item) => item.amount * item.data.price).reduce((a, b) => a + b, 0); let totalPrice: number;
Cart.subscribe(() => {
items = $Cart;
totalPrice = Cart.getTotalPrice();
});
</script> </script>
@ -26,8 +33,8 @@
{/each} {/each}
{:else} {:else}
<div id="emptyCart"> <div id="emptyCart">
<h1>Empty Cart!</h1> <h1>Empty Cart&nbsp;<Basket weight="fill" /></h1>
<p>Go add some items from the menu...</p> <p>Why not go and checkout <a href="/menu" use:link>our menu</a>?</p>
</div> </div>
{/if} {/if}

View file

@ -23,7 +23,7 @@
</script> </script>
<AnnouncementBanner /> <AnnouncementBanner />
<a href="/annoucements" use:link>Learn More <ArrowUpRight /></a>
<div class="spacer" /> <div class="spacer" />
<h2>Where to find us</h2> <h2>Where to find us</h2>
@ -44,9 +44,10 @@
<tr><td>Sunday</td><td>11am</td><td>2am</td></tr> <tr><td>Sunday</td><td>11am</td><td>2am</td></tr>
</table> </table>
</div> </div>
<a href="/menu" use:link>Ready to book a table?</a> <a href="/book" use:link>Ready to book a table?</a>
</div> </div>
</div> </div>
<div class="spacer" /> <div class="spacer" />
<h2>Popular Today</h2> <h2>Popular Today</h2>
@ -60,6 +61,7 @@
{/await} {/await}
</div> </div>
<a href="/menu" use:link>See All <ArrowUpRight /></a> <a href="/menu" use:link>See All <ArrowUpRight /></a>
<div class="spacer" /> <div class="spacer" />
<h2>About Us</h2>contact <h2>About Us</h2>contact

View file

@ -1,30 +1,30 @@
import { wrap } from "svelte-spa-router/wrap"; import { wrap } from "svelte-spa-router/wrap";
import PageLoading from "%/pages/PageLoading.svelte"; import PageLoading from "./pages/PageLoading.svelte";
import Page404 from "%/pages/Page404.svelte"; import Page404 from "./pages/Page404.svelte";
import Page500 from "%/pages/Page500.svelte"; import Page500 from "./pages/Page500.svelte";
const routes = { const routes = {
"/": wrap({ "/": wrap({
asyncComponent: () => import("%/pages/PageIndex.svelte"), asyncComponent: () => import("./pages/PageIndex.svelte"),
loadingComponent: PageLoading, loadingComponent: PageLoading,
conditions: [], conditions: [],
userData: { showNavBar: true, fullWidth: false, }, userData: { showNavBar: true, fullWidth: false, },
}), }),
"/menu": wrap({ "/menu": wrap({
asyncComponent: () => import("%/pages/PageMenu.svelte"), asyncComponent: () => import("./pages/PageMenu.svelte"),
loadingComponent: PageLoading, loadingComponent: PageLoading,
conditions: [], conditions: [],
userData: { showNavBar: true, fullWidth: true, }, userData: { showNavBar: true, fullWidth: true, },
}), }),
"/item/:uuid": wrap({ "/item/:uuid": wrap({
asyncComponent: () => import("%/pages/PageItem.svelte"), asyncComponent: () => import("./pages/PageItem.svelte"),
loadingComponent: PageLoading, loadingComponent: PageLoading,
conditions: [], conditions: [],
userData: { showNavBar: true, fullWidth: true, }, userData: { showNavBar: true, fullWidth: true, },
}), }),
"/contact": wrap({ "/contact": wrap({
asyncComponent: () => import("%/pages/PageContact.svelte"), asyncComponent: () => import("./pages/PageContact.svelte"),
loadingComponent: PageLoading, loadingComponent: PageLoading,
conditions: [], conditions: [],
userData: { showNavBar: true, fullWidth: false, }, userData: { showNavBar: true, fullWidth: false, },
@ -36,7 +36,7 @@ const routes = {
userData: { showNavBar: true, fullWidth: false, }, userData: { showNavBar: true, fullWidth: false, },
}), }),
"/cart": wrap({ "/cart": wrap({
asyncComponent: () => import("%/pages/PageCart.svelte"), asyncComponent: () => import("./pages/PageCart.svelte"),
loadingComponent: PageLoading, loadingComponent: PageLoading,
conditions: [], conditions: [],
userData: { showNavBar: true, fullWidth: false, }, userData: { showNavBar: true, fullWidth: false, },

View file

@ -24,7 +24,7 @@ $border-radius-circle: 99999px;
// GAP SIZING // GAP SIZING
$sizing-default-width: 1000px; $sizing-default-width: 1000px;
$sizing-full-width: 1200px; $sizing-full-width: 1200px;
$sizing-navigation-height: 55px; $sizing-navigation-height: 60px;
// PADDING/MARGIN // PADDING/MARGIN
$spacing-xsmall: 5px; $spacing-xsmall: 5px;

View file

@ -10,9 +10,9 @@ export default defineConfig({
optimizeDeps: { optimizeDeps: {
exclude: ["phosphor-svelte"], exclude: ["phosphor-svelte"],
}, },
resolve: { // resolve: {
alias: { // alias: {
'%': __dirname + '/src', // '%': __dirname + '/src',
} // }
}, // },
}) })