From f5853f20402dc08117dd266d41ea4f044583bcdb Mon Sep 17 00:00:00 2001 From: axolotle Date: Wed, 10 Nov 2021 20:38:34 +0100 Subject: [PATCH] update reconnecting as args to be passed to ReconnectingDisplay --- app/src/api/api.js | 2 +- app/src/store/info.js | 11 ++++++----- app/src/views/_partials/ReconnectingDisplay.vue | 11 +++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/api/api.js b/app/src/api/api.js index c33986e5..5941862a 100644 --- a/app/src/api/api.js +++ b/app/src/api/api.js @@ -199,7 +199,7 @@ export default { * @param {Number} initialDelay - delay before calling the API for the first time in ms. * @return {Promise} */ - tryToReconnect ({ attemps = 1, delay = 2000, initialDelay = 0 } = {}) { + tryToReconnect ({ attemps = 5, delay = 2000, initialDelay = 0 } = {}) { return new Promise((resolve, reject) => { const api = this diff --git a/app/src/store/info.js b/app/src/store/info.js index d65af363..37e09292 100644 --- a/app/src/store/info.js +++ b/app/src/store/info.js @@ -10,7 +10,7 @@ export default { connected: localStorage.getItem('connected') === 'true', // Boolean yunohost: null, // Object { version, repo } waiting: false, // Boolean - reconnecting: false, // Boolean + reconnecting: null, // null|Object { attemps, delay, initialDelay } history: [], // Array of `request` requests: [], // Array of `request` error: null, // null || request @@ -32,8 +32,8 @@ export default { state.waiting = boolean }, - 'SET_RECONNECTING' (state, boolean) { - state.reconnecting = boolean + 'SET_RECONNECTING' (state, args) { + state.reconnecting = args }, 'ADD_REQUEST' (state, request) { @@ -138,8 +138,9 @@ export default { return api.get('logout') }, - 'TRY_TO_RECONNECT' ({ commit, dispatch }) { - commit('SET_RECONNECTING', true) + 'TRY_TO_RECONNECT' ({ commit, dispatch }, args = {}) { + // FIXME This is very ugly arguments forwarding, will use proper component way of doing this when switching to Vue 3 (teleport) + commit('SET_RECONNECTING', args) dispatch('RESET_CONNECTED') }, diff --git a/app/src/views/_partials/ReconnectingDisplay.vue b/app/src/views/_partials/ReconnectingDisplay.vue index 125dd097..e9f91242 100644 --- a/app/src/views/_partials/ReconnectingDisplay.vue +++ b/app/src/views/_partials/ReconnectingDisplay.vue @@ -56,13 +56,13 @@ export default { }, computed: { - ...mapGetters(['currentRequest']) + ...mapGetters(['reconnecting']) }, methods: { - tryToReconnect ({ initialDelay = 0 } = {}) { + tryToReconnect (initialDelay = 0) { this.status = 'reconnecting' - api.tryToReconnect({ initialDelay }).then(() => { + api.tryToReconnect({ ...this.reconnecting, initialDelay }).then(() => { this.status = 'success' }).catch(() => { this.status = 'failed' @@ -71,9 +71,8 @@ export default { }, created () { - const origin = this.currentRequest.humanRouteKey - this.origin = ['upgrade.system'].includes(origin) ? origin.replace('.', '_') : 'unknown' - this.tryToReconnect({ initialDelay: 2000 }) + this.origin = this.reconnecting.origin || 'unknown' + this.tryToReconnect(this.reconnecting.initialDelay) } }