gallery.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import router from '@/router'
  2. export default {
  3. state: {
  4. creation: undefined
  5. },
  6. mutations: {
  7. 'SET_CREATION' (state, id) {
  8. state.creation = id
  9. }
  10. },
  11. actions: {
  12. async 'INIT_GALLERY' ({ state, commit, dispatch, getters }, id) {
  13. const ids = await dispatch('GET_ALL_NODES_IDS', { variant: 'creation', dataLevel: 'full' })
  14. if (isNaN(id)) {
  15. dispatch('OPEN_CREATION', { id: ids[ids.length - 1] })
  16. } else {
  17. dispatch('DISPLAY_CREATION', id)
  18. }
  19. return dispatch('GET_NODES', { ids, dataLevel: 'full' })
  20. },
  21. 'DISPLAY_CREATION' ({ state, commit, dispatch, getters }, id) {
  22. commit('SET_CREATION', id)
  23. commit('ADD_HISTORY_ENTRIES', [id])
  24. },
  25. async 'OPEN_CREATION' ({ state, commit, dispatch }, { id, map = true }) {
  26. if (router.currentRoute.name !== 'gallery-view') {
  27. router.push({ name: 'gallery-view', params: { id }, hash: map ? '#map' : '' })
  28. } else {
  29. router.push({ params: { id } })
  30. }
  31. }
  32. },
  33. getters: {
  34. creations: (state, getters, rootState) => {
  35. const ids = rootState.ids.creation
  36. if (ids === undefined) return
  37. const nodes = ids.map(id => rootState.nodes[id])
  38. if (nodes.some(node => node === undefined)) return
  39. return nodes
  40. },
  41. creation: (state, getters, rootState) => {
  42. if (state.creation === undefined || state.creation === null) return state.creation
  43. return rootState.nodes[state.creation]
  44. }
  45. }
  46. }