mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-11 10:03:51 +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';
|
||||
|
||||
/* eslint-disable padding-line-between-statements, newline-after-var */
|
||||
export const CREATE_SHORT_URL_START = 'shlink/createShortUrl/CREATE_SHORT_URL_START';
|
||||
@@ -50,9 +50,12 @@ export default function reducer(state = defaultState, action) {
|
||||
}
|
||||
}
|
||||
|
||||
export const _createShortUrl = (shlinkApiClient, data) => async (dispatch) => {
|
||||
export const _createShortUrl = (buildShlinkApiClient, data) => async (dispatch, getState) => {
|
||||
dispatch({ type: CREATE_SHORT_URL_START });
|
||||
|
||||
const { selectedServer } = getState();
|
||||
const shlinkApiClient = buildShlinkApiClient(selectedServer);
|
||||
|
||||
try {
|
||||
const result = await shlinkApiClient.createShortUrl(data);
|
||||
|
||||
@@ -62,6 +65,6 @@ export const _createShortUrl = (shlinkApiClient, data) => async (dispatch) => {
|
||||
}
|
||||
};
|
||||
|
||||
export const createShortUrl = curry(_createShortUrl)(shlinkApiClient);
|
||||
export const createShortUrl = curry(_createShortUrl)(buildShlinkApiClient);
|
||||
|
||||
export const resetCreateShortUrl = () => ({ type: RESET_CREATE_SHORT_URL });
|
||||
|
||||
@@ -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 */
|
||||
const DELETE_SHORT_URL_START = 'shlink/deleteShortUrl/DELETE_SHORT_URL_START';
|
||||
@@ -56,9 +56,12 @@ export default function reducer(state = defaultState, action) {
|
||||
}
|
||||
}
|
||||
|
||||
export const _deleteShortUrl = (shlinkApiClient, shortCode) => async (dispatch) => {
|
||||
export const _deleteShortUrl = (buildShlinkApiClient, shortCode) => async (dispatch, getState) => {
|
||||
dispatch({ type: DELETE_SHORT_URL_START });
|
||||
|
||||
const { selectedServer } = getState();
|
||||
const shlinkApiClient = buildShlinkApiClient(selectedServer);
|
||||
|
||||
try {
|
||||
await shlinkApiClient.deleteShortUrl(shortCode);
|
||||
dispatch({ type: DELETE_SHORT_URL, shortCode });
|
||||
@@ -69,7 +72,7 @@ export const _deleteShortUrl = (shlinkApiClient, shortCode) => async (dispatch)
|
||||
}
|
||||
};
|
||||
|
||||
export const deleteShortUrl = curry(_deleteShortUrl)(shlinkApiClient);
|
||||
export const deleteShortUrl = curry(_deleteShortUrl)(buildShlinkApiClient);
|
||||
|
||||
export const resetDeleteShortUrl = () => ({ type: RESET_DELETE_SHORT_URL });
|
||||
|
||||
|
||||
@@ -50,8 +50,10 @@ export default function reducer(state = defaultState, action) {
|
||||
}
|
||||
}
|
||||
|
||||
export const editShortUrlTags = (shlinkApiClient) => (shortCode, tags) => async (dispatch) => {
|
||||
export const editShortUrlTags = (buildShlinkApiClient) => (shortCode, tags) => async (dispatch, getState) => {
|
||||
dispatch({ type: EDIT_SHORT_URL_TAGS_START });
|
||||
const { selectedServer } = getState();
|
||||
const shlinkApiClient = buildShlinkApiClient(selectedServer);
|
||||
|
||||
try {
|
||||
const normalizedTags = await shlinkApiClient.updateShortUrlTags(shortCode, tags);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { assoc, assocPath, reject } from 'ramda';
|
||||
import PropTypes from 'prop-types';
|
||||
import shlinkApiClient from '../../api/ShlinkApiClient';
|
||||
import { buildShlinkApiClientWithAxios as buildShlinkApiClient } from '../../api/ShlinkApiClientBuilder';
|
||||
import { SHORT_URL_TAGS_EDITED } from './shortUrlTags';
|
||||
import { SHORT_URL_DELETED } from './shortUrlDeletion';
|
||||
|
||||
@@ -55,9 +55,12 @@ export default function reducer(state = initialState, action) {
|
||||
}
|
||||
}
|
||||
|
||||
export const _listShortUrls = (shlinkApiClient, params = {}) => async (dispatch) => {
|
||||
export const _listShortUrls = (buildShlinkApiClient, params = {}) => async (dispatch, getState) => {
|
||||
dispatch({ type: LIST_SHORT_URLS_START });
|
||||
|
||||
const { selectedServer } = getState();
|
||||
const shlinkApiClient = buildShlinkApiClient(selectedServer);
|
||||
|
||||
try {
|
||||
const shortUrls = await shlinkApiClient.listShortUrls(params);
|
||||
|
||||
@@ -67,4 +70,4 @@ export const _listShortUrls = (shlinkApiClient, params = {}) => async (dispatch)
|
||||
}
|
||||
};
|
||||
|
||||
export const listShortUrls = (params = {}) => _listShortUrls(shlinkApiClient, params);
|
||||
export const listShortUrls = (params = {}) => _listShortUrls(buildShlinkApiClient, params);
|
||||
|
||||
Reference in New Issue
Block a user