From 02f5b197e190191131d0de0adc42e10f77c2ed17 Mon Sep 17 00:00:00 2001 From: james Date: Tue, 24 Oct 2023 12:03:06 +0800 Subject: [PATCH] Working collections navigation, broken home page --- .../collections/[collection]/+page.server.ts | 34 ++++++ .../collections/[collection]/+page.svelte | 110 ++++++++++++++++++ frontend/src/routes/index.svelte | 7 ++ 3 files changed, 151 insertions(+) create mode 100644 frontend/src/routes/collections/[collection]/+page.server.ts create mode 100644 frontend/src/routes/collections/[collection]/+page.svelte create mode 100644 frontend/src/routes/index.svelte diff --git a/frontend/src/routes/collections/[collection]/+page.server.ts b/frontend/src/routes/collections/[collection]/+page.server.ts new file mode 100644 index 0000000..fbd8a94 --- /dev/null +++ b/frontend/src/routes/collections/[collection]/+page.server.ts @@ -0,0 +1,34 @@ +export const ssr: boolean = true; +export const csr: boolean = true; + +console.log('Script executed'); + +interface LoadResponse { + myapps: any; + status?: number; + error?: string; +} +/** @type {import('../[collection]/$types').PageServerLoad} */ +export async function load({ params }): Promise { + const collectionValue = params.collection + console.log(`load started collection=${collectionValue}`); + try { + const res = await fetch(`http://localhost:8000/api/apps/collections/${collectionValue}`); + + if (!res.ok) { + const text = await res.text(); + throw new Error(`Failed to fetch collections status ${res.status} ${text}`); + } + + const app_collections: any = await res.json(); + console.log(`loaded collections with len: ${Object.keys(app_collections).length}`); + return { myapps: app_collections }; + } catch (error) { + console.error('Failed to load data:', error); + return { + myapps: {}, + status: 500, + error: 'Failed to load trending apps' + }; + } +} diff --git a/frontend/src/routes/collections/[collection]/+page.svelte b/frontend/src/routes/collections/[collection]/+page.svelte new file mode 100644 index 0000000..f9fdb8a --- /dev/null +++ b/frontend/src/routes/collections/[collection]/+page.svelte @@ -0,0 +1,110 @@ + + +

Welcome!

+ +
+ {#if data.myapps} + +

{data.myapps.title}

+ {#each Object.entries(data.myapps.categories) as [_key, cat]} + {#if cat.key == $myCategorySelection} + +

+ {/if} + {/each} + {:else} +

Loading...

+ {data} + {/if} +
+ + diff --git a/frontend/src/routes/index.svelte b/frontend/src/routes/index.svelte new file mode 100644 index 0000000..39a7474 --- /dev/null +++ b/frontend/src/routes/index.svelte @@ -0,0 +1,7 @@ +