From 2f252ad8803043fb50919b8a2912c11c866dc3bc Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Thu, 12 Sep 2024 15:52:53 +0200 Subject: [PATCH] fix: Load archived card if URL is opened directly Signed-off-by: Julius Knorr --- src/components/board/Board.vue | 10 ++++++++++ src/store/main.js | 4 ++-- src/store/stack.js | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/components/board/Board.vue b/src/components/board/Board.vue index 3c50289d2..6ba3b5015 100644 --- a/src/components/board/Board.vue +++ b/src/components/board/Board.vue @@ -182,6 +182,16 @@ export default { await this.$store.dispatch('loadBoardById', this.id) await this.$store.dispatch('loadStacks', this.id) + const routeCardId = parseInt(this.$route.params.cardId) + // If an archived card is requested, and we cannot find it in the current we load the archived stacks instead + if (routeCardId && !this.$store.getters.cardById(routeCardId)) { + await this.$store.dispatch('loadArchivedStacks', this.id) + + if (this.$store.getters.cardById(routeCardId)) { + this.$store.commit('toggleShowArchived', true) + } + } + this.session?.close() this.session = createSession(this.id) } catch (e) { diff --git a/src/store/main.js b/src/store/main.js index f52aeafc9..5f9d7d054 100644 --- a/src/store/main.js +++ b/src/store/main.js @@ -189,8 +189,8 @@ export default new Vuex.Store({ } }) }, - toggleShowArchived(state) { - state.showArchived = !state.showArchived + toggleShowArchived(state, newState = undefined) { + state.showArchived = newState !== undefined ? newState : !state.showArchived }, /* * Adds or replaces a board in the store. diff --git a/src/store/stack.js b/src/store/stack.js index 608ffd32b..8b522f200 100644 --- a/src/store/stack.js +++ b/src/store/stack.js @@ -95,6 +95,21 @@ export default { } commit('setCards', cards) }, + async loadArchivedStacks({ commit, getters }, boardId) { + const archivedStacks = await apiClient.loadArchivedStacks(boardId) + const cards = [] + for (const i in archivedStacks) { + const stack = archivedStacks[i] + for (const j in stack.cards) { + cards.push(stack.cards[j]) + } + delete stack.cards + if (!getters.stackById(stack.id)) { + commit('addStack', stack) + } + } + commit('setCards', cards) + }, createStack({ commit }, stack) { stack.boardId = this.state.currentBoard.id apiClient.createStack(stack)