2018-06-15 22:49:25 +03:00
|
|
|
import ServersService from '../../servers/services';
|
|
|
|
import ShlinkApiClient from '../../api/ShlinkApiClient';
|
|
|
|
|
2018-07-15 11:28:39 +03:00
|
|
|
export const LIST_SHORT_URLS = 'shlink/shortUrlsList/LIST_SHORT_URLS';
|
|
|
|
export const UPDATE_SHORT_URLS_LIST = 'shlink/shortUrlsList/UPDATE_SHORT_URLS_LIST';
|
|
|
|
|
|
|
|
export default function reducer(state = [], action) {
|
2018-06-15 22:49:25 +03:00
|
|
|
switch (action.type) {
|
|
|
|
case LIST_SHORT_URLS:
|
2018-06-17 18:12:16 +03:00
|
|
|
case UPDATE_SHORT_URLS_LIST:
|
2018-06-15 22:49:25 +03:00
|
|
|
return action.shortUrls;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-16 12:24:42 +03:00
|
|
|
export const listShortUrls = (serverId, params = {}) => {
|
2018-06-15 22:49:25 +03:00
|
|
|
return async dispatch => {
|
|
|
|
const selectedServer = ServersService.findServerById(serverId);
|
|
|
|
|
|
|
|
ShlinkApiClient.setConfig(selectedServer);
|
2018-06-16 12:24:42 +03:00
|
|
|
const shortUrls = await ShlinkApiClient.listShortUrls(params);
|
|
|
|
dispatch({ type: LIST_SHORT_URLS, shortUrls, selectedServer });
|
2018-06-15 22:49:25 +03:00
|
|
|
};
|
|
|
|
};
|
2018-06-17 18:12:16 +03:00
|
|
|
|
|
|
|
export const updateShortUrlsList = (params = {}) => {
|
|
|
|
return async dispatch => {
|
2018-07-15 11:28:39 +03:00
|
|
|
|
|
|
|
|
2018-06-17 18:12:16 +03:00
|
|
|
const shortUrls = await ShlinkApiClient.listShortUrls(params);
|
|
|
|
dispatch({ type: UPDATE_SHORT_URLS_LIST, shortUrls, params });
|
|
|
|
};
|
|
|
|
};
|