| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- import api from '../../utils/api'
- import { allBySlug, repackBySort } from './arrangements'
-
- const state = {
- all: [],
- loaded: false,
- singleObject: null,
- }
-
- const getters = {
- allObjects: state => state.all,
- allObjectsBySlug: state => allBySlug(state),
- allObjectsLoaded: state => state.loaded,
- }
-
- const actions = {
- getAllObjects({ commit }, { sortType, params }) {
- commit('CLEAR_OBJECTS')
- commit('OBJECTS_LOADED', false)
- const storeFetch = objects => {
- let repacked = repackBySort(objects, sortType)
- commit('STORE_FETCHED_OBJECTS', { objects: repacked })
- commit('OBJECTS_LOADED', true)
- }
- return api.getByType({
- type: 'object',
- sort: sortType,
- params,
- cb: storeFetch,
- })
- },
- getMoreObjects({ commit }, { sortType, params }) {
- const storeFetch = objects => {
- let repacked = objects
- commit('ADD_TO_FETCHED_OBJECTS', { objects: repacked })
- commit('OBJECTS_LOADED', true)
- }
- return api.getByType({
- type: 'object',
- sort: sortType,
- params,
- cb: storeFetch,
- })
- },
- getSingleObject({ commit }, id) {
- commit('CLEAR_SINGLE_OBJECTS')
- commit('OBJECTS_LOADED', false)
-
- return api.getSingleType('object', id, object => {
- commit('STORE_FETCHED_SINGLE_OBJECT', object)
- commit('OBJECTS_LOADED', true)
- })
- },
- }
-
- const mutations = {
- ADD_TO_FETCHED_OBJECTS(state, { objects }) {
- state.all = [...state.all, ...objects]
- },
- STORE_FETCHED_OBJECTS(state, { objects }) {
- state.all = objects
- },
- STORE_FETCHED_SINGLE_OBJECT(state, object) {
- state.singleObject = object
- },
- CLEAR_OBJECTS(state) {
- state.all = []
- },
- CLEAR_SINGLE_OBJECTS(state) {
- state.singleObject = null
- },
- OBJECTS_LOADED(state, val) {
- state.loaded = val
- },
- }
-
- export default { state, getters, actions, mutations }
|