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}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected $filterScopes = [];
|
protected $filterScopes = [
|
||||||
|
'tags' => 'withAllTags',
|
||||||
|
'tags.all' => 'withAllTags',
|
||||||
|
'tags.any' => 'withAnyTags',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
|
|
@ -20,7 +20,11 @@ class RecipeAdapter extends AbstractAdapter
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected $filterScopes = [];
|
protected $filterScopes = [
|
||||||
|
'tags' => 'withAllTags',
|
||||||
|
'tags.all' => 'withAllTags',
|
||||||
|
'tags.any' => 'withAnyTags',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
|
|
@ -42,9 +42,11 @@
|
||||||
size: 12,
|
size: 12,
|
||||||
morePages: false,
|
morePages: false,
|
||||||
searchTerm: '{{ $defaultSearch ?? null }}',
|
searchTerm: '{{ $defaultSearch ?? null }}',
|
||||||
|
filterTag: null,
|
||||||
reset() {
|
reset() {
|
||||||
this.number = 1;
|
this.number = 1;
|
||||||
this.searchTerm = null;
|
this.searchTerm = null;
|
||||||
|
this.filterTag = null;
|
||||||
this.morePages = false;
|
this.morePages = false;
|
||||||
},
|
},
|
||||||
loadMore() {
|
loadMore() {
|
||||||
|
@ -52,6 +54,9 @@
|
||||||
if (this.searchTerm) {
|
if (this.searchTerm) {
|
||||||
url += `&filter[search]=${this.searchTerm}`;
|
url += `&filter[search]=${this.searchTerm}`;
|
||||||
}
|
}
|
||||||
|
if (this.filterTag) {
|
||||||
|
url += `&filter[tags]=${this.filterTag}`;
|
||||||
|
}
|
||||||
fetch(url)
|
fetch(url)
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
@ -69,14 +74,13 @@
|
||||||
this.reset();
|
this.reset();
|
||||||
if (e.target.value !== '') {
|
if (e.target.value !== '') {
|
||||||
this.searchTerm = e.target.value;
|
this.searchTerm = e.target.value;
|
||||||
this.loadMore();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.loadMore();
|
|
||||||
}
|
}
|
||||||
|
this.loadMore();
|
||||||
},
|
},
|
||||||
filterByTag(e) {
|
filterByTag(e) {
|
||||||
console.log(e.target.text);
|
this.reset();
|
||||||
|
this.filterTag = e.target.text;
|
||||||
|
this.loadMore();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue