| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import api from '../../utils/api'
- import { allBySlug, repackBySort } from './arrangements'
-
- const state = {
- all: [],
- loaded: false,
- singleGuide: null,
- }
-
- const getters = {
- allGuides: state => state.all,
- allGuidesBySlug: state => allBySlug(state),
- allGuidesLoaded: state => state.loaded,
- }
-
- const actions = {
- getAllGuides({ commit }, { sortType, params }) {
- commit('CLEAR_GUIDES')
- commit('GUIDES_LOADED', false)
- const storeFetch = guides => {
- let repacked = repackBySort(guides, sortType)
- commit('STORE_FETCHED_GUIDES', { guides: repacked })
- commit('GUIDES_LOADED', true)
- }
- return api.getByType({
- type: 'guide',
- sort: sortType,
- params,
- cb: storeFetch,
- })
- },
- getMoreGuides({ commit }, { sortType, params }) {
- const storeFetch = guides => {
- let repacked = guides
- commit('ADD_TO_FETCHED_GUIDES', { guides: repacked })
- commit('GUIDES_LOADED', true)
- }
- return api.getByType({
- type: 'guide',
- sort: sortType,
- params,
- cb: storeFetch,
- })
- },
- getSingleGuide({ commit }, id) {
- commit('CLEAR_SINGLE_GUIDES')
- commit('GUIDES_LOADED', false)
-
- return api.getSingleType('guide', id, guide => {
- commit('STORE_FETCHED_SINGLE_GUIDE', guide)
- commit('GUIDES_LOADED', true)
- })
- },
- }
-
- const mutations = {
- ADD_TO_FETCHED_GUIDES(state, { guides }) {
- state.all = [...state.all, ...guides]
- },
- STORE_FETCHED_GUIDES(state, { guides }) {
- state.all = guides
- },
- STORE_FETCHED_SINGLE_GUIDE(state, guide) {
- state.singleGuide = guide
- },
- CLEAR_GUIDES(state) {
- state.all = []
- },
- CLEAR_SINGLE_GUIDES(state) {
- state.singleGuide = null
- },
- GUIDES_LOADED(state, val) {
- state.loaded = val
- },
- }
-
- export default { state, getters, actions, mutations }
|