shlink-web-client/src/short-urls/reducers/shortUrlsList.js

31 lines
985 B
JavaScript
Raw Normal View History

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