chore: refactoring deploys (#5135)
This commit is contained in:
committed by
GitHub
parent
a0ae13a665
commit
822acd4585
@ -1,46 +0,0 @@
|
||||
import { Map, fromJS } from 'immutable';
|
||||
import {
|
||||
DEPLOY_PREVIEW_REQUEST,
|
||||
DEPLOY_PREVIEW_SUCCESS,
|
||||
DEPLOY_PREVIEW_FAILURE,
|
||||
} from 'Actions/deploys';
|
||||
|
||||
function deploys(state = Map({ deploys: Map() }), action) {
|
||||
switch (action.type) {
|
||||
case DEPLOY_PREVIEW_REQUEST: {
|
||||
const { collection, slug } = action.payload;
|
||||
return state.setIn(['deploys', `${collection}.${slug}`, 'isFetching'], true);
|
||||
}
|
||||
|
||||
case DEPLOY_PREVIEW_SUCCESS: {
|
||||
const { collection, slug, url, status } = action.payload;
|
||||
return state.setIn(
|
||||
['deploys', `${collection}.${slug}`],
|
||||
fromJS({
|
||||
isFetching: false,
|
||||
url,
|
||||
status,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
case DEPLOY_PREVIEW_FAILURE: {
|
||||
const { collection, slug } = action.payload;
|
||||
return state.setIn(
|
||||
['deploys', `${collection}.${slug}`],
|
||||
fromJS({
|
||||
isFetching: false,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
||||
export function selectDeployPreview(state, collection, slug) {
|
||||
return state.getIn(['deploys', `${collection}.${slug}`]);
|
||||
}
|
||||
|
||||
export default deploys;
|
50
packages/netlify-cms-core/src/reducers/deploys.ts
Normal file
50
packages/netlify-cms-core/src/reducers/deploys.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { produce } from 'immer';
|
||||
import {
|
||||
DEPLOY_PREVIEW_REQUEST,
|
||||
DEPLOY_PREVIEW_SUCCESS,
|
||||
DEPLOY_PREVIEW_FAILURE,
|
||||
DeploysAction,
|
||||
} from '../actions/deploys';
|
||||
|
||||
export type Deploys = {
|
||||
[key: string]: {
|
||||
isFetching: boolean;
|
||||
url?: string;
|
||||
status?: string;
|
||||
};
|
||||
};
|
||||
|
||||
const defaultState: Deploys = {};
|
||||
|
||||
const deploys = produce((state: Deploys, action: DeploysAction) => {
|
||||
switch (action.type) {
|
||||
case DEPLOY_PREVIEW_REQUEST: {
|
||||
const { collection, slug } = action.payload;
|
||||
const key = `${collection}.${slug}`;
|
||||
state[key] = state[key] || {};
|
||||
state[key].isFetching = true;
|
||||
break;
|
||||
}
|
||||
|
||||
case DEPLOY_PREVIEW_SUCCESS: {
|
||||
const { collection, slug, url, status } = action.payload;
|
||||
const key = `${collection}.${slug}`;
|
||||
state[key].isFetching = false;
|
||||
state[key].url = url;
|
||||
state[key].status = status;
|
||||
break;
|
||||
}
|
||||
|
||||
case DEPLOY_PREVIEW_FAILURE: {
|
||||
const { collection, slug } = action.payload;
|
||||
state[`${collection}.${slug}`].isFetching = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, defaultState);
|
||||
|
||||
export function selectDeployPreview(state: Deploys, collection: string, slug: string) {
|
||||
return state[`${collection}.${slug}`];
|
||||
}
|
||||
|
||||
export default deploys;
|
Reference in New Issue
Block a user