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:
parent
7a6c154e5f
commit
4b0775b5ea
1 changed files with 13 additions and 9 deletions
|
|
@ -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 || "");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue