🚧 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:
@@ -13,9 +13,9 @@
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
import { stagger, timeline } from 'motion'
|
||||
import { DELAY } from '$utils/contants'
|
||||
import { fetchAPI } from '$utils/api'
|
||||
import { quartOut } from '$animations/easings'
|
||||
import { map, lerp, throttle } from '$utils/functions'
|
||||
import { PUBLIC_FILTERS_DEFAULT_COUNTRY, PUBLIC_FILTERS_DEFAULT_SORT, PUBLIC_GRID_INCREMENT } from '$env/static/public'
|
||||
// Components
|
||||
import Metas from '$components/Metas.svelte'
|
||||
import PageTransition from '$components/PageTransition.svelte'
|
||||
@@ -57,8 +57,8 @@
|
||||
/**
|
||||
* Filters
|
||||
*/
|
||||
const defaultCountry: string = import.meta.env.VITE_FILTERS_DEFAULT_COUNTRY
|
||||
const defaultSort: string = import.meta.env.VITE_FILTERS_DEFAULT_SORT
|
||||
const defaultCountry: string = PUBLIC_FILTERS_DEFAULT_COUNTRY
|
||||
const defaultSort: string = PUBLIC_FILTERS_DEFAULT_SORT
|
||||
const urlFiltersParams = new URLSearchParams()
|
||||
let filtered: boolean
|
||||
let filterCountry = $page.url.searchParams.get('country') || defaultCountry
|
||||
@@ -158,39 +158,43 @@
|
||||
*/
|
||||
// [function] Load photos helper
|
||||
const loadPhotos = async (page: number) => {
|
||||
const res = fetchAPI(`
|
||||
query {
|
||||
photos: photo (
|
||||
filter: {
|
||||
${filterCountry !== 'all' ? `location: { country: { slug: { _eq: "${filterCountry}" }} },` : ''}
|
||||
status: { _eq: "published" },
|
||||
},
|
||||
sort: "${filterSort === 'latest' ? '-' : ''}date_created",
|
||||
limit: ${import.meta.env.VITE_GRID_INCREMENT},
|
||||
page: ${page},
|
||||
) {
|
||||
id
|
||||
title
|
||||
slug
|
||||
image {
|
||||
const res = await fetch('/api/data', {
|
||||
method: 'POST',
|
||||
body: `
|
||||
query {
|
||||
photos: photo (
|
||||
filter: {
|
||||
${filterCountry !== 'all' ? `location: { country: { slug: { _eq: "${filterCountry}" }} },` : ''}
|
||||
status: { _eq: "published" },
|
||||
},
|
||||
sort: "${filterSort === 'latest' ? '-' : ''}date_created",
|
||||
limit: ${PUBLIC_GRID_INCREMENT},
|
||||
page: ${page},
|
||||
) {
|
||||
id
|
||||
title
|
||||
}
|
||||
location {
|
||||
slug
|
||||
name
|
||||
region
|
||||
country {
|
||||
image {
|
||||
id
|
||||
title
|
||||
}
|
||||
location {
|
||||
slug
|
||||
name
|
||||
flag { id }
|
||||
region
|
||||
country {
|
||||
slug
|
||||
name
|
||||
flag { id }
|
||||
}
|
||||
}
|
||||
city
|
||||
}
|
||||
city
|
||||
}
|
||||
}
|
||||
`)
|
||||
const { data: { photos }} = await res
|
||||
`,
|
||||
})
|
||||
|
||||
const { data: { photos }} = await res.json()
|
||||
|
||||
if (photos) {
|
||||
// Return new photos
|
||||
@@ -209,7 +213,7 @@
|
||||
photos = [...photos, ...newPhotos]
|
||||
|
||||
// Define actions if the number of new photos is the expected ones
|
||||
if (newPhotos.length === Number(import.meta.env.VITE_GRID_INCREMENT)) {
|
||||
if (newPhotos.length === Number(PUBLIC_GRID_INCREMENT)) {
|
||||
// Increment the current page
|
||||
currentPage++
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user