feat: Add Header to Document History Sidebar

This commit is contained in:
Guilherme Diniz
2020-08-21 20:58:57 -03:00
parent ec55299c8b
commit 05f48f054b

View File

@ -1,20 +1,23 @@
// @flow // @flow
import ArrowKeyNavigation from "boundless-arrow-key-navigation"; import ArrowKeyNavigation from "boundless-arrow-key-navigation";
import { observable, action } from "mobx"; import { action, observable } from "mobx";
import { observer, inject } from "mobx-react"; import { inject, observer } from "mobx-react";
import { CloseIcon } from "outline-icons";
import * as React from "react"; import * as React from "react";
import { type RouterHistory, type Match } from "react-router-dom"; import { type Match, Redirect, type RouterHistory } from "react-router-dom";
import { Waypoint } from "react-waypoint"; import { Waypoint } from "react-waypoint";
import styled from "styled-components"; import styled from "styled-components";
import { DEFAULT_PAGINATION_LIMIT } from "stores/BaseStore"; import { DEFAULT_PAGINATION_LIMIT } from "stores/BaseStore";
import DocumentsStore from "stores/DocumentsStore"; import DocumentsStore from "stores/DocumentsStore";
import RevisionsStore from "stores/RevisionsStore"; import RevisionsStore from "stores/RevisionsStore";
import Document from "models/Document";
import Flex from "components/Flex"; import Flex from "components/Flex";
import { ListPlaceholder } from "components/LoadingPlaceholder"; import { ListPlaceholder } from "components/LoadingPlaceholder";
import Button from "../Button";
import Revision from "./components/Revision"; import Revision from "./components/Revision";
import { documentHistoryUrl } from "utils/routeHelpers"; import { documentHistoryUrl, documentUrl } from "utils/routeHelpers";
type Props = { type Props = {
match: Match, match: Match,
@ -29,6 +32,7 @@ class DocumentHistory extends React.Component<Props> {
@observable isFetching: boolean = false; @observable isFetching: boolean = false;
@observable offset: number = 0; @observable offset: number = 0;
@observable allowLoadMore: boolean = true; @observable allowLoadMore: boolean = true;
@observable redirectTo: ?string;
async componentDidMount() { async componentDidMount() {
await this.loadMoreResults(); await this.loadMoreResults();
@ -86,15 +90,30 @@ class DocumentHistory extends React.Component<Props> {
return this.props.revisions.getDocumentRevisions(document.id); return this.props.revisions.getDocumentRevisions(document.id);
} }
onCloseHistory = (document: Document) => {
this.redirectTo = documentUrl(document);
};
render() { render() {
const document = this.props.documents.getByUrl( const document = this.props.documents.getByUrl(
this.props.match.params.documentSlug this.props.match.params.documentSlug
); );
const showLoading = (!this.isLoaded && this.isFetching) || !document; const showLoading = (!this.isLoaded && this.isFetching) || !document;
if (this.redirectTo) return <Redirect to={this.redirectTo} push />;
return ( return (
<Sidebar> <Sidebar>
<Wrapper column> <Wrapper column>
<Header justify={"center"}>
<Title>History</Title>
<CloseButton
icon={<CloseIcon />}
onClick={() => this.onCloseHistory(document)}
neutral
borderOnHover
/>
</Header>
{showLoading ? ( {showLoading ? (
<Loading> <Loading>
<ListPlaceholder count={5} /> <ListPlaceholder count={5} />
@ -146,4 +165,29 @@ const Sidebar = styled(Flex)`
z-index: 1; z-index: 1;
`; `;
const Title = styled.h3`
max-width: 90%;
overflow: hidden;
text-overflow: ellipsis;
font-size: 20px;
margin-top: 0;
margin-bottom: 0.25em;
white-space: nowrap;
color: ${(props) => props.theme.text};
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
`;
const Header = styled(Flex)`
position: relative;
padding: 20px;
border-bottom: 1px solid ${(props) => props.theme.divider};
`;
const CloseButton = styled(Button)`
position: absolute;
top: 10px;
right: 10px;
`;
export default inject("documents", "revisions")(DocumentHistory); export default inject("documents", "revisions")(DocumentHistory);