| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import api from '../../utils/api'
- import { allBySlug, repackBySort } from './arrangements'
-
- const state = {
- all: [],
- loaded: false,
- singlePublication: null,
- }
-
- const getters = {
- allPublications: state => state.all,
- allPublicationsBySlug: state => allBySlug(state),
- allPublicationsLoaded: state => state.loaded,
- }
-
- const actions = {
- getAllPublications({ commit }, { sortType, params }) {
- commit('CLEAR_PUBLICATIONS')
- commit('PUBLICATIONS_LOADED', false)
- const storeFetch = publications => {
- let repacked = repackBySort(publications, sortType)
- commit('STORE_FETCHED_PUBLICATIONS', { publications: repacked })
- commit('PUBLICATIONS_LOADED', true)
- }
- return api.getByType({
- type: 'publication',
- sort: sortType,
- params,
- cb: storeFetch,
- })
- },
- getMorePublications({ commit }, { sortType, params }) {
- const storeFetch = publications => {
- let repacked = publications
- commit('ADD_TO_FETCHED_PUBLICATIONS', { publications: repacked })
- commit('PUBLICATIONS_LOADED', true)
- }
- return api.getByType({
- type: 'publication',
- sort: sortType,
- params,
- cb: storeFetch,
- })
- },
- getSinglePublication({ commit }, id) {
- commit('CLEAR_SINGLE_PUBLICATIONS')
- commit('PUBLICATIONS_LOADED', false)
-
- return api.getSingleType('publication', id, publication => {
- commit('STORE_FETCHED_SINGLE_PUBLICATION', publication)
- commit('PUBLICATIONS_LOADED', true)
- })
- },
- }
-
- const mutations = {
- ADD_TO_FETCHED_PUBLICATIONS(state, { publications }) {
- state.all = [...state.all, ...publications]
- },
- STORE_FETCHED_PUBLICATIONS(state, { publications }) {
- state.all = publications
- },
- STORE_FETCHED_SINGLE_PUBLICATION(state, publication) {
- state.singlePublication = publication
- },
- CLEAR_PUBLICATIONS(state) {
- state.all = []
- },
- CLEAR_SINGLE_PUBLICATIONS(state) {
- state.singlePublication = null
- },
- PUBLICATIONS_LOADED(state, val) {
- state.loaded = val
- },
- }
-
- export default { state, getters, actions, mutations }
|