From 3d7b859d1214591aa5f4074210135b85d1ec7ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Tue, 6 Sep 2022 14:51:47 +0200 Subject: [PATCH] Move API fields to file --- src/routes/[country]/[location]/+page.server.ts | 14 +------------- src/routes/[country]/[location]/+page.svelte | 2 +- src/utils/api.ts | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/routes/[country]/[location]/+page.server.ts b/src/routes/[country]/[location]/+page.server.ts index 057c876..b3769ef 100644 --- a/src/routes/[country]/[location]/+page.server.ts +++ b/src/routes/[country]/[location]/+page.server.ts @@ -1,20 +1,8 @@ import { error } from '@sveltejs/kit' import type { PageServerLoad } from './$types' import { PUBLIC_LIST_AMOUNT } from '$env/static/public' -import { fetchAPI } from '$utils/api' +import { fetchAPI, photoFields } from '$utils/api' -export const photoFields = ` - title - slug - city - image { - id - title - width, height - } - date_taken - date_created -` export const load: PageServerLoad = async ({ params }) => { try { diff --git a/src/routes/[country]/[location]/+page.svelte b/src/routes/[country]/[location]/+page.svelte index 87e9af1..638278f 100644 --- a/src/routes/[country]/[location]/+page.svelte +++ b/src/routes/[country]/[location]/+page.svelte @@ -12,7 +12,7 @@ import { quartOut } from '$animations/easings' import { getAssetUrlKey } from '$utils/api' import { DELAY } from '$utils/contants' - import { photoFields } from './+page.server' + import { photoFields } from '$utils/api' import { PUBLIC_LIST_INCREMENT } from '$env/static/public' // Components import Metas from '$components/Metas.svelte' diff --git a/src/utils/api.ts b/src/utils/api.ts index 3afff21..f05732d 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -43,6 +43,23 @@ export const getAssetUrlKey = ( } +/** + * GraphQL fields + */ +export const photoFields = ` + title + slug + city + image { + id + title + width, height + } + date_taken + date_created +` + + /** * Get a Directus asset URL from parameters */