From fd150e252c916053331e96d12f4281ccb1ca80ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Sat, 9 Oct 2021 18:59:38 +0200 Subject: [PATCH] [wip] Implement photos loading and make everything dynamic - Handle what happens when we click on Load more photos (detect if can load next or if reached the end) - Show the current and total amount of photos (WIP as it apparently can't be filtered for aggregated) - See filtered photos from URL when coming directly - Disable button when all photos has been seen - Show message if location doesn't exist --- .env.local | 6 +- src/components/atoms/Button.svelte | 3 +- src/routes/photos.svelte | 201 ++++++++++++++++++++++------- src/style/pages/_photos.scss | 23 +++- 4 files changed, 180 insertions(+), 53 deletions(-) diff --git a/.env.local b/.env.local index 2a3c738..cb77b78 100644 --- a/.env.local +++ b/.env.local @@ -1,8 +1,10 @@ # Options VITE_LIMIT_TIME=2 * 7 * 24 * 60 * 60 * 1000 VITE_PREVIEW_COUNT=4 -VITE_GRID_AMOUNT=21 -VITE_GRID_INCREMENT=21 +VITE_GRID_AMOUNT=22 +VITE_GRID_INCREMENT=22 +VITE_LIST_AMOUNT=10 +VITE_LIST_INCREMENT=10 # API related # VITE_API_URL_DEV="http://192.168.1.19:8055" diff --git a/src/components/atoms/Button.svelte b/src/components/atoms/Button.svelte index 34917e7..97eb2ad 100644 --- a/src/components/atoms/Button.svelte +++ b/src/components/atoms/Button.svelte @@ -2,6 +2,7 @@ export let text: string export let tag: string = 'a' export let url: string = undefined + export let disabled: boolean = undefined const classes = [ 'button', @@ -10,7 +11,7 @@ {#if tag === 'button'} - diff --git a/src/routes/photos.svelte b/src/routes/photos.svelte index eedb77c..c4a948b 100644 --- a/src/routes/photos.svelte +++ b/src/routes/photos.svelte @@ -1,10 +1,11 @@ @@ -136,10 +180,15 @@
-
- {#each Array(22 * 2) as _} - - {/each} -
- -
-

Last updated: 4 days ago

-
+ {:else if !filteredCountryExists} +
+

+ {$page.query.get('country').replace(/(^|\s)\S/g, letter => letter.toUpperCase())} is not available… yet 👀 +

+
+ {/if}
@@ -226,14 +292,48 @@ import { fetchAPI } from '$utils/api' export async function load ({ page, session, fetch, context }) { - // TODO: Implement query parameters from URL (country, sort) + // Query parameters + const queryCountry = page.query.get('country') + const querySort = page.query.get('sort') + const res = await fetchAPI(` query { - photo (limit: 11, sort: ["-date_created"]) { + photos: photo ( + filter: { + ${queryCountry ? `location: { country: { slug: { _eq: "${queryCountry}" }} },` : ''} + status: { _eq: "published" }, + }, + sort: "${querySort === 'latest' ? '-' : ''}date_created", + limit: ${import.meta.env.VITE_GRID_AMOUNT}, + page: 1, + ) { + title + slug image { id title } + location { + slug + country { slug } + } + } + + total_published: photo_aggregated { + count { id } + } + + country: country ( + filter: { + slug: { _eq: "${queryCountry}" }, + status: { _eq: "published" }, + }, + ) { + slug + } + + lastUpdated: photo (limit: 1, sort: "-date_created", filter: { status: { _eq: "published" }}) { + date_created } } `) @@ -242,7 +342,10 @@ return { props: { - photos: data.photo, + photos: data.photos, + filteredCountryExists: data.country.length > 0, + totalPhotos: data.total_published[0].count.id, + lastUpdated: data.lastUpdated[0].date_created, } } } diff --git a/src/style/pages/_photos.scss b/src/style/pages/_photos.scss index 5556881..02ced93 100644 --- a/src/style/pages/_photos.scss +++ b/src/style/pages/_photos.scss @@ -324,6 +324,20 @@ } } + + // Message + &__message { + // grid-column: ; + text-align: center; + padding: clamp(48px, 10vw, 160px) 0; + color: $color-text; + + @include bp (sm) { + grid-column: 3 / span 20; + } + } + + /** * Controls */ @@ -361,12 +375,14 @@ // See More Photos .button { + $color-button: #F2D3B8; grid-column: span var(--columns); grid-row: 1; margin: 0 auto; height: 56px; - background-color: #F2D3B8; + background-color: $color-button; font-size: rem(16px); + border: none; @include bp (sm) { grid-column: 6 / span 12; @@ -374,6 +390,11 @@ padding: 0 40px; font-size: rem(18px); } + + &[disabled] { + background: none; + border: 2px solid darken($color-button, 2); + } } // Photo Count