2018-06-15 22:49:25 +03:00
|
|
|
import { LIST_SHORT_URLS } 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:
|
|
|
|
return action.shortUrls;
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const listShortUrls = (serverId) => {
|
|
|
|
return async dispatch => {
|
|
|
|
const selectedServer = ServersService.findServerById(serverId);
|
|
|
|
|
|
|
|
ShlinkApiClient.setConfig(selectedServer);
|
2018-06-15 22:51:50 +03:00
|
|
|
const shortUrls = await ShlinkApiClient.listShortUrls();
|
|
|
|
dispatch({ type: LIST_SHORT_URLS, shortUrls });
|
2018-06-15 22:49:25 +03:00
|
|
|
};
|
|
|
|
};
|