Add tag filter handling

This commit is contained in:
Christopher C. Wells 2021-02-27 06:06:15 -08:00 committed by Christopher Charbonneau Wells
parent 794c0712bc
commit a14b58483a
3 changed files with 19 additions and 7 deletions

View File

@ -19,7 +19,11 @@ class FoodAdapter extends AbstractAdapter
/**
* {@inheritdoc}
*/
protected $filterScopes = [];
protected $filterScopes = [
'tags' => 'withAllTags',
'tags.all' => 'withAllTags',
'tags.any' => 'withAnyTags',
];
/**
* {@inheritdoc}

View File

@ -20,7 +20,11 @@ class RecipeAdapter extends AbstractAdapter
/**
* {@inheritdoc}
*/
protected $filterScopes = [];
protected $filterScopes = [
'tags' => 'withAllTags',
'tags.all' => 'withAllTags',
'tags.any' => 'withAnyTags',
];
/**
* {@inheritdoc}

View File

@ -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();
}
}
}