From 3c04f727e83930871fb413c07ea5311167a58bc8 Mon Sep 17 00:00:00 2001 From: guerler Date: Tue, 20 Sep 2022 10:10:58 -0400 Subject: [PATCH] Augment history store, avoid loosing already stored histories --- client/src/components/History/HistoryView.vue | 3 --- client/src/store/historyStore/historyStore.js | 22 ++++++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/client/src/components/History/HistoryView.vue b/client/src/components/History/HistoryView.vue index 67891c2de8d..cfadfe598ad 100644 --- a/client/src/components/History/HistoryView.vue +++ b/client/src/components/History/HistoryView.vue @@ -35,9 +35,6 @@ @view-collection="onViewCollection" /> - - - diff --git a/client/src/store/historyStore/historyStore.js b/client/src/store/historyStore/historyStore.js index 0c6a3814b65..6a15c2deb9a 100644 --- a/client/src/store/historyStore/historyStore.js +++ b/client/src/store/historyStore/historyStore.js @@ -32,13 +32,23 @@ const mutations = { Vue.delete(state.histories, doomed.id); }, setHistories(state, newHistories = []) { - // The incoming history list contains less information than the current history - // so we ensure that already available details are not getting lost + // The incoming history list may contain less information than the already stored + // histories, so we ensure that already available details are not getting lost. const enrichedHistories = newHistories.map((history) => { const historyState = state.histories[history.id] || {}; return Object.assign({}, history, historyState); }); + // Histories are provided as list but stored as map. const newMap = enrichedHistories.reduce((acc, h) => ({ ...acc, [h.id]: h }), {}); + // Ensure that already stored histories, which are not available in the incoming array, + // are not lost. This happens e.g. with shared histories since they have different owners. + state.histories.forEach((history) => { + const historyId = history.id; + if (!newMap[historyId]) { + newMap[historyId] = history; + } + }); + // Update stored histories Vue.set(state, "histories", newMap); }, setHistoriesLoading(state, isLoading) { @@ -82,7 +92,7 @@ const getters = { }; // flags to keep track of loading states -const isLoadingHistory = new Map(); +const isLoadingHistory = new Set(); let isLoadingHistories = false; const actions = { @@ -125,7 +135,7 @@ const actions = { }, loadHistoryById({ dispatch }, id) { if (!isLoadingHistory.has(id)) { - const p = getHistoryById(id) + getHistoryById(id) .then((history) => { dispatch("setHistory", history); }) @@ -135,7 +145,7 @@ const actions = { .finally(() => { isLoadingHistory.delete(id); }); - //isLoadingHistory.set(id, p); + isLoadingHistory.add(id); } }, resetHistory({ commit }) { @@ -150,7 +160,7 @@ const actions = { commit("setHistory", history); commit("setCurrentHistoryId", history.id); }, - async setCurrentHistory({ dispatch, getters }, id) { + async setCurrentHistory({ dispatch }, id) { const changedHistory = await setCurrentHistoryOnServer(id); return dispatch("selectHistory", changedHistory); },