mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Updated short URL visits loading so that it loads visits in several requests
This commit is contained in:
parent
58d3a59e58
commit
0c1f533747
2 changed files with 18 additions and 5 deletions
|
@ -22,9 +22,9 @@ export default class ShlinkApiClient {
|
||||||
.then((resp) => resp.data);
|
.then((resp) => resp.data);
|
||||||
};
|
};
|
||||||
|
|
||||||
getShortUrlVisits = (shortCode, dates) =>
|
getShortUrlVisits = (shortCode, query) =>
|
||||||
this._performRequest(`/short-urls/${shortCode}/visits`, 'GET', dates)
|
this._performRequest(`/short-urls/${shortCode}/visits`, 'GET', query)
|
||||||
.then((resp) => resp.data.visits.data);
|
.then((resp) => resp.data.visits);
|
||||||
|
|
||||||
getShortUrl = (shortCode) =>
|
getShortUrl = (shortCode) =>
|
||||||
this._performRequest(`/short-urls/${shortCode}`, 'GET')
|
this._performRequest(`/short-urls/${shortCode}`, 'GET')
|
||||||
|
|
|
@ -46,10 +46,23 @@ export const getShortUrlVisits = (buildShlinkApiClient) => (shortCode, dates) =>
|
||||||
dispatch({ type: GET_SHORT_URL_VISITS_START });
|
dispatch({ type: GET_SHORT_URL_VISITS_START });
|
||||||
|
|
||||||
const { selectedServer } = getState();
|
const { selectedServer } = getState();
|
||||||
const shlinkApiClient = buildShlinkApiClient(selectedServer);
|
const { getShortUrlVisits } = buildShlinkApiClient(selectedServer);
|
||||||
|
const itemsPerPage = 5000;
|
||||||
|
const isLastPage = ({ currentPage, pagesCount }) => currentPage >= pagesCount;
|
||||||
|
|
||||||
|
const loadVisits = async (page = 1) => {
|
||||||
|
const { pagination, data } = await getShortUrlVisits(shortCode, { ...dates, page, itemsPerPage });
|
||||||
|
|
||||||
|
// If pagination was not returned, then this is an older shlink version. Just return data
|
||||||
|
if (!pagination || isLastPage(pagination)) {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.concat(await loadVisits(page + 1));
|
||||||
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const visits = await shlinkApiClient.getShortUrlVisits(shortCode, dates);
|
const visits = await loadVisits();
|
||||||
|
|
||||||
dispatch({ visits, type: GET_SHORT_URL_VISITS });
|
dispatch({ visits, type: GET_SHORT_URL_VISITS });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
Loading…
Reference in a new issue