From 56a3b29f65cc4fb9954db5aeda2614c01c918aa8 Mon Sep 17 00:00:00 2001 From: axolotle Date: Mon, 15 Feb 2021 15:21:26 +0100 Subject: [PATCH] add status prop to store's history entries --- app/src/api/handlers.js | 2 +- app/src/store/info.js | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/api/handlers.js b/app/src/api/handlers.js index bad9c258..c8a48d3d 100644 --- a/app/src/api/handlers.js +++ b/app/src/api/handlers.js @@ -32,7 +32,7 @@ async function _getResponseData (response) { */ export async function handleResponse (response, method) { const responseData = await _getResponseData(response) - store.dispatch('SERVER_RESPONDED') + store.dispatch('SERVER_RESPONDED', response.ok) return response.ok ? responseData : handleError(response, responseData, method) } diff --git a/app/src/store/info.js b/app/src/store/info.js index ac664773..5c19075c 100644 --- a/app/src/store/info.js +++ b/app/src/store/info.js @@ -28,7 +28,11 @@ export default { }, 'ADD_HISTORY_ENTRY' (state, [uri, method, date]) { - state.history.push({ uri, method, date, messages: [] }) + state.history.push({ uri, method, date, status: 'pending', messages: [] }) + }, + + 'UPDATE_LAST_HISTORY_ENTRY' (state, [key, value]) { + Vue.set(state.history[state.history.length - 1], key, value) }, 'ADD_MESSAGE' (state, message) { @@ -109,7 +113,15 @@ export default { commit('ADD_HISTORY_ENTRY', [uri, method, Date.now()]) }, - 'SERVER_RESPONDED' ({ commit }) { + 'SERVER_RESPONDED' ({ state, commit }, success) { + const action = state.history.length ? state.history[state.history.length - 1] : null + if (action) { + let status = success ? 'success' : 'error' + if (status === 'success' && action.messages.some(msg => msg.type === 'danger' || msg.type === 'warning')) { + status = 'warning' + } + commit('UPDATE_LAST_HISTORY_ENTRY', ['status', status]) + } commit('UPDATE_WAITING', false) },