renders filtered sites

This commit is contained in:
buttle 2021-11-04 12:52:10 +01:00
parent f515da4a9f
commit 73147144e7
2 changed files with 31 additions and 5 deletions

View File

@ -29,6 +29,7 @@ This file is part of ArciveList.
<script>
import axios from 'axios';
import { mapMutations } from 'vuex'
export default {
name: "Search",
@ -63,6 +64,7 @@ export default {
methods: {
search: function() {
console.log(this.search_text)
this.setSearchText(this.search_text)
var search_url = this.api_endpoint + this.search_text;
var self = this;
@ -70,25 +72,27 @@ export default {
})
.then(function (response) {
console.log(response.data)
//self.sites = response.data
self.setFilteredSites(response.data)
})
.catch(function (error) {
console.log(error);
});
}
},
/*
site_url: function(slug) {
return this.base_url + '/s/' + slug
}
*/
...mapMutations([
'setFilteredSites', 'setSearchText'
]),
},
watched: {
},
computed: {
api_endpoint: function() {
return '/api/sites?search='
return '/api/collections/search?fulltext_search='
},
}
};

View File

@ -13,19 +13,41 @@ Vue.use(Vuex)
const store = new Vuex.Store({
state: {
search_text: "",
sites: [],
filtered_sites: [],
},
mutations: {
setSearchText(state, text) {
state.search_text = text
},
setSites(state, sites) {
state.sites = sites
},
setFilteredSites(state, filtered_site_ids) {
console.log(filtered_site_ids)
var sites = []
for (const [site_id, weight] of Object.entries(filtered_site_ids)) {
var site = state.sites.find(x => x.id == site_id)
if (site) {
console.log('push')
sites.push(site)
}
}
state.filtered_sites = sites
},
},
getters: {
/*
getSites: state => {
return state.sites
},
*/
getDisplayedSites: state => {
return state.sites
if (state.search_text === "") {
return state.sites
}
return state.filtered_sites
},
}
})