Prevented short URLs list to be reloaded when tags are edited

This commit is contained in:
Alejandro Celaya
2018-08-18 17:14:33 +02:00
parent b5de9bf523
commit 680d80d753
4 changed files with 34 additions and 14 deletions

View File

@@ -6,6 +6,7 @@ export const EDIT_SHORT_URL_TAGS_START = 'shlink/shortUrlTags/EDIT_SHORT_URL_TAG
export const EDIT_SHORT_URL_TAGS_ERROR = 'shlink/shortUrlTags/EDIT_SHORT_URL_TAGS_ERROR';
export const EDIT_SHORT_URL_TAGS = 'shlink/shortUrlTags/EDIT_SHORT_URL_TAGS';
export const RESET_EDIT_SHORT_URL_TAGS = 'shlink/shortUrlTags/RESET_EDIT_SHORT_URL_TAGS';
export const SHORT_URL_TAGS_EDITED = 'shlink/shortUrlTags/SHORT_URL_TAGS_EDITED';
export const shortUrlTagsType = PropTypes.shape({
shortCode: PropTypes.string,
@@ -64,3 +65,9 @@ export const _editShortUrlTags = (ShlinkApiClient, shortCode, tags) => async (di
export const editShortUrlTags = curry(_editShortUrlTags)(ShlinkApiClient);
export const resetShortUrlsTags = () => ({ type: RESET_EDIT_SHORT_URL_TAGS });
export const shortUrlTagsEdited = (shortCode, tags) => ({
tags,
shortCode,
type: SHORT_URL_TAGS_EDITED,
});

View File

@@ -1,4 +1,6 @@
import ShlinkApiClient from '../../api/ShlinkApiClient';
import { SHORT_URL_TAGS_EDITED } from './shortUrlTags';
import { assoc, assocPath } from 'ramda';
const LIST_SHORT_URLS_START = 'shlink/shortUrlsList/LIST_SHORT_URLS_START';
const LIST_SHORT_URLS_ERROR = 'shlink/shortUrlsList/LIST_SHORT_URLS_ERROR';
@@ -25,6 +27,13 @@ export default function reducer(state = initialState, action) {
error: true,
shortUrls: []
};
case SHORT_URL_TAGS_EDITED:
const { data } = state.shortUrls;
return assocPath(['shortUrls', 'data'], data.map(shortUrl =>
shortUrl.shortCode === action.shortCode
? assoc('tags', action.tags, shortUrl)
: shortUrl
), state);
default:
return state;
}
@@ -41,9 +50,3 @@ export const _listShortUrls = (ShlinkApiClient, params = {}) => async dispatch =
}
};
export const listShortUrls = (params = {}) => _listShortUrls(ShlinkApiClient, params);
export const _refreshShortUrls = ShlinkApiClient => async (dispatch, getState) => {
const { shortUrlsListParams } = getState();
await _listShortUrls(ShlinkApiClient, shortUrlsListParams)(dispatch);
};
export const refreshShortUrls = () => _refreshShortUrls(ShlinkApiClient);