Removed duplicated code when building ShlinkApiClient

This commit is contained in:
Alejandro Celaya
2019-04-21 11:31:40 +02:00
parent 48f7103205
commit 7b80d78dc5
15 changed files with 60 additions and 52 deletions

View File

@@ -29,11 +29,10 @@ export default handleActions({
export const getShortUrlDetail = (buildShlinkApiClient) => (shortCode) => async (dispatch, getState) => {
dispatch({ type: GET_SHORT_URL_DETAIL_START });
const { selectedServer } = getState();
const shlinkApiClient = buildShlinkApiClient(selectedServer);
const { getShortUrl } = await buildShlinkApiClient(getState);
try {
const shortUrl = await shlinkApiClient.getShortUrl(shortCode);
const shortUrl = await getShortUrl(shortCode);
dispatch({ shortUrl, type: GET_SHORT_URL_DETAIL });
} catch (e) {

View File

@@ -52,8 +52,7 @@ export default handleActions({
export const getShortUrlVisits = (buildShlinkApiClient) => (shortCode, dates) => async (dispatch, getState) => {
dispatch({ type: GET_SHORT_URL_VISITS_START });
const { selectedServer } = getState();
const { getShortUrlVisits } = buildShlinkApiClient(selectedServer);
const { getShortUrlVisits } = await buildShlinkApiClient(getState);
const itemsPerPage = 5000;
const isLastPage = ({ currentPage, pagesCount }) => currentPage >= pagesCount;