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

@@ -32,11 +32,10 @@ export default handleActions({
export const createShortUrl = (buildShlinkApiClient) => (data) => async (dispatch, getState) => {
dispatch({ type: CREATE_SHORT_URL_START });
const { selectedServer } = getState();
const shlinkApiClient = buildShlinkApiClient(selectedServer);
const { createShortUrl } = await buildShlinkApiClient(getState);
try {
const result = await shlinkApiClient.createShortUrl(data);
const result = await createShortUrl(data);
dispatch({ type: CREATE_SHORT_URL, result });
} catch (e) {

View File

@@ -36,8 +36,7 @@ export default handleActions({
export const deleteShortUrl = (buildShlinkApiClient) => (shortCode) => async (dispatch, getState) => {
dispatch({ type: DELETE_SHORT_URL_START });
const { selectedServer } = getState();
const { deleteShortUrl } = buildShlinkApiClient(selectedServer);
const { deleteShortUrl } = await buildShlinkApiClient(getState);
try {
await deleteShortUrl(shortCode);

View File

@@ -33,11 +33,10 @@ export default handleActions({
export const editShortUrlTags = (buildShlinkApiClient) => (shortCode, tags) => async (dispatch, getState) => {
dispatch({ type: EDIT_SHORT_URL_TAGS_START });
const { selectedServer } = getState();
const shlinkApiClient = buildShlinkApiClient(selectedServer);
const { updateShortUrlTags } = await buildShlinkApiClient(getState);
try {
const normalizedTags = await shlinkApiClient.updateShortUrlTags(shortCode, tags);
const normalizedTags = await updateShortUrlTags(shortCode, tags);
dispatch({ tags: normalizedTags, shortCode, type: EDIT_SHORT_URL_TAGS });
} catch (e) {

View File

@@ -45,8 +45,7 @@ export default handleActions({
export const listShortUrls = (buildShlinkApiClient) => (params = {}) => async (dispatch, getState) => {
dispatch({ type: LIST_SHORT_URLS_START });
const { selectedServer = {} } = getState();
const { listShortUrls } = buildShlinkApiClient(selectedServer);
const { listShortUrls } = await buildShlinkApiClient(getState);
try {
const shortUrls = await listShortUrls(params);