Rework API calls and each loops
This commit is contained in:
@@ -69,13 +69,13 @@
|
|||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<div class="globe__pins">
|
<div class="globe__pins">
|
||||||
{#if type !== 'part'}
|
{#if type !== 'part'}
|
||||||
{#each $locations as location}
|
{#each $locations as { name, slug, coordinates, country }}
|
||||||
<div class="pin pin--place" data-lat="{location.coordinates.lat}" data-lng="{location.coordinates.lng}">
|
<div class="pin pin--place" data-lat="{coordinates.lat}" data-lng="{coordinates.lng}">
|
||||||
<a href="/location/{location.country.slug}/{location.slug}" class="pin__dot" rel="prefetch">
|
<a href="/location/{country.slug}/{slug}" class="pin__dot" rel="prefetch">
|
||||||
<i class="pin__dot"></i>
|
<i class="pin__dot"></i>
|
||||||
</a>
|
</a>
|
||||||
<a href="/location/{location.country.slug}/{location.slug}" class="pin__name" rel="prefetch">
|
<a href="/location/{country.slug}/{slug}" class="pin__name" rel="prefetch">
|
||||||
<span>{location.name}</span>
|
<span>{name}</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
|||||||
@@ -98,7 +98,9 @@
|
|||||||
*/
|
*/
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
// Entering transition
|
// Entering transition
|
||||||
|
if (photos.length) {
|
||||||
animateIn(scope)
|
animateIn(scope)
|
||||||
|
}
|
||||||
|
|
||||||
// Hover function
|
// Hover function
|
||||||
hover = event => {
|
hover = event => {
|
||||||
@@ -129,6 +131,7 @@
|
|||||||
|
|
||||||
<svelte:window on:keydown={keyboardNav} />
|
<svelte:window on:keydown={keyboardNav} />
|
||||||
|
|
||||||
|
{#if photos.length}
|
||||||
<div class="carousel"
|
<div class="carousel"
|
||||||
on:touchstart={swipeStart}
|
on:touchstart={swipeStart}
|
||||||
on:touchend={swipeEnd}
|
on:touchend={swipeEnd}
|
||||||
@@ -208,3 +211,4 @@
|
|||||||
{/each}
|
{/each}
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
|
|||||||
@@ -50,25 +50,27 @@
|
|||||||
<p>{$site.credits_text}</p>
|
<p>{$site.credits_text}</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if $site.credits_list}
|
||||||
<div class="page__list page__part">
|
<div class="page__list page__part">
|
||||||
{#each $site.credits_list as category}
|
{#each $site.credits_list as { title, credits }}
|
||||||
<div class="page__category">
|
<div class="page__category">
|
||||||
<h2 class="title-category">{category.name}</h2>
|
<h2 class="title-category">{title}</h2>
|
||||||
{#each category.credits as person}
|
{#each credits as { name, role, website }, i}
|
||||||
<dl>
|
<dl>
|
||||||
<dt class="style-location">
|
<dt class="style-location">
|
||||||
{#if person.url}
|
{#if website}
|
||||||
<LinkTranslate href={person.url} text={person.name} target="_blank" rel="noopener" />
|
<LinkTranslate href={website} text={name} target="_blank" rel="noopener" />
|
||||||
{:else}
|
{:else}
|
||||||
{person.name}
|
{name}
|
||||||
{/if}
|
{/if}
|
||||||
</dt>
|
</dt>
|
||||||
<dd class="style-caps style-caps style-caps--transparent">{person.role}</dd>
|
<dd class="style-caps style-caps style-caps--transparent">{role}</dd>
|
||||||
</dl>
|
</dl>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<InteractiveGlobe type="part" />
|
<InteractiveGlobe type="part" />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -4,8 +4,13 @@
|
|||||||
// Preload data
|
// Preload data
|
||||||
export async function preload (page, session) {
|
export async function preload (page, session) {
|
||||||
// Load random photos
|
// 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 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()
|
const photos = await req.json()
|
||||||
if (req.ok) {
|
if (req.ok) {
|
||||||
return { photos: photos.data }
|
return { photos: photos.data }
|
||||||
|
|||||||
@@ -4,7 +4,14 @@
|
|||||||
// Preload data
|
// Preload data
|
||||||
export async function preload (page, session) {
|
export async function preload (page, session) {
|
||||||
// Load photos
|
// 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()
|
const photos = await req.json()
|
||||||
if (req.ok) {
|
if (req.ok) {
|
||||||
return { photos: photos.data }
|
return { photos: photos.data }
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ export const dev = process.env.NODE_ENV === 'development'
|
|||||||
Site related
|
Site related
|
||||||
========================================================================== */
|
========================================================================== */
|
||||||
const apiEndpoint = dev ? 'http://api.housesof.localhost/how' : 'https://api.housesof.world/_'
|
const apiEndpoint = dev ? 'http://api.housesof.localhost/how' : 'https://api.housesof.world/_'
|
||||||
|
const apiAccessToken = 'NJk0urljsdSvApUDzWxGgoO6'
|
||||||
export const apiEndpoints = {
|
export const apiEndpoints = {
|
||||||
gql: apiEndpoint + '/gql?access_token=NJk0urljsdSvApUDzWxGgoO6',
|
gql: `${apiEndpoint}/gql?access_token=${apiAccessToken}`,
|
||||||
rest: apiEndpoint
|
rest: apiEndpoint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user