diff --git a/src/components/organisms/ShopHeader.svelte b/src/components/organisms/ShopHeader.svelte new file mode 100644 index 0000000..efcb228 --- /dev/null +++ b/src/components/organisms/ShopHeader.svelte @@ -0,0 +1,133 @@ + + +
+
+ + + + + Back to Houses Of + +
+ +

Shop

+ + + + photo +
+ + \ No newline at end of file diff --git a/src/routes/shop/[type]-[name].svelte b/src/routes/shop/[type]-[name].svelte index 0516e3e..65e07e5 100644 --- a/src/routes/shop/[type]-[name].svelte +++ b/src/routes/shop/[type]-[name].svelte @@ -1,148 +1,28 @@ -
- - - - - - - photo -
- - + -
- - - \ No newline at end of file + \ No newline at end of file diff --git a/src/routes/shop/[type]-[name].ts b/src/routes/shop/[type]-[name].ts new file mode 100644 index 0000000..ab3c55e --- /dev/null +++ b/src/routes/shop/[type]-[name].ts @@ -0,0 +1,57 @@ +import type { RequestEvent, RequestHandlerOutput } from '@sveltejs/kit' +import { fetchAPI } from '$utils/api' +import { getProduct } from '$utils/functions/swell' + +export async function get({ params }: RequestEvent): Promise { + try { + // Get content from API + const data = await fetchAPI(` + query { + poster: product (search: "${params.name}") { + name + type + description + details + location { + name + slug + } + product_id + photos_product { + directus_files_id { + id + title + } + } + photos_preview { + directus_files_id { + id + title + } + } + } + } + `) + + if (data) { + const poster = data.data.poster[0] + + // Fetch Swell API for product + const shopProduct = await getProduct(poster.product_id) + + if (shopProduct) { + return { + body: { + product: poster, + shopProduct, + } + } + } + } + } catch (error) { + return { + status: 404, + body: error, + } + } +} \ No newline at end of file diff --git a/src/routes/shop/__layout.svelte b/src/routes/shop/__layout.svelte index 0211d90..516f824 100644 --- a/src/routes/shop/__layout.svelte +++ b/src/routes/shop/__layout.svelte @@ -41,10 +41,10 @@ \ No newline at end of file diff --git a/src/routes/shop/index.svelte b/src/routes/shop/index.svelte index 0a2dab7..fe183f4 100644 --- a/src/routes/shop/index.svelte +++ b/src/routes/shop/index.svelte @@ -1,81 +1,16 @@ -
- - -

Shop

- - - - photo -
- - + - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/routes/shop/index.ts b/src/routes/shop/index.ts new file mode 100644 index 0000000..7bd90e3 --- /dev/null +++ b/src/routes/shop/index.ts @@ -0,0 +1,60 @@ +import type { RequestEvent, RequestHandlerOutput } from '@sveltejs/kit' +import { fetchAPI } from '$utils/api' +import { getRandomElement } from '$utils/functions' +import { getProduct } from '$utils/functions/swell' + +export async function get({}: RequestEvent): Promise { + try { + // Get content from API + const data = await fetchAPI(` + query { + posters: product ( + filter: { status: { _eq: "published" }} + ) { + name + type + description + details + location { + name + slug + } + product_id + photos_product { + directus_files_id { + id + title + } + } + photos_preview { + directus_files_id { + id + title + } + } + } + } + `) + + if (data) { + const randomPoster = getRandomElement(data.data.posters) + + // Fetch Swell API for product + const shopProduct = await getProduct(randomPoster.product_id) + + if (shopProduct) { + return { + body: { + product: randomPoster, + shopProduct, + } + } + } + } + } catch (error) { + return { + status: 404, + body: error, + } + } +} \ No newline at end of file