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> <script>
import axios from 'axios'; import axios from 'axios';
import { mapMutations } from 'vuex'
export default { export default {
name: "Search", name: "Search",
@ -63,6 +64,7 @@ export default {
methods: { methods: {
search: function() { search: function() {
console.log(this.search_text) console.log(this.search_text)
this.setSearchText(this.search_text)
var search_url = this.api_endpoint + this.search_text; var search_url = this.api_endpoint + this.search_text;
var self = this; var self = this;
@ -70,25 +72,27 @@ export default {
}) })
.then(function (response) { .then(function (response) {
console.log(response.data) console.log(response.data)
//self.sites = response.data self.setFilteredSites(response.data)
}) })
.catch(function (error) { .catch(function (error) {
console.log(error); console.log(error);
}); });
},
}
/* /*
site_url: function(slug) { site_url: function(slug) {
return this.base_url + '/s/' + slug return this.base_url + '/s/' + slug
} }
*/ */
...mapMutations([
'setFilteredSites', 'setSearchText'
]),
}, },
watched: { watched: {
}, },
computed: { computed: {
api_endpoint: function() { 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({ const store = new Vuex.Store({
state: { state: {
search_text: "",
sites: [], sites: [],
filtered_sites: [],
}, },
mutations: { mutations: {
setSearchText(state, text) {
state.search_text = text
},
setSites(state, sites) { setSites(state, sites) {
state.sites = 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: { getters: {
/*
getSites: state => { getSites: state => {
return state.sites return state.sites
}, },
*/
getDisplayedSites: state => { getDisplayedSites: state => {
return state.sites if (state.search_text === "") {
return state.sites
}
return state.filtered_sites
}, },
} }
}) })