gallery.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. export default {
  2. state: {
  3. creation: undefined
  4. },
  5. mutations: {
  6. 'SET_CREATION' (state, id) {
  7. state.creation = id
  8. }
  9. },
  10. actions: {
  11. async 'INIT_GALLERY' ({ state, commit, dispatch, getters }) {
  12. const ids = await dispatch('GET_ALL_NODES_IDS', { variant: 'creation', dataLevel: 'full' })
  13. dispatch('OPEN_CREATION', ids[ids.length - 1])
  14. return dispatch('GET_NODES', { ids, dataLevel: 'full' })
  15. },
  16. async 'OPEN_CREATION' ({ state, commit, dispatch }, id) {
  17. commit('SET_CREATION', id)
  18. commit('ADD_HISTORY_ENTRIES', [id])
  19. return dispatch('GET_NODE', { id, dataLevel: 'full' })
  20. }
  21. },
  22. getters: {
  23. creations: (state, getters, rootState) => {
  24. const ids = rootState.ids.creation
  25. if (ids === undefined) return
  26. const nodes = ids.map(id => rootState.nodes[id])
  27. if (nodes.some(node => node === undefined)) return
  28. return nodes
  29. },
  30. creation: (state, getters, rootState) => {
  31. if (state.creation === undefined || state.creation === null) return state.creation
  32. return rootState.nodes[state.creation]
  33. }
  34. }
  35. }