mirror of https://github.com/kcal-app/kcal.git
Add tag filter handling
This commit is contained in:
parent
794c0712bc
commit
a14b58483a
|
@ -19,7 +19,11 @@ class FoodAdapter extends AbstractAdapter
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $filterScopes = [];
|
||||
protected $filterScopes = [
|
||||
'tags' => 'withAllTags',
|
||||
'tags.all' => 'withAllTags',
|
||||
'tags.any' => 'withAnyTags',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -20,7 +20,11 @@ class RecipeAdapter extends AbstractAdapter
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $filterScopes = [];
|
||||
protected $filterScopes = [
|
||||
'tags' => 'withAllTags',
|
||||
'tags.all' => 'withAllTags',
|
||||
'tags.any' => 'withAnyTags',
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -42,9 +42,11 @@
|
|||
size: 12,
|
||||
morePages: false,
|
||||
searchTerm: '{{ $defaultSearch ?? null }}',
|
||||
filterTag: null,
|
||||
reset() {
|
||||
this.number = 1;
|
||||
this.searchTerm = null;
|
||||
this.filterTag = null;
|
||||
this.morePages = false;
|
||||
},
|
||||
loadMore() {
|
||||
|
@ -52,6 +54,9 @@
|
|||
if (this.searchTerm) {
|
||||
url += `&filter[search]=${this.searchTerm}`;
|
||||
}
|
||||
if (this.filterTag) {
|
||||
url += `&filter[tags]=${this.filterTag}`;
|
||||
}
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
|
@ -69,14 +74,13 @@
|
|||
this.reset();
|
||||
if (e.target.value !== '') {
|
||||
this.searchTerm = e.target.value;
|
||||
this.loadMore();
|
||||
}
|
||||
else {
|
||||
this.loadMore();
|
||||
}
|
||||
this.loadMore();
|
||||
},
|
||||
filterByTag(e) {
|
||||
console.log(e.target.text);
|
||||
this.reset();
|
||||
this.filterTag = e.target.text;
|
||||
this.loadMore();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue