2019-09-02 12:25:17 +00:00
|
|
|
import { createReducer } from "../../utils/AppsmithUtils"
|
2019-08-26 12:41:21 +00:00
|
|
|
import {
|
|
|
|
|
ActionTypes,
|
|
|
|
|
ReduxAction,
|
|
|
|
|
LoadCanvasPayload,
|
|
|
|
|
LoadWidgetCardsPanePayload
|
|
|
|
|
} from "../../constants/ActionConstants"
|
2019-09-09 09:08:54 +00:00
|
|
|
import { WidgetCardProps, WidgetProps } 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,
|
2019-09-09 09:08:54 +00:00
|
|
|
action: ReduxAction<{pageId: string, widget: WidgetProps}>
|
2019-08-26 12:41:21 +00:00
|
|
|
) => {
|
|
|
|
|
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-09-06 09:30:22 +00:00
|
|
|
[id: string]: WidgetCardProps[];
|
2019-09-02 10:58:11 +00:00
|
|
|
};
|
2019-08-26 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default editorReducer
|