mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-11 01:53:51 +00:00
Removed duplicated code when building ShlinkApiClient
This commit is contained in:
@@ -35,7 +35,7 @@ const ShortUrlsRowMenu = (DeleteShortUrlModal, EditTagsModal) => class ShortUrls
|
||||
toggle = () => this.setState(({ isOpen }) => ({ isOpen: !isOpen }));
|
||||
|
||||
render() {
|
||||
const { onCopyToClipboard, shortUrl, selectedServer: { id } } = this.props;
|
||||
const { onCopyToClipboard, shortUrl, selectedServer } = this.props;
|
||||
const completeShortUrl = shortUrl && shortUrl.shortUrl ? shortUrl.shortUrl : '';
|
||||
const toggleModal = (prop) => () => this.setState((prevState) => ({ [prop]: !prevState[prop] }));
|
||||
const toggleQrCode = toggleModal('isQrModalOpen');
|
||||
@@ -49,7 +49,7 @@ const ShortUrlsRowMenu = (DeleteShortUrlModal, EditTagsModal) => class ShortUrls
|
||||
<FontAwesomeIcon icon={menuIcon} />
|
||||
</DropdownToggle>
|
||||
<DropdownMenu right>
|
||||
<DropdownItem tag={Link} to={`/server/${id}/short-code/${shortUrl.shortCode}/visits`}>
|
||||
<DropdownItem tag={Link} to={`/server/${selectedServer ? selectedServer.id : ''}/short-code/${shortUrl.shortCode}/visits`}>
|
||||
<FontAwesomeIcon icon={pieChartIcon} /> Visit stats
|
||||
</DropdownItem>
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user