From 7a165721d95d74857b54a2a4e37a42e06507802b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Mon, 30 May 2022 21:54:43 +0200 Subject: [PATCH] [chore] Switch rest of page endpoints --- package.json | 4 +- pnpm-lock.yaml | 74 +++++++-------- .../[country]/[location]/[photo].svelte | 91 +----------------- src/routes/[country]/[location]/[photo].ts | 95 +++++++++++++++++++ src/routes/[country]/[location]/index.svelte | 74 +-------------- src/routes/[country]/[location]/index.ts | 76 +++++++++++++++ src/routes/credits.svelte | 43 +-------- src/routes/credits.ts | 45 +++++++++ src/routes/index.ts | 2 +- src/routes/photos.ts | 1 + 10 files changed, 262 insertions(+), 243 deletions(-) create mode 100644 src/routes/[country]/[location]/[photo].ts create mode 100644 src/routes/[country]/[location]/index.ts create mode 100644 src/routes/credits.ts diff --git a/package.json b/package.json index 8f19182..3cab3e1 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,8 @@ "@sveltejs/adapter-vercel": "^1.0.0-next.56", "@sveltejs/kit": "next", "@types/animejs": "^3.1.4", - "@typescript-eslint/eslint-plugin": "^5.26.0", - "@typescript-eslint/parser": "^5.26.0", + "@typescript-eslint/eslint-plugin": "^5.27.0", + "@typescript-eslint/parser": "^5.27.0", "eslint": "^8.16.0", "eslint-plugin-svelte3": "^4.0.0", "sass": "^1.52.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7fec795..c71b1b2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -6,8 +6,8 @@ specifiers: '@sveltejs/adapter-vercel': ^1.0.0-next.56 '@sveltejs/kit': next '@types/animejs': ^3.1.4 - '@typescript-eslint/eslint-plugin': ^5.26.0 - '@typescript-eslint/parser': ^5.26.0 + '@typescript-eslint/eslint-plugin': ^5.27.0 + '@typescript-eslint/parser': ^5.27.0 animejs: ^3.2.1 dayjs: ^1.11.2 embla-carousel: ^6.2.0 @@ -36,8 +36,8 @@ devDependencies: '@sveltejs/adapter-vercel': 1.0.0-next.56 '@sveltejs/kit': 1.0.0-next.345_sass@1.52.1+svelte@3.48.0 '@types/animejs': 3.1.4 - '@typescript-eslint/eslint-plugin': 5.26.0_hzuh7e2up357pvq3mkokjvu2lq - '@typescript-eslint/parser': 5.26.0_xztl6dhthcahlo6akmb2bmjmle + '@typescript-eslint/eslint-plugin': 5.27.0_dszb5tb7atwkjjijmmov4qhi7i + '@typescript-eslint/parser': 5.27.0_xztl6dhthcahlo6akmb2bmjmle eslint: 8.16.0 eslint-plugin-svelte3: 4.0.0_vypdqzeyqutkgs6qzc7qod4c64 sass: 1.52.1 @@ -257,8 +257,8 @@ packages: '@types/node': 17.0.36 dev: true - /@typescript-eslint/eslint-plugin/5.26.0_hzuh7e2up357pvq3mkokjvu2lq: - resolution: {integrity: sha512-oGCmo0PqnRZZndr+KwvvAUvD3kNE4AfyoGCwOZpoCncSh4MVD06JTE8XQa2u9u+NX5CsyZMBTEc2C72zx38eYA==} + /@typescript-eslint/eslint-plugin/5.27.0_dszb5tb7atwkjjijmmov4qhi7i: + resolution: {integrity: sha512-DDrIA7GXtmHXr1VCcx9HivA39eprYBIFxbQEHI6NyraRDxCGpxAFiYQAT/1Y0vh1C+o2vfBiy4IuPoXxtTZCAQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: '@typescript-eslint/parser': ^5.0.0 @@ -268,10 +268,10 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/parser': 5.26.0_xztl6dhthcahlo6akmb2bmjmle - '@typescript-eslint/scope-manager': 5.26.0 - '@typescript-eslint/type-utils': 5.26.0_xztl6dhthcahlo6akmb2bmjmle - '@typescript-eslint/utils': 5.26.0_xztl6dhthcahlo6akmb2bmjmle + '@typescript-eslint/parser': 5.27.0_xztl6dhthcahlo6akmb2bmjmle + '@typescript-eslint/scope-manager': 5.27.0 + '@typescript-eslint/type-utils': 5.27.0_xztl6dhthcahlo6akmb2bmjmle + '@typescript-eslint/utils': 5.27.0_xztl6dhthcahlo6akmb2bmjmle debug: 4.3.4 eslint: 8.16.0 functional-red-black-tree: 1.0.1 @@ -284,8 +284,8 @@ packages: - supports-color dev: true - /@typescript-eslint/parser/5.26.0_xztl6dhthcahlo6akmb2bmjmle: - resolution: {integrity: sha512-n/IzU87ttzIdnAH5vQ4BBDnLPly7rC5VnjN3m0xBG82HK6rhRxnCb3w/GyWbNDghPd+NktJqB/wl6+YkzZ5T5Q==} + /@typescript-eslint/parser/5.27.0_xztl6dhthcahlo6akmb2bmjmle: + resolution: {integrity: sha512-8oGjQF46c52l7fMiPPvX4It3u3V3JipssqDfHQ2hcR0AeR8Zge+OYyKUCm5b70X72N1qXt0qgHenwN6Gc2SXZA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 @@ -294,9 +294,9 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/scope-manager': 5.26.0 - '@typescript-eslint/types': 5.26.0 - '@typescript-eslint/typescript-estree': 5.26.0_typescript@4.7.2 + '@typescript-eslint/scope-manager': 5.27.0 + '@typescript-eslint/types': 5.27.0 + '@typescript-eslint/typescript-estree': 5.27.0_typescript@4.7.2 debug: 4.3.4 eslint: 8.16.0 typescript: 4.7.2 @@ -304,16 +304,16 @@ packages: - supports-color dev: true - /@typescript-eslint/scope-manager/5.26.0: - resolution: {integrity: sha512-gVzTJUESuTwiju/7NiTb4c5oqod8xt5GhMbExKsCTp6adU3mya6AGJ4Pl9xC7x2DX9UYFsjImC0mA62BCY22Iw==} + /@typescript-eslint/scope-manager/5.27.0: + resolution: {integrity: sha512-VnykheBQ/sHd1Vt0LJ1JLrMH1GzHO+SzX6VTXuStISIsvRiurue/eRkTqSrG0CexHQgKG8shyJfR4o5VYioB9g==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - '@typescript-eslint/types': 5.26.0 - '@typescript-eslint/visitor-keys': 5.26.0 + '@typescript-eslint/types': 5.27.0 + '@typescript-eslint/visitor-keys': 5.27.0 dev: true - /@typescript-eslint/type-utils/5.26.0_xztl6dhthcahlo6akmb2bmjmle: - resolution: {integrity: sha512-7ccbUVWGLmcRDSA1+ADkDBl5fP87EJt0fnijsMFTVHXKGduYMgienC/i3QwoVhDADUAPoytgjbZbCOMj4TY55A==} + /@typescript-eslint/type-utils/5.27.0_xztl6dhthcahlo6akmb2bmjmle: + resolution: {integrity: sha512-vpTvRRchaf628Hb/Xzfek+85o//zEUotr1SmexKvTfs7czXfYjXVT/a5yDbpzLBX1rhbqxjDdr1Gyo0x1Fc64g==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: '*' @@ -322,7 +322,7 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/utils': 5.26.0_xztl6dhthcahlo6akmb2bmjmle + '@typescript-eslint/utils': 5.27.0_xztl6dhthcahlo6akmb2bmjmle debug: 4.3.4 eslint: 8.16.0 tsutils: 3.21.0_typescript@4.7.2 @@ -331,13 +331,13 @@ packages: - supports-color dev: true - /@typescript-eslint/types/5.26.0: - resolution: {integrity: sha512-8794JZFE1RN4XaExLWLI2oSXsVImNkl79PzTOOWt9h0UHROwJedNOD2IJyfL0NbddFllcktGIO2aOu10avQQyA==} + /@typescript-eslint/types/5.27.0: + resolution: {integrity: sha512-lY6C7oGm9a/GWhmUDOs3xAVRz4ty/XKlQ2fOLr8GAIryGn0+UBOoJDWyHer3UgrHkenorwvBnphhP+zPmzmw0A==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /@typescript-eslint/typescript-estree/5.26.0_typescript@4.7.2: - resolution: {integrity: sha512-EyGpw6eQDsfD6jIqmXP3rU5oHScZ51tL/cZgFbFBvWuCwrIptl+oueUZzSmLtxFuSOQ9vDcJIs+279gnJkfd1w==} + /@typescript-eslint/typescript-estree/5.27.0_typescript@4.7.2: + resolution: {integrity: sha512-QywPMFvgZ+MHSLRofLI7BDL+UczFFHyj0vF5ibeChDAJgdTV8k4xgEwF0geFhVlPc1p8r70eYewzpo6ps+9LJQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: typescript: '*' @@ -345,8 +345,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/types': 5.26.0 - '@typescript-eslint/visitor-keys': 5.26.0 + '@typescript-eslint/types': 5.27.0 + '@typescript-eslint/visitor-keys': 5.27.0 debug: 4.3.4 globby: 11.1.0 is-glob: 4.0.3 @@ -357,16 +357,16 @@ packages: - supports-color dev: true - /@typescript-eslint/utils/5.26.0_xztl6dhthcahlo6akmb2bmjmle: - resolution: {integrity: sha512-PJFwcTq2Pt4AMOKfe3zQOdez6InIDOjUJJD3v3LyEtxHGVVRK3Vo7Dd923t/4M9hSH2q2CLvcTdxlLPjcIk3eg==} + /@typescript-eslint/utils/5.27.0_xztl6dhthcahlo6akmb2bmjmle: + resolution: {integrity: sha512-nZvCrkIJppym7cIbP3pOwIkAefXOmfGPnCM0LQfzNaKxJHI6VjI8NC662uoiPlaf5f6ymkTy9C3NQXev2mdXmA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: eslint: ^6.0.0 || ^7.0.0 || ^8.0.0 dependencies: '@types/json-schema': 7.0.11 - '@typescript-eslint/scope-manager': 5.26.0 - '@typescript-eslint/types': 5.26.0 - '@typescript-eslint/typescript-estree': 5.26.0_typescript@4.7.2 + '@typescript-eslint/scope-manager': 5.27.0 + '@typescript-eslint/types': 5.27.0 + '@typescript-eslint/typescript-estree': 5.27.0_typescript@4.7.2 eslint: 8.16.0 eslint-scope: 5.1.1 eslint-utils: 3.0.0_eslint@8.16.0 @@ -375,11 +375,11 @@ packages: - typescript dev: true - /@typescript-eslint/visitor-keys/5.26.0: - resolution: {integrity: sha512-wei+ffqHanYDOQgg/fS6Hcar6wAWv0CUPQ3TZzOWd2BLfgP539rb49bwua8WRAs7R6kOSLn82rfEu2ro6Llt8Q==} + /@typescript-eslint/visitor-keys/5.27.0: + resolution: {integrity: sha512-46cYrteA2MrIAjv9ai44OQDUoCZyHeGIc4lsjCUX2WT6r4C+kidz1bNiR4017wHOPUythYeH+Sc7/cFP97KEAA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: - '@typescript-eslint/types': 5.26.0 + '@typescript-eslint/types': 5.27.0 eslint-visitor-keys: 3.3.0 dev: true @@ -2256,7 +2256,7 @@ packages: /wide-align/1.1.5: resolution: {integrity: sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==} dependencies: - string-width: 4.2.3 + string-width: 1.0.2 dev: true /word-wrap/1.2.3: diff --git a/src/routes/[country]/[location]/[photo].svelte b/src/routes/[country]/[location]/[photo].svelte index d3795d7..bdad9b7 100644 --- a/src/routes/[country]/[location]/[photo].svelte +++ b/src/routes/[country]/[location]/[photo].svelte @@ -6,6 +6,7 @@ import { scale } from 'svelte/transition' import { quartOut } from 'svelte/easing' import { getAssetUrlKey } from '$utils/helpers' + import { fetchAPI } from '$utils/api' import { previousPage } from '$utils/stores' import { throttle } from '$utils/functions' import { swipe } from '$utils/interactions/swipe' @@ -398,92 +399,4 @@ {/if} - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/routes/[country]/[location]/[photo].ts b/src/routes/[country]/[location]/[photo].ts new file mode 100644 index 0000000..dd86698 --- /dev/null +++ b/src/routes/[country]/[location]/[photo].ts @@ -0,0 +1,95 @@ +import type { RequestEvent, RequestHandlerOutput } from '@sveltejs/kit' +import { fetchAPI } from '$utils/api' + +export async function get({ params }: RequestEvent): Promise { + try { + // Get the first photo ID + const firstPhoto = await fetchAPI(` + query { + photo (search: "${params.photo}") { + id + } + } + `) + const firstPhotoId = firstPhoto?.data?.photo[0]?.id + + // TODO: use same request for both queries (photo.id) + const photosBeforeFirst = await fetchAPI(` + query { + count: photo_aggregated ( + filter: { + id: { _gt: ${firstPhotoId} }, + location: { slug: { _eq: "${params.location}" }}, + status: { _eq: "published" }, + }, + sort: "-id", + ) { + count { + id + } + } + } + `) + + // Define offset from the current count + const offset = Math.max(photosBeforeFirst?.data?.count[0]?.count.id - 5, 0) + const limit = 10 + + const res = await fetchAPI(` + query { + photos: photo ( + filter: { + location: { slug: { _eq: "${params.location}" }} + status: { _eq: "published" }, + }, + sort: "-date_created", + limit: ${limit}, + offset: ${offset}, + ) { + id + title + slug + date_taken + image { + id + title + } + city + } + + location (filter: { slug: { _eq: "${params.location}" }}) { + id + name + slug + country { + name + slug + } + } + + total_published: photo_aggregated (filter: { location: { slug: { _eq: "${params.location}" }}}) { + count { location } + } + } + `) + + const { data } = res + const currentIndex = data.photos.findIndex((photo: any) => photo.slug === params.photo) + + return { + body: { + photos: data.photos, + location: data.location[0], + currentIndex, + countPhotos: data.total_published[0].count.location, + limit, + offset, + } + } + } catch (error) { + return { + status: 404, + body: error, + } + } +} \ No newline at end of file diff --git a/src/routes/[country]/[location]/index.svelte b/src/routes/[country]/[location]/index.svelte index a337a69..8fe28b8 100644 --- a/src/routes/[country]/[location]/index.svelte +++ b/src/routes/[country]/[location]/index.svelte @@ -7,6 +7,7 @@ import dayjs from 'dayjs' import relativeTime from 'dayjs/plugin/relativeTime.js' import { getAssetUrlKey } from '$utils/helpers' + import { fetchAPI } from '$utils/api' import { DURATION } from '$utils/contants' // Components import Metas from '$components/Metas.svelte' @@ -348,75 +349,4 @@

