mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-13 11:03:50 +00:00
Simplified ShlinkApiClient and moved runtime creation logic to external service
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { curry } from 'ramda';
|
||||
import PropTypes from 'prop-types';
|
||||
import shlinkApiClient from '../../api/ShlinkApiClient';
|
||||
import { buildShlinkApiClientWithAxios as buildShlinkApiClient } from '../../api/ShlinkApiClientBuilder';
|
||||
import { shortUrlType } from '../../short-urls/reducers/shortUrlsList';
|
||||
|
||||
/* eslint-disable padding-line-between-statements, newline-after-var */
|
||||
@@ -45,9 +45,12 @@ export default function reducer(state = initialState, action) {
|
||||
}
|
||||
}
|
||||
|
||||
export const _getShortUrlDetail = (shlinkApiClient, shortCode) => async (dispatch) => {
|
||||
export const _getShortUrlDetail = (buildShlinkApiClient, shortCode) => async (dispatch, getState) => {
|
||||
dispatch({ type: GET_SHORT_URL_DETAIL_START });
|
||||
|
||||
const { selectedServer } = getState();
|
||||
const shlinkApiClient = buildShlinkApiClient(selectedServer);
|
||||
|
||||
try {
|
||||
const shortUrl = await shlinkApiClient.getShortUrl(shortCode);
|
||||
|
||||
@@ -57,4 +60,4 @@ export const _getShortUrlDetail = (shlinkApiClient, shortCode) => async (dispatc
|
||||
}
|
||||
};
|
||||
|
||||
export const getShortUrlDetail = curry(_getShortUrlDetail)(shlinkApiClient);
|
||||
export const getShortUrlDetail = curry(_getShortUrlDetail)(buildShlinkApiClient);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { curry } from 'ramda';
|
||||
import PropTypes from 'prop-types';
|
||||
import shlinkApiClient from '../../api/ShlinkApiClient';
|
||||
import { buildShlinkApiClientWithAxios as buildShlinkApiClient } from '../../api/ShlinkApiClientBuilder';
|
||||
|
||||
/* eslint-disable padding-line-between-statements, newline-after-var */
|
||||
export const GET_SHORT_URL_VISITS_START = 'shlink/shortUrlVisits/GET_SHORT_URL_VISITS_START';
|
||||
@@ -44,9 +44,12 @@ export default function reducer(state = initialState, action) {
|
||||
}
|
||||
}
|
||||
|
||||
export const _getShortUrlVisits = (shlinkApiClient, shortCode, dates) => async (dispatch) => {
|
||||
export const _getShortUrlVisits = (buildShlinkApiClient, shortCode, dates) => async (dispatch, getState) => {
|
||||
dispatch({ type: GET_SHORT_URL_VISITS_START });
|
||||
|
||||
const { selectedServer } = getState();
|
||||
const shlinkApiClient = buildShlinkApiClient(selectedServer);
|
||||
|
||||
try {
|
||||
const visits = await shlinkApiClient.getShortUrlVisits(shortCode, dates);
|
||||
|
||||
@@ -56,4 +59,4 @@ export const _getShortUrlVisits = (shlinkApiClient, shortCode, dates) => async (
|
||||
}
|
||||
};
|
||||
|
||||
export const getShortUrlVisits = curry(_getShortUrlVisits)(shlinkApiClient);
|
||||
export const getShortUrlVisits = curry(_getShortUrlVisits)(buildShlinkApiClient);
|
||||
|
||||
Reference in New Issue
Block a user