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 styled from "styled-components";
|
|
|
|
|
|
2019-10-29 12:02:58 +00:00
|
|
|
const Wrapper = styled.div<{ isVisible: boolean }>`
|
2019-10-18 08:16:26 +00:00
|
|
|
position: absolute;
|
2019-10-29 12:02:58 +00:00
|
|
|
top: 1px;
|
|
|
|
|
left: 1px;
|
|
|
|
|
width: 100%;
|
2019-10-18 08:16:26 +00:00
|
|
|
height: calc(100vh - ${props => props.theme.headerHeight});
|
2019-10-29 12:02:58 +00:00
|
|
|
background-color: ${props =>
|
|
|
|
|
props.isVisible ? "rgba(0, 0, 0, 0.26)" : "transparent"};
|
|
|
|
|
z-index: ${props => (props.isVisible ? 10 : -1)};
|
|
|
|
|
transition-property: z-index;
|
|
|
|
|
transition-delay: ${props => (props.isVisible ? "0" : "0.25s")};
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const DrawerWrapper = styled.div<{ isVisible: boolean }>`
|
|
|
|
|
background-color: white;
|
2019-11-13 11:34:11 +00:00
|
|
|
width: 75%;
|
2019-10-29 12:02:58 +00:00
|
|
|
height: 100%;
|
|
|
|
|
box-shadow: -1px 2px 3px 0px ${props => props.theme.colors.paneBG};
|
|
|
|
|
transform: translateX(${props => (props.isVisible ? `0` : `-80vw`)});
|
|
|
|
|
transition: 0.25s;
|
2019-10-18 08:16:26 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
interface RouterState {
|
2019-10-29 12:02:58 +00:00
|
|
|
isVisible: boolean;
|
2019-10-18 08:16:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class EditorsRouter extends React.Component<RouteComponentProps, RouterState> {
|
|
|
|
|
constructor(props: RouteComponentProps) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
2019-10-29 12:02:58 +00:00
|
|
|
isVisible: this.props.location.pathname !== BUILDER_URL,
|
2019-10-18 08:16:26 +00:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
componentDidUpdate(prevProps: Readonly<RouteComponentProps>): void {
|
|
|
|
|
if (this.props.location.pathname !== prevProps.location.pathname) {
|
|
|
|
|
this.setState({
|
2019-10-29 12:02:58 +00:00
|
|
|
isVisible: this.props.location.pathname !== BUILDER_URL,
|
2019-10-18 08:16:26 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-29 12:02:58 +00:00
|
|
|
handleClose = (e: React.MouseEvent) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
this.setState({
|
|
|
|
|
isVisible: false,
|
|
|
|
|
});
|
|
|
|
|
this.props.history.replace(BUILDER_URL);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
preventClose = (e: React.MouseEvent) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-18 08:16:26 +00:00
|
|
|
render(): React.ReactNode {
|
|
|
|
|
return (
|
2019-10-29 12:02:58 +00:00
|
|
|
<Wrapper isVisible={this.state.isVisible} onClick={this.handleClose}>
|
|
|
|
|
<DrawerWrapper
|
|
|
|
|
isVisible={this.state.isVisible}
|
|
|
|
|
onClick={this.preventClose}
|
2019-10-18 08:16:26 +00:00
|
|
|
>
|
|
|
|
|
<Switch>
|
|
|
|
|
<Route exact path={API_EDITOR_URL} component={ApiEditor} />
|
2019-10-29 12:02:58 +00:00
|
|
|
<Route path={API_EDITOR_ID_URL()} component={ApiEditor} />
|
2019-10-18 08:16:26 +00:00
|
|
|
</Switch>
|
2019-10-29 12:02:58 +00:00
|
|
|
</DrawerWrapper>
|
|
|
|
|
</Wrapper>
|
2019-10-18 08:16:26 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default withRouter(EditorsRouter);
|