From 9965c9dec3f4e89c2613d82e8112e1bd368fee55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Mon, 16 Mar 2020 12:57:53 +0100 Subject: [PATCH] Rework API calls and each loops --- src/molecules/InteractiveGlobe.svelte | 10 +++++----- src/organisms/Carousel.svelte | 6 +++++- src/routes/credits.svelte | 16 +++++++++------- src/routes/index.svelte | 9 +++++++-- src/routes/location/[country]/[place].svelte | 9 ++++++++- src/utils/store.js | 3 ++- 6 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/molecules/InteractiveGlobe.svelte b/src/molecules/InteractiveGlobe.svelte index 6c5c824..3a0f1d5 100644 --- a/src/molecules/InteractiveGlobe.svelte +++ b/src/molecules/InteractiveGlobe.svelte @@ -69,13 +69,13 @@
{#if type !== 'part'} - {#each $locations as location} -
- + {#each $locations as { name, slug, coordinates, country }} + {/each} diff --git a/src/organisms/Carousel.svelte b/src/organisms/Carousel.svelte index c34940a..bf9e982 100644 --- a/src/organisms/Carousel.svelte +++ b/src/organisms/Carousel.svelte @@ -98,7 +98,9 @@ */ onMount(() => { // Entering transition - animateIn(scope) + if (photos.length) { + animateIn(scope) + } // Hover function hover = event => { @@ -129,6 +131,7 @@ +{#if photos.length} +{/if} diff --git a/src/routes/credits.svelte b/src/routes/credits.svelte index ef575e1..7d83a4f 100644 --- a/src/routes/credits.svelte +++ b/src/routes/credits.svelte @@ -50,25 +50,27 @@

{$site.credits_text}

+ {#if $site.credits_list}
- {#each $site.credits_list as category} + {#each $site.credits_list as { title, credits }}
-

{category.name}

- {#each category.credits as person} +

{title}

+ {#each credits as { name, role, website }, i}
- {#if person.url} - + {#if website} + {:else} - {person.name} + {name} {/if}
-
{person.role}
+
{role}
{/each}
{/each}
+ {/if}
diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 2ade781..067f915 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -4,13 +4,18 @@ // Preload data export async function preload (page, session) { // Load random photos + const fields = [ + 'id', 'name', 'image.private_hash', + 'location.id', 'location.name', 'location.slug', 'location.country.name' + ] + const sort = '?' const limit = 5 - const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=id,name,image.*,location.*,location.country.name&sort=?&limit=${limit}`) + const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&sort=${sort}&limit=${limit}`) const photos = await req.json() if (req.ok) { return { photos: photos.data } } - this.error(404, 'Not found') + this.error(404, 'Not found') } diff --git a/src/routes/location/[country]/[place].svelte b/src/routes/location/[country]/[place].svelte index cacc45b..fd5a2af 100644 --- a/src/routes/location/[country]/[place].svelte +++ b/src/routes/location/[country]/[place].svelte @@ -4,7 +4,14 @@ // Preload data export async function preload (page, session) { // Load photos - const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=id,name,slug,date,image.*,location.*,location.country.*,created_on,modified_on&filter[location.slug][rlike]=%${page.params.place}%&limit=-1&sort=-created_on,name`) + const fields = [ + 'id', 'name', 'slug', 'date', 'image.*', + 'location.id', 'location.name', 'location.region', 'location.country.name', + 'created_on', 'modified_on' + ] + const sort = ['-created_on', 'name'] + const limit = -1 + const req = await this.fetch(`${apiEndpoints.rest}/items/photos?fields=${fields.join()}&filter[location.slug][rlike]=%${page.params.place}%&limit=${limit}&sort=${sort.join()}`) const photos = await req.json() if (req.ok) { return { photos: photos.data } diff --git a/src/utils/store.js b/src/utils/store.js index 19123c5..909725f 100644 --- a/src/utils/store.js +++ b/src/utils/store.js @@ -9,8 +9,9 @@ export const dev = process.env.NODE_ENV === 'development' Site related ========================================================================== */ const apiEndpoint = dev ? 'http://api.housesof.localhost/how' : 'https://api.housesof.world/_' +const apiAccessToken = 'NJk0urljsdSvApUDzWxGgoO6' export const apiEndpoints = { - gql: apiEndpoint + '/gql?access_token=NJk0urljsdSvApUDzWxGgoO6', + gql: `${apiEndpoint}/gql?access_token=${apiAccessToken}`, rest: apiEndpoint }