diff --git a/resources/views/components/search-view.blade.php b/resources/views/components/search-view.blade.php
index 150aef8..f431b02 100644
--- a/resources/views/components/search-view.blade.php
+++ b/resources/views/components/search-view.blade.php
@@ -8,11 +8,14 @@
class="w-full mb-4"
@input.debounce.400ms="search($event)" />
- Tags
- @foreach($tags as $tag)
- {{ $tag->name }}
- @endforeach
+ Filters
+ Tags
+
@@ -42,11 +45,9 @@
size: 12,
morePages: false,
searchTerm: '{{ $defaultSearch ?? null }}',
- filterTag: null,
- reset() {
+ filterTags: [],
+ resetPagination() {
this.number = 1;
- this.searchTerm = null;
- this.filterTag = null;
this.morePages = false;
},
loadMore() {
@@ -54,9 +55,7 @@
if (this.searchTerm) {
url += `&filter[search]=${this.searchTerm}`;
}
- if (this.filterTag) {
- url += `&filter[tags]=${this.filterTag}`;
- }
+ this.filterTags.every(tag => url += `&filter[tags.all][]=${tag}`)
fetch(url)
.then(response => response.json())
.then(data => {
@@ -71,15 +70,26 @@
});
},
search(e) {
- this.reset();
+ this.resetPagination();
if (e.target.value !== '') {
this.searchTerm = e.target.value;
}
+ else {
+ this.searchTerm = null;
+ }
this.loadMore();
},
- filterByTag(e) {
- this.reset();
- this.filterTag = e.target.text;
+ updateFilters(e) {
+ this.resetPagination();
+ const newTag = e.target.text;
+ if (this.filterTags.includes(newTag)) {
+ this.filterTags = this.filterTags.filter(tag => tag !== newTag)
+ e.target.classList.remove('bg-gray-600', 'text-white');
+ }
+ else {
+ this.filterTags.push(newTag)
+ e.target.classList.add('bg-gray-600', 'text-white');
+ }
this.loadMore();
}
}