2019-08-26 12:41:21 +00:00
|
|
|
import { createReducer } from "../../utils/PicassoUtils"
|
|
|
|
|
import {
|
|
|
|
|
ActionTypes,
|
|
|
|
|
ReduxAction,
|
|
|
|
|
LoadCanvasPayload,
|
|
|
|
|
LoadWidgetCardsPanePayload
|
|
|
|
|
} from "../../constants/ActionConstants"
|
|
|
|
|
import { IWidgetCardProps, IWidgetProps } from "../../widgets/BaseWidget"
|
2019-08-29 11:22:09 +00:00
|
|
|
import { ContainerWidgetProps } from "../../widgets/ContainerWidget"
|
2019-08-26 12:41:21 +00:00
|
|
|
|
|
|
|
|
const initialState: EditorReduxState = {}
|
|
|
|
|
|
|
|
|
|
const editorReducer = createReducer(initialState, {
|
|
|
|
|
[ActionTypes.SUCCESS_FETCHING_WIDGET_CARDS]: (
|
|
|
|
|
state: EditorReduxState,
|
|
|
|
|
action: ReduxAction<LoadWidgetCardsPanePayload>
|
|
|
|
|
) => {
|
|
|
|
|
return { ...state.pageWidget, ...action.payload }
|
|
|
|
|
},
|
|
|
|
|
[ActionTypes.ADD_PAGE_WIDGET]: (
|
|
|
|
|
state: EditorReduxState,
|
|
|
|
|
action: ReduxAction<{pageId: string, widget: IWidgetProps}>
|
|
|
|
|
) => {
|
|
|
|
|
return state
|
|
|
|
|
},
|
|
|
|
|
[ActionTypes.UPDATE_CANVAS]: (
|
|
|
|
|
state: EditorReduxState,
|
|
|
|
|
action: ReduxAction<LoadCanvasPayload>
|
|
|
|
|
) => {
|
|
|
|
|
return { pageWidgetId: action.payload.pageWidgetId }
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export interface EditorReduxState {
|
2019-08-29 11:22:09 +00:00
|
|
|
pageWidget?: ContainerWidgetProps<any>;
|
2019-08-26 12:41:21 +00:00
|
|
|
cards?: {
|
2019-08-29 11:22:09 +00:00
|
|
|
[id: string]: IWidgetCardProps[];
|
2019-08-26 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default editorReducer
|