2019-11-25 05:07:27 +00:00
|
|
|
import { createReducer } from "utils/AppsmithUtils";
|
|
|
|
|
import { WidgetProps } from "widgets/BaseWidget";
|
|
|
|
|
import { ContainerWidgetProps } from "widgets/ContainerWidget";
|
2019-10-31 08:36:04 +00:00
|
|
|
import {
|
|
|
|
|
ReduxAction,
|
|
|
|
|
ReduxActionTypes,
|
|
|
|
|
PageListPayload,
|
2019-11-25 05:07:27 +00:00
|
|
|
} from "constants/ReduxActionConstants";
|
2020-03-19 03:25:52 +00:00
|
|
|
import { FetchPublishedPageSuccessPayload } from "actions/pageActions";
|
2019-10-31 08:36:04 +00:00
|
|
|
|
|
|
|
|
const initialState: AppViewReduxState = {
|
|
|
|
|
isFetchingPage: false,
|
2020-01-24 09:54:40 +00:00
|
|
|
initialized: false,
|
2019-10-31 08:36:04 +00:00
|
|
|
pages: [],
|
2019-11-14 11:17:36 +00:00
|
|
|
pageWidgetId: "0",
|
2019-10-31 08:36:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const appViewReducer = createReducer(initialState, {
|
2019-11-22 14:02:55 +00:00
|
|
|
[ReduxActionTypes.INITIALIZE_PAGE_VIEWER]: (state: AppViewReduxState) => {
|
2020-01-24 09:54:40 +00:00
|
|
|
return { ...state, initialized: false };
|
|
|
|
|
},
|
|
|
|
|
[ReduxActionTypes.INITIALIZE_PAGE_VIEWER_SUCCESS]: (
|
|
|
|
|
state: AppViewReduxState,
|
|
|
|
|
) => {
|
|
|
|
|
return { ...state, initialized: true };
|
2019-10-31 08:36:04 +00:00
|
|
|
},
|
|
|
|
|
[ReduxActionTypes.FETCH_PUBLISHED_PAGE_INIT]: (state: AppViewReduxState) => {
|
2019-11-06 06:21:56 +00:00
|
|
|
return { ...state, dsl: undefined, isFetchingPage: true };
|
2019-10-31 08:36:04 +00:00
|
|
|
},
|
|
|
|
|
[ReduxActionTypes.FETCH_PUBLISHED_PAGE_ERROR]: (state: AppViewReduxState) => {
|
|
|
|
|
return { ...state, isFetchingPage: false };
|
|
|
|
|
},
|
|
|
|
|
[ReduxActionTypes.FETCH_PUBLISHED_PAGE_SUCCESS]: (
|
|
|
|
|
state: AppViewReduxState,
|
2020-03-19 03:25:52 +00:00
|
|
|
action: ReduxAction<FetchPublishedPageSuccessPayload>,
|
2019-10-31 08:36:04 +00:00
|
|
|
) => {
|
|
|
|
|
return {
|
2020-01-24 09:54:40 +00:00
|
|
|
...state,
|
2019-10-31 08:36:04 +00:00
|
|
|
dsl: action.payload.dsl,
|
|
|
|
|
isFetchingPage: false,
|
2019-11-14 11:17:36 +00:00
|
|
|
pageWidgetId: action.payload.pageWidgetId,
|
2019-10-31 08:36:04 +00:00
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export interface AppViewReduxState {
|
2020-01-24 09:54:40 +00:00
|
|
|
initialized: boolean;
|
2019-10-31 08:36:04 +00:00
|
|
|
dsl?: ContainerWidgetProps<WidgetProps>;
|
|
|
|
|
isFetchingPage: boolean;
|
|
|
|
|
currentLayoutId?: string;
|
|
|
|
|
pages: PageListPayload;
|
2019-11-14 11:17:36 +00:00
|
|
|
pageWidgetId: string;
|
2019-10-31 08:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default appViewReducer;
|