mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-19 21:16:18 +00:00
Refactored server reducer, removing duplicated code and taking advantage of redux-actions
This commit is contained in:
@@ -21,9 +21,7 @@ export const selectServer = (serversService) => (serverId) => (dispatch) => {
|
||||
});
|
||||
};
|
||||
|
||||
const reducer = handleActions({
|
||||
export default handleActions({
|
||||
[RESET_SELECTED_SERVER]: () => defaultState,
|
||||
[SELECT_SERVER]: (state, { selectedServer }) => selectedServer,
|
||||
}, defaultState);
|
||||
|
||||
export default reducer;
|
||||
|
||||
@@ -1,33 +1,16 @@
|
||||
import { createAction, handleActions } from 'redux-actions';
|
||||
import { pipe } from 'ramda';
|
||||
|
||||
export const FETCH_SERVERS = 'shlink/servers/FETCH_SERVERS';
|
||||
|
||||
export default function reducer(state = {}, action) {
|
||||
switch (action.type) {
|
||||
case FETCH_SERVERS:
|
||||
return action.servers;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
export const listServers = ({ listServers }) => createAction(FETCH_SERVERS, () => listServers());
|
||||
|
||||
export const listServers = (serversService) => () => ({
|
||||
type: FETCH_SERVERS,
|
||||
servers: serversService.listServers(),
|
||||
});
|
||||
export const createServer = ({ createServer }, listServers) => pipe(createServer, listServers);
|
||||
|
||||
export const createServer = (serversService, listServers) => (server) => {
|
||||
serversService.createServer(server);
|
||||
export const deleteServer = ({ deleteServer }, listServers) => pipe(deleteServer, listServers);
|
||||
|
||||
return listServers();
|
||||
};
|
||||
export const createServers = ({ createServers }, listServers) => pipe(createServers, listServers);
|
||||
|
||||
export const deleteServer = (serversService, listServers) => (server) => {
|
||||
serversService.deleteServer(server);
|
||||
|
||||
return listServers();
|
||||
};
|
||||
|
||||
export const createServers = (serversService, listServers) => (servers) => {
|
||||
serversService.createServers(servers);
|
||||
|
||||
return listServers();
|
||||
};
|
||||
export default handleActions({
|
||||
[FETCH_SERVERS]: (state, { payload }) => payload,
|
||||
}, {});
|
||||
|
||||
Reference in New Issue
Block a user