| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- 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) {
- commit('PAGES_LOADED', false)
- return await api.getByType({ type: 'page', sort: sortType, cb: pages => {
- commit('STORE_FETCHED_PAGES', { pages })
- commit('PAGES_LOADED', true)
- }
- })
- },
- getSinglePage({ commit }, id) {
- commit('CLEAR_SINGLE_PAGE')
- commit('PAGES_LOADED', false)
- 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 }
|