PromucFlow_constructor/app/client/src/pages/Editor/routes.tsx

66 lines
1.7 KiB
TypeScript
Raw Normal View History

2019-10-18 08:16:26 +00:00
import React from "react";
import {
Route,
Switch,
withRouter,
RouteComponentProps,
} from "react-router-dom";
import ApiEditor from "./ApiEditor";
2019-10-21 15:12:45 +00:00
import {
API_EDITOR_ID_URL,
API_EDITOR_URL,
BUILDER_URL,
} from "../../constants/routes";
2019-10-18 08:16:26 +00:00
import { Drawer, Position } from "@blueprintjs/core";
import styled from "styled-components";
2019-10-21 15:12:45 +00:00
import { theme } from "../../constants/DefaultTheme";
2019-10-18 08:16:26 +00:00
const MainWrapper = styled.div`
position: absolute;
width: calc(100vw - ${props => props.theme.sidebarWidth});
height: calc(100vh - ${props => props.theme.headerHeight});
left: ${props => props.theme.sidebarWidth};
`;
interface RouterState {
drawerOpen: boolean;
}
class EditorsRouter extends React.Component<RouteComponentProps, RouterState> {
constructor(props: RouteComponentProps) {
super(props);
this.state = {
drawerOpen: this.props.location.pathname !== BUILDER_URL,
};
}
componentDidUpdate(prevProps: Readonly<RouteComponentProps>): void {
if (this.props.location.pathname !== prevProps.location.pathname) {
this.setState({
drawerOpen: this.props.location.pathname !== BUILDER_URL,
});
}
}
render(): React.ReactNode {
const drawerOpen = this.props.location.pathname !== BUILDER_URL;
return (
<MainWrapper>
<Drawer
isOpen={drawerOpen}
position={Position.LEFT}
usePortal={false}
2019-10-21 15:12:45 +00:00
size={theme.drawerWidth}
canOutsideClickClose={true}
2019-10-18 08:16:26 +00:00
>
<Switch>
<Route exact path={API_EDITOR_URL} component={ApiEditor} />
2019-10-21 15:12:45 +00:00
<Route exact path={API_EDITOR_ID_URL()} component={ApiEditor} />
2019-10-18 08:16:26 +00:00
</Switch>
</Drawer>
</MainWrapper>
);
}
}
export default withRouter(EditorsRouter);