refactor: get rid of page data types

This commit is contained in:
2023-05-26 23:47:08 +02:00
parent 422727586e
commit 685d4fd244
28 changed files with 44 additions and 72 deletions

View File

@@ -1,10 +1,9 @@
import { error } from '@sveltejs/kit'
import type { LayoutServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
import { fetchSwell } from '$utils/functions/shopServer'
export const load = (async () => {
export const load = async () => {
try {
// Get content from API
const res = await fetchAPI(`query {
@@ -76,4 +75,4 @@ export const load = (async () => {
} catch (err) {
throw error(500, err.message)
}
}) satisfies LayoutServerLoad
}

View File

@@ -3,14 +3,13 @@
</style>
<script lang="ts">
import type { PageData } from './$types'
import { setContext } from 'svelte'
import { cartNotifications } from '$utils/stores/shop'
// Components
import Cart from '$components/organisms/Cart.svelte'
import NotificationCart from '$components/molecules/NotificationCart.svelte'
export let data: PageData
export let data
const { shop, locations, posters, shopProducts, settings } = data

View File

@@ -1,11 +1,10 @@
import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
import { getRandomItem } from 'utils/array'
import { fetchSwell } from '$utils/functions/shopServer'
export const load = (async ({ setHeaders }) => {
export const load = async ({ setHeaders }) => {
try {
// Get content from API
const data = await fetchAPI(`query {
@@ -54,4 +53,4 @@ export const load = (async ({ setHeaders }) => {
} catch (err) {
throw error(500, err.message)
}
}) satisfies PageServerLoad
}

View File

@@ -1,5 +1,4 @@
<script lang="ts">
import type { PageData } from './$types'
import { getContext } from 'svelte'
import { getAssetUrlKey } from '$utils/api'
import { shopCurrentProductSlug } from '$utils/stores/shop'
@@ -10,7 +9,7 @@
import ShopHeader from '$components/organisms/ShopBanner.svelte'
import PosterLayout from '$components/layouts/PosterLayout.svelte'
export let data: PageData
export let data
const { product, shopProduct }: { product: any, shopProduct: any } = data
const { posters, settings }: any = getContext('shop')

View File

@@ -1,10 +1,9 @@
import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
import { fetchSwell } from '$utils/functions/shopServer'
export const load = (async ({ params, setHeaders }) => {
export const load = async ({ params, setHeaders }) => {
try {
// Get content from API
const data = await fetchAPI(`query {
@@ -51,4 +50,4 @@ export const load = (async ({ params, setHeaders }) => {
} catch (err) {
throw error(404)
}
}) satisfies PageServerLoad
}

View File

@@ -1,5 +1,4 @@
<script lang="ts">
import type { PageData } from './$types'
import { getContext } from 'svelte'
import { getAssetUrlKey } from '$utils/api'
import { shopCurrentProductSlug } from '$utils/stores/shop'
@@ -11,7 +10,7 @@
import PostersGrid from '$components/organisms/PostersGrid.svelte'
import PosterLayout from '$components/layouts/PosterLayout.svelte'
export let data: PageData
export let data
const { posters }: any = getContext('shop')

View File

@@ -1,10 +1,9 @@
import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
import { PUBLIC_LIST_AMOUNT } from '$env/static/public'
import { fetchAPI, photoFields } from '$utils/api'
export const load = (async ({ params, setHeaders }) => {
export const load = async ({ params, setHeaders }) => {
try {
const { location: slug } = params
@@ -88,4 +87,4 @@ export const load = (async ({ params, setHeaders }) => {
} catch (err) {
throw error(500, err.message)
}
}) satisfies PageServerLoad
}

View File

@@ -4,7 +4,6 @@
<script lang="ts">
import { page, navigating } from '$app/stores'
import type { PageData } from './$types'
import { onMount } from 'svelte'
import { stagger, timeline } from 'motion'
import dayjs from 'dayjs'
@@ -26,7 +25,7 @@
import NewsletterModule from '$components/organisms/NewsletterModule.svelte'
import ShopModule from '$components/organisms/ShopModule.svelte'
export let data: PageData
export let data
let { photos, totalPhotos }: { photos: any[], totalPhotos: number } = data
$: ({ photos, totalPhotos } = data)

View File

@@ -1,9 +1,8 @@
import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
export const load = (async ({ params, setHeaders }) => {
export const load = async ({ params, setHeaders }) => {
try {
// Get the first photo ID
const firstPhoto = await fetchAPI(`query {
@@ -89,4 +88,4 @@ export const load = (async ({ params, setHeaders }) => {
} catch (err) {
throw error(500, err.message)
}
}) satisfies PageServerLoad
}

View File

@@ -6,7 +6,6 @@
import { browser } from '$app/environment'
import { page, navigating } from '$app/stores'
import { goto } from '$app/navigation'
import type { PageData } from './$types'
import { onMount, tick } from 'svelte'
import { fade, scale } from 'svelte/transition'
import { quartOut } from 'svelte/easing'
@@ -26,7 +25,7 @@
import IconArrow from '$components/atoms/IconArrow.svelte'
import ButtonCircle from '$components/atoms/ButtonCircle.svelte'
export let data: PageData
export let data
let { photos, currentIndex }: { photos: any[], currentIndex: number } = data
const { location, countPhotos, limit, offset }: { location: any, countPhotos: number, limit: number, offset: number } = data

View File

@@ -1,10 +1,9 @@
import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
import { getRandomItems } from 'utils/array'
export const load = (async ({ setHeaders }) => {
export const load = async ({ setHeaders }) => {
try {
// Get data and total of published photos
const res = await fetchAPI(`query {
@@ -102,4 +101,4 @@ export const load = (async ({ setHeaders }) => {
} catch (err) {
throw error(500, err.message)
}
}) satisfies PageServerLoad
}

View File

@@ -7,7 +7,6 @@
import { onMount, afterUpdate } from 'svelte'
import { quartOut as quartOutSvelte } from 'svelte/easing'
import { fade, fly } from 'svelte/transition'
import type { PageData } from './$types'
import { animate, inView, stagger, timeline } from 'motion'
import { mailtoClipboard } from '$utils/functions'
import { getAssetUrlKey } from '$utils/api'
@@ -24,7 +23,7 @@
import ProcessStep from '$components/molecules/ProcessStep.svelte'
import Banner from '$components/organisms/Banner.svelte'
export let data: PageData
export let data
const { about, photos } = data
let scrollY: number, innerWidth: number, innerHeight: number

View File

@@ -1,9 +1,8 @@
import { error } from '@sveltejs/kit'
import type { RequestHandler } from './$types'
import { fetchAPI } from '$utils/api'
export const POST = (async ({ request, setHeaders }) => {
export const POST = async ({ request, setHeaders }) => {
try {
const body = await request.text()
@@ -22,4 +21,4 @@ export const POST = (async ({ request, setHeaders }) => {
} catch (err) {
throw error(500, err.message)
}
}) satisfies RequestHandler
}

View File

@@ -1,9 +1,8 @@
import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
export const load = (async ({ setHeaders }) => {
export const load = async ({ setHeaders }) => {
try {
const res = await fetchAPI(`query {
credits {
@@ -41,4 +40,4 @@ export const load = (async ({ setHeaders }) => {
} catch (err) {
throw error(500, err.message)
}
}) satisfies PageServerLoad
}

View File

@@ -4,7 +4,6 @@
<script lang="ts">
import { navigating } from '$app/stores'
import type { PageData } from './$types'
import { onMount } from 'svelte'
import { stagger, timeline } from 'motion'
import { DELAY } from '$utils/constants'
@@ -16,7 +15,7 @@
import Heading from '$components/molecules/Heading.svelte'
import InteractiveGlobe from '$components/organisms/InteractiveGlobe.svelte'
export let data: PageData
export let data
const { credit } = data

View File

@@ -1,5 +1,4 @@
import { error } from '@sveltejs/kit'
import type { RequestHandler } from './$types'
import { fetchSwell } from '$utils/functions/shopServer'
import { fetchAPI, getAssetUrlKey } from '$utils/api'
@@ -12,7 +11,7 @@ const gCategories = [
}
]
export const GET = (async ({ url, setHeaders }) => {
export const GET = async ({ url, setHeaders }) => {
try {
const products = []
@@ -66,7 +65,7 @@ export const GET = (async ({ url, setHeaders }) => {
} catch (err) {
throw error(500, err.message)
}
}) satisfies RequestHandler
}
// Render sitemap

View File

@@ -1,10 +1,9 @@
import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
import { PUBLIC_FILTERS_DEFAULT_COUNTRY, PUBLIC_FILTERS_DEFAULT_SORT, PUBLIC_GRID_AMOUNT } from '$env/static/public'
export const load = (async ({ url, setHeaders }) => {
export const load = async ({ url, setHeaders }) => {
try {
// Query parameters
const queryCountry = url.searchParams.get('country') || PUBLIC_FILTERS_DEFAULT_COUNTRY
@@ -85,4 +84,4 @@ export const load = (async ({ url, setHeaders }) => {
} catch (err) {
throw error(500, err.message)
}
}) satisfies PageServerLoad
}

View File

@@ -5,7 +5,6 @@
<script lang="ts">
import { page, navigating } from '$app/stores'
import { goto } from '$app/navigation'
import type { PageData } from './$types'
import { getContext, onMount } from 'svelte'
import { fly } from 'svelte/transition'
import { quartOut as quartOutSvelte } from 'svelte/easing'
@@ -32,7 +31,7 @@
import ShopModule from '$components/organisms/ShopModule.svelte'
import NewsletterModule from '$components/organisms/NewsletterModule.svelte'
export let data: PageData
export let data
let { photos, totalPhotos }: { photos: any[], totalPhotos: number } = data
$: ({ photos, totalPhotos } = data)

View File

@@ -1,9 +1,8 @@
import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
export const load = (async ({ setHeaders }) => {
export const load = async ({ setHeaders }) => {
try {
const res = await fetchAPI(`query {
settings {
@@ -36,4 +35,4 @@ export const load = (async ({ setHeaders }) => {
} catch (err) {
throw error(500, err.message)
}
}) satisfies PageServerLoad
}

View File

@@ -4,7 +4,6 @@
<script lang="ts">
import { navigating } from '$app/stores'
import type { PageData } from './$types'
import { onMount } from 'svelte'
import { stagger, timeline } from 'motion'
import { DELAY } from '$utils/constants'
@@ -17,7 +16,7 @@
import NewsletterIssue from '$components/molecules/NewsletterIssue.svelte'
import InteractiveGlobe from '$components/organisms/InteractiveGlobe.svelte'
export let data: PageData
export let data
const { issues } = data
const latestIssue = issues[0]

View File

@@ -1,9 +1,8 @@
import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
export const load = (async ({ setHeaders }) => {
export const load = async ({ setHeaders }) => {
try {
const res = await fetchAPI(`query {
legal {
@@ -24,4 +23,4 @@ export const load = (async ({ setHeaders }) => {
} catch (err) {
throw error(500, err.message)
}
}) satisfies PageServerLoad
}

View File

@@ -3,7 +3,6 @@
</style>
<script lang="ts">
import type { PageData } from './$types'
import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime'
// Components
@@ -11,7 +10,7 @@
import Metas from '$components/Metas.svelte'
import Heading from '$components/molecules/Heading.svelte'
export let data: PageData
export let data
const { legal } = data
dayjs.extend(relativeTime)

View File

@@ -1,10 +1,9 @@
import { error } from '@sveltejs/kit'
import type { LayoutServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
import { PUBLIC_PREVIEW_COUNT } from '$env/static/public'
export const load = (async () => {
export const load = async ({ url }) => {
try {
const res = await fetchAPI(`query {
locations: location (filter: { status: { _eq: "published" }}) {
@@ -102,4 +101,4 @@ export const load = (async () => {
} catch (err) {
throw error(500, err || 'Failed to fetch data')
}
}) satisfies LayoutServerLoad
}

View File

@@ -5,7 +5,6 @@
import { page } from '$app/stores'
import { beforeNavigate } from '$app/navigation'
import { PUBLIC_ANALYTICS_DOMAIN } from '$env/static/public'
import type { PageData } from './$types'
import { onMount, setContext } from 'svelte'
import { pageLoading, previousPage } from '$utils/stores'
import '$utils/polyfills'
@@ -16,7 +15,7 @@
import Switcher from '$components/molecules/Switcher.svelte'
import Footer from '$components/organisms/Footer.svelte'
export let data: PageData
export let data
let innerHeight: number
$: innerHeight && document.body.style.setProperty('--vh', `${innerHeight}px`)

View File

@@ -1,10 +1,9 @@
import { error } from '@sveltejs/kit'
import type { PageServerLoad } from './$types'
import { fetchAPI } from '$utils/api'
import { getRandomItems } from 'utils/array'
export const load = (async ({ setHeaders }) => {
export const load = async ({ setHeaders }) => {
try {
// Get total of published photos
const totalRes = await fetchAPI(`query {
@@ -53,4 +52,4 @@ export const load = (async ({ setHeaders }) => {
} catch (err) {
throw error(500, err.message)
}
}) satisfies PageServerLoad
}

View File

@@ -4,7 +4,6 @@
<script lang="ts">
import { navigating } from '$app/stores'
import type { PageData } from './$types'
import { getContext, onMount } from 'svelte'
import { timeline, stagger } from 'motion'
import { DELAY } from '$utils/constants'
@@ -28,7 +27,7 @@
import ShopModule from '$components/organisms/ShopModule.svelte'
import NewsletterModule from '$components/organisms/NewsletterModule.svelte'
export let data: PageData
export let data
const { photos } = data
const { settings, locations }: any = getContext('global')

View File

@@ -1,8 +1,7 @@
import { NEWSLETTER_API_TOKEN, NEWSLETTER_LIST_ID } from '$env/static/private'
import type { RequestHandler } from './$types'
export const POST = (async ({ request, fetch }) => {
export const POST = async ({ request, fetch }) => {
const data: { email: string } = await request.json()
const { email } = data
@@ -38,4 +37,4 @@ export const POST = (async ({ request, fetch }) => {
}), {
status: 200
})
}) satisfies RequestHandler
}

View File

@@ -1,9 +1,8 @@
import { error } from '@sveltejs/kit'
import type { RequestHandler } from './$types'
import { fetchAPI } from '$utils/api'
export const GET = (async ({ url, setHeaders }) => {
export const GET = async ({ url, setHeaders }) => {
try {
const locations = []
const products = []
@@ -72,7 +71,7 @@ export const GET = (async ({ url, setHeaders }) => {
} catch (err) {
throw error(500, err.message)
}
}) satisfies RequestHandler
}
const render = (origin: string, pages: any[]) => {