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