NEXT craftinamerica.org. Base setup for headless wordpress https://www.craftinamerica.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

search.js 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import api from '../../utils/api'
  2. const state = {
  3. all: [],
  4. loaded: false,
  5. }
  6. const getters = {
  7. allSearchResults: state => state.all,
  8. allSearchResultsLoaded: state => state.loaded,
  9. }
  10. const actions = {
  11. async getMoreSearchResults({ commit }, { params }) {
  12. const storeFetch = (searchResults => {
  13. commit('ADD_TO_FETCHED_SEARCH_RESULTS', { searchResults })
  14. commit('SEARCH_RESULTS_LOADED', true)
  15. })
  16. return await api.getByType({ type: 'search', params, cb: storeFetch })
  17. }
  18. }
  19. const mutations = {
  20. ADD_TO_FETCHED_SEARCH_RESULTS(state, { searchResults }) {
  21. console.log('adding results', searchResults)
  22. state.all = [...state.all, ...searchResults]
  23. },
  24. STORE_FETCHED_SEARCH_RESULTS(state, { searchResults }) {
  25. state.all = searchResults
  26. },
  27. CLEAR_SEARCH_RESULTS(state) {
  28. state.all = []
  29. },
  30. SEARCH_RESULTS_LOADED(state, val) {
  31. state.loaded = val
  32. },
  33. }
  34. export default { state, getters, actions, mutations }