Moved management of filtering options to own reducer

This commit is contained in:
Alejandro Celaya
2018-06-17 17:12:16 +02:00
parent 6587a08ed1
commit 1f157a015b
8 changed files with 100 additions and 21 deletions

View File

@@ -1,10 +1,11 @@
import { LIST_SHORT_URLS } from '../../reducers/types';
import { LIST_SHORT_URLS, UPDATE_SHORT_URLS_LIST } from '../../reducers/types';
import ServersService from '../../servers/services';
import ShlinkApiClient from '../../api/ShlinkApiClient';
export default function shortUrlsListReducer(state = [], action) {
switch (action.type) {
case LIST_SHORT_URLS:
case UPDATE_SHORT_URLS_LIST:
return action.shortUrls;
default:
return state;
@@ -20,3 +21,10 @@ export const listShortUrls = (serverId, params = {}) => {
dispatch({ type: LIST_SHORT_URLS, shortUrls, selectedServer });
};
};
export const updateShortUrlsList = (params = {}) => {
return async dispatch => {
const shortUrls = await ShlinkApiClient.listShortUrls(params);
dispatch({ type: UPDATE_SHORT_URLS_LIST, shortUrls, params });
};
};

View File

@@ -0,0 +1,10 @@
import { UPDATE_SHORT_URLS_LIST } from '../../reducers/types';
export default function shortUrlsListReducer(state = { page: 1 }, action) {
switch (action.type) {
case UPDATE_SHORT_URLS_LIST:
return { ...state, ...action.params };
default:
return state;
}
}