Query Location page content

This commit is contained in:
2021-09-26 23:36:58 +02:00
parent 03e0c1c162
commit bee59dab90
3 changed files with 66 additions and 1 deletions

View File

@@ -0,0 +1 @@
photo page

View File

@@ -0,0 +1,65 @@
<script lang="ts">
import { page } from '$app/stores'
// Components
import Image from '$components/atoms/Image.svelte'
export let data: any
export let photos: any
const { params } = $page
</script>
<h1>Hello {data.name}</h1>
{#each photos as { image: { id, title }, slug }}
<div class="photo">
<a href="/{params.country}/{params.location}/{slug}">
<Image
id={id}
alt="{title}, {data.name}"
width={1000}
height={600}
format="webp"
/>
</a>
</div>
{/each}
<script context="module" lang="ts">
import { fetchAPI } from '$utils/api'
export async function load ({ page, session, fetch, context }) {
const { location } = page.params
const res = await fetchAPI(`
query {
location (filter: { slug: { _eq: "${location}" } }) {
name
slug
description
date_updated
}
photo (filter: { location: { slug: { _eq: "${location}" } }}) {
title
slug
date_taken
image {
id
title
}
}
}
`)
const { data } = res
return {
props: {
data: data.location[0],
photos: data.photo,
}
}
}
</script>