feat(ProductFilterViewModel): enhance URL parameter handling

Improve loading of search, ranges, tags, and brands from URL.
Trigger loading state and refresh list when filters are applied.
This commit is contained in:
Jérémy Munsch 2026-10-28 11:36:40 +01:00
parent 7a6c154e5f
commit 4b0775b5ea
No known key found for this signature in database
GPG key ID: 2AAECDA6B7330F91

View file

@ -143,28 +143,32 @@ export class ProductFilterViewModel {
const urlParams = new URL(document.location.href).searchParams;
const urlSearch = urlParams.get("search")?.trim() ?? "";
if (urlSearch) {
this.store.setSearchValue(urlSearch);
}
this.searchValue.value = this.store.currentSearchValue;
const urlRanges = urlParams
.getAll("ranges[]")
.map(v => Number.parseInt(v.trim(), 10))
.filter(v => !Number.isNaN(v)) as RangeId[];
this.store.setActiveRanges(urlRanges);
const urlTags = urlParams
.getAll("tags[]")
.map(v => Number.parseInt(v.trim(), 10))
.filter(v => !Number.isNaN(v)) as TagId[];
this.store.setActiveTags(urlTags);
const urlBrands = urlParams
.getAll("brands[]")
.map(v => v.trim())
.filter(v => v.length) as BrandValue[];
if (urlSearch.length) {
this.store.setSearchValue(urlSearch);
}
this.store.setActiveRanges(urlRanges);
this.store.setActiveTags(urlTags);
this.store.setActiveBrands(urlBrands);
this.searchValue.value = this.store.currentSearchValue;
if (urlSearch.length || urlRanges.length || urlTags.length || urlBrands.length) {
this.store.setLoading(true);
this.refreshList();
}
watch(this.searchValue, (newValue) => {
const cleanText = String(newValue || "");