From a8eb809ce8ab03d6902411955bc03da169af3c94 Mon Sep 17 00:00:00 2001 From: KevinMidboe Date: Tue, 16 Apr 2019 00:09:25 +0200 Subject: [PATCH] Increment logic added before it should, this is now fixed. Also changed the name of some input function paramteres to make more sense. --- src/store.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/store.js b/src/store.js index 74c4cc0..ee79020 100644 --- a/src/store.js +++ b/src/store.js @@ -6,7 +6,8 @@ Vue.use(Vuex) const state = { popover: false, popoverAlbum: [], - popoverAlbumIndex: 0, + popoverAlbumLength: 0, + popoverAlbumIndex: 0 } const mutations = { @@ -20,18 +21,20 @@ const mutations = { setPopoverAlbum (state, album) { state.popoverAlbum = album; + state.popoverAlbumLength = album.length - 1; }, setPopoverAlbumIndex (state, index) { state.popoverAlbumIndex = index; + console.log('new index', index); }, incrementPopoverImage (state) { let index = state.popoverAlbumIndex; - index++ - console.log('Setting popover index:', index) - if (index > state.popoverAlbum.length - 1) { + if (index < state.popoverAlbumLength) { + index++; + } else { index = 0; } @@ -40,11 +43,11 @@ const mutations = { decrementPopoverImage (state) { let index = state.popoverAlbumIndex; - index-- - console.log('Setting popover index:', index) - if (index < 0) { - index = state.popoverAlbum.length - 1; + if (index > 0) { + index--; + } else { + index = state.popoverAlbumLength; } state.popoverAlbumIndex = index; @@ -55,8 +58,8 @@ const mutations = { const actions = { showPopover: ({ commit }) => commit('showPopover'), hidePopover: ({ commit }) => commit('hidePopover'), - setPopoverAlbum: ({ commit }, payload) => commit('setPopoverAlbum', payload), - setPopoverAlbumIndex: ({ commit }, payload) => commit('setPopoverAlbumIndex', payload), + setPopoverAlbum: ({ commit }, images) => commit('setPopoverAlbum', images), + setPopoverAlbumIndex: ({ commit }, index) => commit('setPopoverAlbumIndex', index), incrementPopoverImage: ({ commit }) => commit('incrementPopoverImage'), decrementPopoverImage: ({ commit }) => commit('decrementPopoverImage'),