mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-07-26 05:31:57 +00:00
Some minor refactorings
This commit is contained in:
@@ -3,21 +3,21 @@ import { pipe, isEmpty, assoc, map, prop } from 'ramda';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { homepage } from '../../../package.json';
|
||||
|
||||
export const FETCH_SERVERS = 'shlink/servers/FETCH_SERVERS';
|
||||
export const LIST_SERVERS = 'shlink/servers/LIST_SERVERS';
|
||||
|
||||
const initialState = {};
|
||||
|
||||
const assocId = (server) => assoc('id', server.id || uuid(), server);
|
||||
|
||||
export default handleActions({
|
||||
[FETCH_SERVERS]: (state, { list }) => list,
|
||||
[LIST_SERVERS]: (state, { list }) => list,
|
||||
}, initialState);
|
||||
|
||||
export const listServers = ({ listServers, createServers }, { get }) => () => async (dispatch) => {
|
||||
const localList = listServers();
|
||||
|
||||
if (!isEmpty(localList)) {
|
||||
dispatch({ type: FETCH_SERVERS, list: localList });
|
||||
dispatch({ type: LIST_SERVERS, list: localList });
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -39,7 +39,7 @@ export const listServers = ({ listServers, createServers }, { get }) => () => as
|
||||
.catch(() => []);
|
||||
|
||||
createServers(remoteList);
|
||||
dispatch({ type: FETCH_SERVERS, list: remoteList.reduce((map, server) => ({ ...map, [server.id]: server }), {}) });
|
||||
dispatch({ type: LIST_SERVERS, list: remoteList.reduce((map, server) => ({ ...map, [server.id]: server }), {}) });
|
||||
};
|
||||
|
||||
export const createServer = ({ createServer }, listServersAction) => pipe(createServer, listServersAction);
|
||||
Reference in New Issue
Block a user