| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import api from '../../utils/api'
-
- // initial state
- const state = {
- all: [],
- loaded: false,
- singlePage: null,
- }
-
- // getters
- const getters = {
- allPages: state => state.all,
- allPagesLoaded: state => state.loaded,
- }
-
- // actions
- const actions = {
- async getAllPages({ commit }, { sortType, params }) {
- commit('PAGES_LOADED', false)
- return await api.getByType({
- type: 'page',
- sort: sortType,
- params,
- cb: pages => {
- commit('STORE_FETCHED_PAGES', { pages })
- commit('PAGES_LOADED', true)
- },
- })
- },
- getSinglePage({ commit }, id) {
- commit('CLEAR_SINGLE_PAGE')
- commit('PAGES_LOADED', false)
- return api.getSingleType('page', id, page => {
- commit('STORE_FETCHED_SINGLE_PAGE', page)
- commit('PAGES_LOADED', true)
- })
- },
- }
-
- // mutations
- const mutations = {
- STORE_FETCHED_PAGES(state, { pages }) {
- state.all = pages
- },
- STORE_FETCHED_SINGLE_PAGE(state, page) {
- state.singlePage = page
- },
- CLEAR_PAGES(state) {
- state.all = []
- },
- CLEAR_SINGLE_PAGE(state) {
- state.singlePage = null
- },
- PAGES_LOADED(state, val) {
- state.loaded = val
- },
- }
-
- export default { state, getters, actions, mutations }
|