UNPKG

decap-cms-core

Version:

Decap CMS core application, see decap-cms package for the main distribution.

50 lines 1.3 kB
import { produce } from 'immer'; import { DEPLOY_PREVIEW_REQUEST, DEPLOY_PREVIEW_SUCCESS, DEPLOY_PREVIEW_FAILURE } from '../actions/deploys'; const defaultState = {}; const deploys = produce((state, action) => { switch (action.type) { case DEPLOY_PREVIEW_REQUEST: { const { collection, slug } = action.payload; const key = `${collection}.${slug}`; state[key] = { isFetching: true, status: 'PENDING' }; 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; const key = `${collection}.${slug}`; state[key].isFetching = false; state[key].url = undefined; state[key].status = 'PENDING'; break; } } }, defaultState); export function selectDeployPreview(state, collection, slug) { return state[`${collection}.${slug}`]; } export default deploys;