Fix Photos page reactivity when changing country

This commit is contained in:
2021-10-23 15:34:28 +02:00
parent f8f6872b5e
commit eb026cabad
2 changed files with 35 additions and 37 deletions

View File

@@ -8,6 +8,7 @@
import dayjs from 'dayjs' import dayjs from 'dayjs'
import relativeTime from 'dayjs/plugin/relativeTime.js' import relativeTime from 'dayjs/plugin/relativeTime.js'
import { map, lerp } from '$utils/functions' import { map, lerp } from '$utils/functions'
import { getAssetUrlKey } from '$utils/helpers'
// Components // Components
import Metas from '$components/Metas.svelte' import Metas from '$components/Metas.svelte'
import IconEarth from '$components/atoms/IconEarth.svelte' import IconEarth from '$components/atoms/IconEarth.svelte'
@@ -28,7 +29,7 @@
const { countries }: any = getContext('global') const { countries }: any = getContext('global')
let buttonReset: HTMLElement let buttonReset: HTMLElement
let buttonShuffle: HTMLElement // let buttonShuffle: HTMLElement
let scrollY: number let scrollY: number
let innerWidth: number, innerHeight: number let innerWidth: number, innerHeight: number
@@ -40,6 +41,7 @@
let countryFlagId: string let countryFlagId: string
$: filtered = filterCountry !== defaultCountry || filterSort !== defaultSort $: filtered = filterCountry !== defaultCountry || filterSort !== defaultSort
$: latestPhoto = photos[0] $: latestPhoto = photos[0]
$: currentCountry = countries.find((country: any) => country.slug === filterCountry)
// Pages related informations // Pages related informations
let currentPage: number = 1 let currentPage: number = 1
@@ -61,23 +63,19 @@
/** /**
* Define URL params * Define URL params
*/ */
$: { $: countryFlagId = currentCountry ? currentCountry.flag.id : undefined
// Define country flag from selection
if (filterCountry !== defaultCountry) {
countryFlagId = countries.find((country: any) => country.slug === filterCountry).flag.id
} else {
countryFlagId = undefined
}
// Update URL filtering params from filter values // Update URL filtering params from filter values
if (browser) { $: if (browser) {
urlFiltersParams.set('country', filterCountry) urlFiltersParams.set('country', filterCountry)
urlFiltersParams.set('sort', filterSort) urlFiltersParams.set('sort', filterSort)
goto(`${$page.path}?${urlFiltersParams.toString()}`, { replaceState: true, keepfocus: true, noscroll: true })
} let path: string = `${$page.path}?${urlFiltersParams.toString()}`
goto(path, { replaceState: true, keepfocus: true, noscroll: true })
} }
/** /**
* Select change events * Select change events
*/ */
@@ -164,7 +162,7 @@
</script> </script>
<Metas <Metas
title="Photos" title="Houses Of - {filterCountry === defaultCountry ? `Photos` : `Photos of ${currentCountry.name}`}"
description="" description=""
image="" image=""
/> />

View File

@@ -1,27 +1,6 @@
import { API_URL } from '$utils/api' import { API_URL } from '$utils/api'
/**
* Get a Directus asset URL from parameters
*/
export const getAssetUrl = (
id: string,
width: number,
height: number,
quality?: number,
fit: string = 'inside',
format?: string
) => {
let args = ''
// Add arguments to URL if specified
if (quality) args += `&quality=${quality}`
if (format) args += `&format=${format}`
return `${API_URL}/assets/${id}?width=${width}&height=${height}&fit=${fit}${args}`
}
/** /**
* Get a Directus asset URL from parameters * Get a Directus asset URL from parameters
*/ */
@@ -30,4 +9,25 @@ export const getAssetUrlKey = (
key: string key: string
) => { ) => {
return `${API_URL}/assets/${id}?key=${key}` return `${API_URL}/assets/${id}?key=${key}`
} }
/**
* Get a Directus asset URL from parameters
*/
// export const getAssetUrl = (
// id: string,
// width: number,
// height: number,
// quality?: number,
// fit: string = 'inside',
// format?: string
// ) => {
// let args = ''
// // Add arguments to URL if specified
// if (quality) args += `&quality=${quality}`
// if (format) args += `&format=${format}`
// return `${API_URL}/assets/${id}?width=${width}&height=${height}&fit=${fit}${args}`
// }