From 9bdbe9071648f7fcca3eedda5ba5d9542018079f Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 11 May 2020 18:55:35 +0200 Subject: [PATCH] Ensured state is properly reset when starting, finisihing or failing to load visits --- src/visits/reducers/shortUrlDetail.js | 6 +++--- src/visits/reducers/shortUrlVisits.js | 20 +++----------------- src/visits/reducers/tagVisits.js | 24 +++--------------------- 3 files changed, 9 insertions(+), 41 deletions(-) diff --git a/src/visits/reducers/shortUrlDetail.js b/src/visits/reducers/shortUrlDetail.js index 477464f5..7612b7ab 100644 --- a/src/visits/reducers/shortUrlDetail.js +++ b/src/visits/reducers/shortUrlDetail.js @@ -21,9 +21,9 @@ const initialState = { }; export default handleActions({ - [GET_SHORT_URL_DETAIL_START]: (state) => ({ ...state, loading: true }), - [GET_SHORT_URL_DETAIL_ERROR]: (state) => ({ ...state, loading: false, error: true }), - [GET_SHORT_URL_DETAIL]: (state, { shortUrl }) => ({ shortUrl, loading: false, error: false }), + [GET_SHORT_URL_DETAIL_START]: () => ({ ...initialState, loading: true }), + [GET_SHORT_URL_DETAIL_ERROR]: () => ({ ...initialState, loading: false, error: true }), + [GET_SHORT_URL_DETAIL]: (state, { shortUrl }) => ({ ...initialState, shortUrl }), }, initialState); export const getShortUrlDetail = (buildShlinkApiClient) => (shortCode, domain) => async (dispatch, getState) => { diff --git a/src/visits/reducers/shortUrlVisits.js b/src/visits/reducers/shortUrlVisits.js index 58b5d49c..7b785c79 100644 --- a/src/visits/reducers/shortUrlVisits.js +++ b/src/visits/reducers/shortUrlVisits.js @@ -33,27 +33,13 @@ const initialState = { }; export default handleActions({ - [GET_SHORT_URL_VISITS_START]: (state) => ({ - ...state, - loading: true, - loadingLarge: false, - cancelLoad: false, - }), - [GET_SHORT_URL_VISITS_ERROR]: (state) => ({ - ...state, - loading: false, - loadingLarge: false, - error: true, - cancelLoad: false, - }), + [GET_SHORT_URL_VISITS_START]: () => ({ ...initialState, loading: true }), + [GET_SHORT_URL_VISITS_ERROR]: () => ({ ...initialState, error: true }), [GET_SHORT_URL_VISITS]: (state, { visits, shortCode, domain }) => ({ + ...initialState, visits, shortCode, domain, - loading: false, - loadingLarge: false, - error: false, - cancelLoad: false, }), [GET_SHORT_URL_VISITS_LARGE]: (state) => ({ ...state, loadingLarge: true }), [GET_SHORT_URL_VISITS_CANCEL]: (state) => ({ ...state, cancelLoad: true }), diff --git a/src/visits/reducers/tagVisits.js b/src/visits/reducers/tagVisits.js index c59facf2..453b6db5 100644 --- a/src/visits/reducers/tagVisits.js +++ b/src/visits/reducers/tagVisits.js @@ -30,27 +30,9 @@ const initialState = { }; export default handleActions({ - [GET_TAG_VISITS_START]: (state) => ({ - ...state, - loading: true, - loadingLarge: false, - cancelLoad: false, - }), - [GET_TAG_VISITS_ERROR]: (state) => ({ - ...state, - loading: false, - loadingLarge: false, - error: true, - cancelLoad: false, - }), - [GET_TAG_VISITS]: (state, { visits, tag }) => ({ - visits, - tag, - loading: false, - loadingLarge: false, - error: false, - cancelLoad: false, - }), + [GET_TAG_VISITS_START]: () => ({ ...initialState, loading: true }), + [GET_TAG_VISITS_ERROR]: () => ({ ...initialState, error: true }), + [GET_TAG_VISITS]: (state, { visits, tag }) => ({ ...initialState, visits, tag }), [GET_TAG_VISITS_LARGE]: (state) => ({ ...state, loadingLarge: true }), [GET_TAG_VISITS_CANCEL]: (state) => ({ ...state, cancelLoad: true }), [CREATE_VISIT]: (state, { shortUrl, visit }) => { // eslint-disable-line object-shorthand