2019-10-18 08:16:26 +00:00
|
|
|
import React, { Component } from "react";
|
2019-09-09 10:30:22 +00:00
|
|
|
import { connect } from "react-redux";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { AppState } from "../../reducers";
|
|
|
|
|
import EditorHeader from "./EditorHeader";
|
2019-10-18 08:16:26 +00:00
|
|
|
import EditorsRouter from "./routes";
|
2019-10-21 15:12:45 +00:00
|
|
|
import NavBar from "../../components/editor/NavBar";
|
2019-10-18 08:16:26 +00:00
|
|
|
import WidgetsEditor from "./WidgetsEditor";
|
2019-10-24 09:23:50 +00:00
|
|
|
import {
|
|
|
|
|
getCurrentApplicationId,
|
|
|
|
|
getCurrentLayoutId,
|
|
|
|
|
getCurrentPageId,
|
|
|
|
|
} from "../../selectors/editorSelectors";
|
|
|
|
|
import { ReduxActionTypes } from "../../constants/ReduxActionConstants";
|
2019-08-20 13:19:19 +00:00
|
|
|
|
2019-10-18 08:16:26 +00:00
|
|
|
const MainContainer = styled.div`
|
2019-08-26 12:41:21 +00:00
|
|
|
display: flex;
|
2019-08-29 11:22:09 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
type EditorProps = {
|
2019-09-27 08:08:31 +00:00
|
|
|
currentPageName: string;
|
2019-09-23 10:27:45 +00:00
|
|
|
isSaving: boolean;
|
2019-10-24 09:23:50 +00:00
|
|
|
currentApplicationId?: string;
|
|
|
|
|
currentLayoutId: string;
|
|
|
|
|
currentPageId: string;
|
|
|
|
|
publishApplication: Function;
|
|
|
|
|
previewPage: Function;
|
2019-09-09 10:30:22 +00:00
|
|
|
};
|
2019-08-26 12:41:21 +00:00
|
|
|
|
2019-08-29 11:22:09 +00:00
|
|
|
class Editor extends Component<EditorProps> {
|
2019-10-24 09:23:50 +00:00
|
|
|
handlePublish = () => {
|
|
|
|
|
if (this.props.currentApplicationId)
|
|
|
|
|
this.props.publishApplication(this.props.currentApplicationId);
|
|
|
|
|
};
|
|
|
|
|
handlePreview = () => {
|
|
|
|
|
this.props.previewPage(
|
|
|
|
|
this.props.currentPageId,
|
|
|
|
|
this.props.currentLayoutId,
|
|
|
|
|
);
|
|
|
|
|
//TODO(abhinav): Add logic to open in a different tab.
|
|
|
|
|
};
|
2019-08-29 11:22:09 +00:00
|
|
|
public render() {
|
2019-02-07 05:07:09 +00:00
|
|
|
return (
|
2019-10-18 08:16:26 +00:00
|
|
|
<div>
|
2019-09-27 08:08:31 +00:00
|
|
|
<EditorHeader
|
|
|
|
|
notificationText={this.props.isSaving ? "Saving page..." : undefined}
|
|
|
|
|
pageName={this.props.currentPageName}
|
2019-10-24 09:23:50 +00:00
|
|
|
onPublish={this.handlePublish}
|
|
|
|
|
onPreview={this.handlePreview}
|
2019-09-27 08:08:31 +00:00
|
|
|
/>
|
2019-10-18 08:16:26 +00:00
|
|
|
<MainContainer>
|
|
|
|
|
<NavBar />
|
|
|
|
|
<EditorsRouter />
|
|
|
|
|
<WidgetsEditor />
|
|
|
|
|
</MainContainer>
|
|
|
|
|
</div>
|
2019-09-09 10:30:22 +00:00
|
|
|
);
|
2019-02-07 05:07:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 09:23:50 +00:00
|
|
|
const mapStateToProps = (state: AppState) => ({
|
2019-10-18 08:16:26 +00:00
|
|
|
currentPageName: state.ui.editor.currentPageName,
|
|
|
|
|
isSaving: state.ui.editor.isSaving,
|
2019-10-24 09:23:50 +00:00
|
|
|
currentApplicationId: getCurrentApplicationId(state),
|
|
|
|
|
currentPageId: getCurrentPageId(state),
|
|
|
|
|
currentLayoutId: getCurrentLayoutId(state),
|
2019-10-18 08:16:26 +00:00
|
|
|
});
|
2019-08-26 12:41:21 +00:00
|
|
|
|
2019-10-24 09:23:50 +00:00
|
|
|
const mapDispatchToProps = (dispatch: any) => {
|
|
|
|
|
return {
|
|
|
|
|
publishApplication: (applicationId: string) => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: ReduxActionTypes.PUBLISH_APPLICATION_INIT,
|
|
|
|
|
payload: {
|
|
|
|
|
applicationId,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
previewPage: (pageId: string, layoutId: string) => {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: ReduxActionTypes.FETCH_PUBLISHED_PAGE_INIT,
|
|
|
|
|
payload: {
|
|
|
|
|
pageId,
|
|
|
|
|
layoutId,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
|
mapStateToProps,
|
|
|
|
|
mapDispatchToProps,
|
|
|
|
|
)(Editor);
|