import api from '../../utils/api' const state = { all: [], loaded: false, } const getters = { allSearchResults: state => state.all, allSearchResultsLoaded: state => state.loaded, } const actions = { async getMoreSearchResults({ commit }, { params }) { const storeFetch = (searchResults => { commit('ADD_TO_FETCHED_SEARCH_RESULTS', { searchResults }) commit('SEARCH_RESULTS_LOADED', true) }) return await api.getByType({ type: 'search', params, cb: storeFetch }) } } const mutations = { ADD_TO_FETCHED_SEARCH_RESULTS(state, { searchResults }) { console.log('adding results', searchResults) state.all = [...state.all, ...searchResults] }, STORE_FETCHED_SEARCH_RESULTS(state, { searchResults }) { state.all = searchResults }, CLEAR_SEARCH_RESULTS(state) { state.all = [] }, SEARCH_RESULTS_LOADED(state, val) { state.loaded = val }, } export default { state, getters, actions, mutations }