🚧 Migrate env variables to use internal SvelteKit system

Some API fetching function rewriting needed as privates cannot be included into public code
This commit is contained in:
2022-08-16 16:58:57 +02:00
parent 5e5c08ddd1
commit 6e904850aa
12 changed files with 131 additions and 92 deletions

View File

@@ -10,9 +10,10 @@
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
import { quartOut } from '$animations/easings'
import { fetchAPI, getAssetUrlKey } from '$utils/api'
import { getAssetUrlKey } from '$utils/api'
import { DELAY } from '$utils/contants'
import { photoFields } from './+page.server'
import { PUBLIC_LIST_INCREMENT } from '$env/static/public'
// Components
import Metas from '$components/Metas.svelte'
import PageTransition from '$components/PageTransition.svelte'
@@ -61,7 +62,7 @@
photos = [...photos, ...newPhotos]
// Define actions if the number of new photos is the expected ones
if (newPhotos.length === Number(import.meta.env.VITE_LIST_INCREMENT)) {
if (newPhotos.length === Number(PUBLIC_LIST_INCREMENT)) {
// Increment the current page
currentPage++
}
@@ -71,24 +72,27 @@
}
}
// [function] Load photos helper
// Load photos helper
const loadPhotos = async (page?: number) => {
const res = fetchAPI(`
query {
photos: photo (
filter: {
location: { slug: { _eq: "${params.location}" }},
status: { _eq: "published" },
},
sort: "-date_created",
limit: ${import.meta.env.VITE_LIST_INCREMENT},
page: ${page},
) {
${photoFields}
const res = await fetch('/api/data', {
method: 'POST',
body: `
query {
photos: photo (
filter: {
location: { slug: { _eq: "${params.location}" }},
status: { _eq: "published" },
},
sort: "-date_created",
limit: ${PUBLIC_LIST_INCREMENT},
page: ${page},
) {
${photoFields}
}
}
}
`)
const { data: { photos }} = await res
`,
})
const { data: { photos }} = await res.json()
if (photos) {
// Return new photos