From a13654355114c00b9e4c1bea6a2283e1cee575df Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 19 Sep 2020 10:50:49 +0200 Subject: [PATCH 1/2] Fixed tags visits loading not being cancelled when the visits component gets unmounted --- src/visits/reducers/common.ts | 7 ++----- src/visits/reducers/shortUrlVisits.ts | 3 ++- src/visits/reducers/tagVisits.ts | 3 ++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/visits/reducers/common.ts b/src/visits/reducers/common.ts index 4270d12e..f7e0afbd 100644 --- a/src/visits/reducers/common.ts +++ b/src/visits/reducers/common.ts @@ -1,7 +1,6 @@ import { flatten, prop, range, splitEvery } from 'ramda'; import { Action, Dispatch } from 'redux'; import { ShlinkPaginator, ShlinkVisits } from '../../utils/services/types'; -import { GetState } from '../../container/types'; import { Visit } from '../types'; const ITEMS_PER_PAGE = 5000; @@ -25,7 +24,7 @@ export const getVisitsWithLoader = async & { visits: V extraFinishActionData: Partial, actionMap: ActionMap, dispatch: Dispatch, - getState: GetState, + shouldCancel: () => boolean, ) => { dispatch({ type: actionMap.start }); @@ -33,9 +32,7 @@ export const getVisitsWithLoader = async & { visits: V Promise.all(pages.map(async (page) => visitsLoader(page, ITEMS_PER_PAGE).then(prop('data')))).then(flatten); const loadPagesBlocks = async (pagesBlocks: number[][], index = 0): Promise => { - const { shortUrlVisits: { cancelLoad } } = getState(); - - if (cancelLoad) { + if (shouldCancel()) { return []; } diff --git a/src/visits/reducers/shortUrlVisits.ts b/src/visits/reducers/shortUrlVisits.ts index a7ee4407..4cc689b2 100644 --- a/src/visits/reducers/shortUrlVisits.ts +++ b/src/visits/reducers/shortUrlVisits.ts @@ -69,6 +69,7 @@ export const getShortUrlVisits = (buildShlinkApiClient: ShlinkApiClientBuilder) shortCode, { ...query, page, itemsPerPage }, ); + const shouldCancel = () => getState().shortUrlVisits.cancelLoad; const extraFinishActionData: Partial = { shortCode, domain: query.domain }; const actionMap = { start: GET_SHORT_URL_VISITS_START, @@ -78,7 +79,7 @@ export const getShortUrlVisits = (buildShlinkApiClient: ShlinkApiClientBuilder) progress: GET_SHORT_URL_VISITS_PROGRESS_CHANGED, }; - return getVisitsWithLoader(visitsLoader, extraFinishActionData, actionMap, dispatch, getState); + return getVisitsWithLoader(visitsLoader, extraFinishActionData, actionMap, dispatch, shouldCancel); }; export const cancelGetShortUrlVisits = buildActionCreator(GET_SHORT_URL_VISITS_CANCEL); diff --git a/src/visits/reducers/tagVisits.ts b/src/visits/reducers/tagVisits.ts index 04fcc498..691c8b14 100644 --- a/src/visits/reducers/tagVisits.ts +++ b/src/visits/reducers/tagVisits.ts @@ -60,6 +60,7 @@ export const getTagVisits = (buildShlinkApiClient: ShlinkApiClientBuilder) => (t tag, { ...query, page, itemsPerPage }, ); + const shouldCancel = () => getState().tagVisits.cancelLoad; const extraFinishActionData: Partial = { tag }; const actionMap = { start: GET_TAG_VISITS_START, @@ -69,7 +70,7 @@ export const getTagVisits = (buildShlinkApiClient: ShlinkApiClientBuilder) => (t progress: GET_TAG_VISITS_PROGRESS_CHANGED, }; - return getVisitsWithLoader(visitsLoader, extraFinishActionData, actionMap, dispatch, getState); + return getVisitsWithLoader(visitsLoader, extraFinishActionData, actionMap, dispatch, shouldCancel); }; export const cancelGetTagVisits = buildActionCreator(GET_TAG_VISITS_CANCEL); From 6bf3fc0fd53f11995a8146f2004e114eab81d060 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sat, 19 Sep 2020 10:51:41 +0200 Subject: [PATCH 2/2] Updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3391cf17..1d6ceb8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), #### Fixed * [#295](https://github.com/shlinkio/shlink-web-client/issues/295) Fixed custom slug field not being disabled when selecting a short code length. +* [#301](https://github.com/shlinkio/shlink-web-client/issues/301) Fixed tags visits loading not being cancelled when leaving visits page. ## 2.5.1 - 2020-06-06