mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-08 17:27:32 +03:00
Merge pull request #303 from acelaya-forks/feature/cancel-tags-visits
Feature/cancel tags visits
This commit is contained in:
commit
46db1e39f3
4 changed files with 7 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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 <T extends Action<string> & { visits: V
|
|||
extraFinishActionData: Partial<T>,
|
||||
actionMap: ActionMap,
|
||||
dispatch: Dispatch,
|
||||
getState: GetState,
|
||||
shouldCancel: () => boolean,
|
||||
) => {
|
||||
dispatch({ type: actionMap.start });
|
||||
|
||||
|
@ -33,9 +32,7 @@ export const getVisitsWithLoader = async <T extends Action<string> & { 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<Visit[]> => {
|
||||
const { shortUrlVisits: { cancelLoad } } = getState();
|
||||
|
||||
if (cancelLoad) {
|
||||
if (shouldCancel()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ export const getShortUrlVisits = (buildShlinkApiClient: ShlinkApiClientBuilder)
|
|||
shortCode,
|
||||
{ ...query, page, itemsPerPage },
|
||||
);
|
||||
const shouldCancel = () => getState().shortUrlVisits.cancelLoad;
|
||||
const extraFinishActionData: Partial<ShortUrlVisitsAction> = { 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);
|
||||
|
|
|
@ -60,6 +60,7 @@ export const getTagVisits = (buildShlinkApiClient: ShlinkApiClientBuilder) => (t
|
|||
tag,
|
||||
{ ...query, page, itemsPerPage },
|
||||
);
|
||||
const shouldCancel = () => getState().tagVisits.cancelLoad;
|
||||
const extraFinishActionData: Partial<TagVisitsAction> = { 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);
|
||||
|
|
Loading…
Reference in a new issue