From 23594bc33883610c5b1b7a4ceee6be459c09b579 Mon Sep 17 00:00:00 2001 From: axolotle Date: Tue, 12 Mar 2024 03:09:59 +0100 Subject: [PATCH] fix: temp fix for reactivity problems on nested obj request --- app/src/store/info.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/src/store/info.js b/app/src/store/info.js index e6819028..a631b37d 100644 --- a/app/src/store/info.js +++ b/app/src/store/info.js @@ -13,6 +13,7 @@ export default { reconnecting: null, // null|Object { attemps, delay, initialDelay } history: [], // Array of `request` requests: [], // Array of `request` + currentRequest: null, error: null, // null || request historyTimer: null, // null || setTimeout id tempMessages: [], // Array of messages @@ -43,6 +44,10 @@ export default { state.reconnecting = args }, + SET_CURRENT_REQUEST(state, request) { + state.currentRequest = request + }, + ADD_REQUEST(state, request) { if (state.requests.length > 10) { // We do not remove requests right after it resolves since an error might bring @@ -52,9 +57,9 @@ export default { state.requests.push(request) }, - UPDATE_REQUEST(state, { request, key, value }) { + UPDATE_REQUEST(state, { key, value }) { // This rely on data persistance and reactivity. - request[key] = value + state.currentRequest[key] = value }, REMOVE_REQUEST(state, request) { @@ -70,7 +75,7 @@ export default { state.tempMessages.push([message, type]) }, - UPDATE_DISPLAYED_MESSAGES(state, { request }) { + UPDATE_DISPLAYED_MESSAGES(state) { if (!state.tempMessages.length) { state.historyTimer = null return @@ -86,9 +91,10 @@ export default { ) state.tempMessages = [] state.historyTimer = null - request.messages = request.messages.concat(messages) - request.warnings += warnings - request.errors += errors + state.currentRequest.messages = + state.currentRequest.messages.concat(messages) + state.currentRequest.warnings += warnings + state.currentRequest.errors += errors }, SET_ERROR(state, request) { @@ -221,6 +227,7 @@ export default { commit('ADD_HISTORY_ACTION', request) } commit('ADD_REQUEST', request) + commit('SET_CURRENT_REQUEST', request) if (wait) { setTimeout(() => { // Display the waiting modal only if the request takes some time. @@ -245,13 +252,13 @@ export default { messages.length && messages[messages.length - 1].color === 'warning' ) { - request.showWarningMessage = true + state.currentRequest.showWarningMessage = true } status = 'warning' } commit('UPDATE_REQUEST', { request, key: 'status', value: status }) - if (wait && !request.showWarningMessage) { + if (wait && !state.currentRequest.showWarningMessage) { // Remove the overlay after a short delay to allow an error to display withtout flickering. setTimeout(() => { commit('SET_WAITING', false) @@ -419,10 +426,7 @@ export default { reconnecting: (state) => state.reconnecting, history: (state) => state.history, lastAction: (state) => state.history[state.history.length - 1], - currentRequest: (state) => { - const request = state.requests.find(({ status }) => status === 'pending') - return request || state.requests[state.requests.length - 1] - }, + currentRequest: (state) => state.currentRequest, routerKey: (state) => state.routerKey, breadcrumb: (state) => state.breadcrumb, transitionName: (state) => state.transitionName,