{/if} - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/routes/[country]/[location]/index.ts b/src/routes/[country]/[location]/index.ts new file mode 100644 index 0000000..364fb7b --- /dev/null +++ b/src/routes/[country]/[location]/index.ts @@ -0,0 +1,76 @@ +import type { RequestEvent, RequestHandlerOutput } from '@sveltejs/kit' +import { fetchAPI } from '$utils/api' + +export async function get({ params }: RequestEvent): Promise { + try { + const { location } = params + + // Query + const res = await fetchAPI(` + query { + location ( + filter: { + slug: { _eq: "${location}" }, + status: { _eq: "published" }, + } + ) { + id + name + slug + description + date_updated + illustration_desktop { id } + illustration_desktop_2x { id } + illustration_mobile { id } + credits { + credit_id { + name + website + } + } + country { name } + has_poster + } + + photos: photo ( + filter: { + location: { slug: { _eq: "${location}" }} + }, + sort: "-date_created", + limit: ${import.meta.env.VITE_LIST_AMOUNT}, + page: 1, + ) { + title + slug + city + image { + id + title + } + date_taken + date_created + } + + # Total + total_published: photo_aggregated (filter: { location: { slug: { _eq: "${location}" }}}) { + count { location } + } + } + `) + + const { data } = res + + return { + body: { + location: data.location[0], + photos: data.photos, + totalPhotos: data.photos.length ? data.total_published[0].count.location : 0, + } + } + } catch (error) { + return { + status: 404, + body: error, + } + } +} \ No newline at end of file diff --git a/src/routes/credits.svelte b/src/routes/credits.svelte index ca2d68b..dabb73f 100644 --- a/src/routes/credits.svelte +++ b/src/routes/credits.svelte @@ -148,45 +148,4 @@ - - - - \ No newline at end of file + \ No newline at end of file diff --git a/src/routes/credits.ts b/src/routes/credits.ts new file mode 100644 index 0000000..5e7fab9 --- /dev/null +++ b/src/routes/credits.ts @@ -0,0 +1,45 @@ +import type { RequestEvent, RequestHandlerOutput } from '@sveltejs/kit' +import { fetchAPI } from '$utils/api' + +export async function get({}: RequestEvent): Promise { + try { + const res = await fetchAPI(` + query { + credits { + text + list + } + + credit (filter: { status: { _eq: "published" }}) { + name + website + location { + location_id (filter: { status: { _eq: "published" }}) { + name + slug + country { + slug + flag { + id + } + } + } + } + } + } + `) + + const { data } = res + + return { + body: { + data + } + } + } catch (error) { + return { + status: 404, + body: error, + } + } +} \ No newline at end of file diff --git a/src/routes/index.ts b/src/routes/index.ts index 2ffa9a4..a9b9ab1 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -30,10 +30,10 @@ export async function get({}: RequestEvent): Promise { photos: data.photo } } - } catch (error) { return { status: 404, + body: error, } } } \ No newline at end of file diff --git a/src/routes/photos.ts b/src/routes/photos.ts index b41a9e8..ee5c010 100644 --- a/src/routes/photos.ts +++ b/src/routes/photos.ts @@ -72,6 +72,7 @@ export async function get({ url }: RequestEvent): Promise } catch (error) { return { status: 404, + body: error, } } } \ No newline at end of file