From 9515d10b23dc6c5a36fbe26fad81dd62314aab44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 15 May 2020 12:30:35 +0200 Subject: [PATCH] Group card reordering mutation to one MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- src/store/card.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/store/card.js b/src/store/card.js index cfe69bd72..ee91580a9 100644 --- a/src/store/card.js +++ b/src/store/card.js @@ -122,8 +122,8 @@ export default { for (const newCard of cards) { const existingIndex = state.cards.findIndex(_card => _card.id === newCard.id) if (existingIndex !== -1) { - const newCardObject = Object.assign({}, state.cards[existingIndex], { id: newCard.id, order: newCard.order, stackId: newCard.stackId }) - Vue.set(state.cards, existingIndex, newCardObject) + Vue.set(state.cards[existingIndex], 'order', newCard.order) + Vue.set(state.cards[existingIndex], 'stackId', newCard.stackId) } } }, @@ -176,18 +176,20 @@ export default { }, async reorderCard({ commit, getters }, card) { let i = 0 + const newCards = [] for (const c of getters.cardsByStack(card.stackId)) { if (c.id === card.id) { - await commit('updateCardsReorder', [card]) + newCards.push(card) } if (i === card.order) { i++ } if (c.id !== card.id) { - await commit('updateCardsReorder', [{ ...c, order: i++ }]) + newCards.push({ ...c, order: i++ }) } } - await commit('updateCardsReorder', [card]) + newCards.push(card) + await commit('updateCardsReorder', newCards) const cards = await apiClient.reorderCard(card) await commit('updateCardsReorder', Object.values(cards))