Arc-hive-list/src/store.js
2021-11-04 13:01:02 +01:00

51 lines
1,018 B
JavaScript

/*
This file is part of ArciveList.
# SPDX-FileCopyrightText: 2021 Hangar.org
# SPDX-License-Identifier: AGPL-3.0-or-later
*/
import Vue from 'vue'
import Vuex from 'vuex'
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: {
getDisplayedSites: state => {
if (state.search_text === "") {
return state.sites
}
return state.filtered_sites
},
}
})
export default store