[wip] Make Select filters reactive
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { browser } from '$app/env'
|
||||||
|
import { page } from '$app/stores'
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
import { getContext } from 'svelte'
|
import { getContext } from 'svelte'
|
||||||
import { fly } from 'svelte/transition'
|
import { fly } from 'svelte/transition'
|
||||||
import { quartOut } from 'svelte/easing'
|
import { quartOut } from 'svelte/easing'
|
||||||
@@ -28,13 +31,32 @@
|
|||||||
let filterSort: string = defaultSort
|
let filterSort: string = defaultSort
|
||||||
let countryFlagId: string
|
let countryFlagId: string
|
||||||
|
|
||||||
// Define country flag from selection
|
// Define URL params
|
||||||
|
let urlFiltersParams: URLSearchParams
|
||||||
|
if (browser) {
|
||||||
|
urlFiltersParams = new URLSearchParams(window.location.pathname)
|
||||||
|
}
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
|
// Define country flag from selection
|
||||||
if (filterCountry !== defaultCountry) {
|
if (filterCountry !== defaultCountry) {
|
||||||
countryFlagId = countries.find((country: any) => country.slug === filterCountry).flag.id
|
countryFlagId = countries.find((country: any) => country.slug === filterCountry).flag.id
|
||||||
} else {
|
} else {
|
||||||
countryFlagId = undefined
|
countryFlagId = undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update URL filtering params from filter values
|
||||||
|
// if (filtered && filterCountry && filterSort) {
|
||||||
|
// urlFiltersParams.set('country', filterCountry)
|
||||||
|
// urlFiltersParams.set('sort', filterSort)
|
||||||
|
// goto(`${$page.path}?${urlFiltersParams.toString()}`, { noscroll: true })
|
||||||
|
|
||||||
|
// // TODO: Request photos from the country of choice
|
||||||
|
// // loadPhotos()
|
||||||
|
// console.log('load photos')
|
||||||
|
// }
|
||||||
|
|
||||||
|
console.log({ filtered, filterCountry, filterSort })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -43,22 +65,16 @@
|
|||||||
*/
|
*/
|
||||||
// Country select
|
// Country select
|
||||||
const handleCountryChange = ({ detail: value }) => {
|
const handleCountryChange = ({ detail: value }) => {
|
||||||
console.log(value)
|
console.log('country change:', value)
|
||||||
filtered = true
|
filtered = true
|
||||||
filterCountry = value
|
filterCountry = value
|
||||||
|
|
||||||
// TODO: Request photos from the country of choice
|
|
||||||
// TODO: Change URL query sort=value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort select
|
// Sort select
|
||||||
const handleSortChange = ({ detail: value }) => {
|
const handleSortChange = ({ detail: value }) => {
|
||||||
console.log(value)
|
console.log('sort change:', value)
|
||||||
filtered = true
|
filtered = true
|
||||||
filterSort = value
|
filterSort = value
|
||||||
|
|
||||||
// TODO: Request photos sorted by the choice
|
|
||||||
// TODO: Change URL query sort=value
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -69,18 +85,34 @@
|
|||||||
filtered = false
|
filtered = false
|
||||||
filterCountry = defaultCountry
|
filterCountry = defaultCountry
|
||||||
filterSort = defaultSort
|
filterSort = defaultSort
|
||||||
|
goto($page.path, { replaceState: true, noscroll: true })
|
||||||
// TODO: Change URL query sort=defaultSort and country=defaultCountry
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load more photos from CTA
|
* Load photos
|
||||||
*/
|
*/
|
||||||
|
// Load more photos from CTA
|
||||||
const loadMorePhotos = () => {
|
const loadMorePhotos = () => {
|
||||||
console.log('load more photos')
|
console.log('load more photos')
|
||||||
// TODO: Append more photos from API including options and page
|
// TODO: Append more photos from API including options and page
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load photos
|
||||||
|
const loadPhotos = async (page?: number, params?: string) => {
|
||||||
|
const res = fetchAPI(`
|
||||||
|
query {
|
||||||
|
photo (limit: 11, sort: ["-date_created"]) {
|
||||||
|
image {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
const { data } = await res
|
||||||
|
console.log(data)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Metas
|
<Metas
|
||||||
|
|||||||
Reference in New Issue
Block a user