Skip to content

Commit

Permalink
fix: temp fix for reactivity problems on nested obj request
Browse files Browse the repository at this point in the history
  • Loading branch information
Axolotle committed Mar 26, 2024
1 parent 796dad8 commit 23594bc
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions app/src/store/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 23594bc

Please sign in to comment.