// @flow import { throttle } from "lodash"; import { observable } from "mobx"; import { observer, inject } from "mobx-react"; import { TableOfContentsIcon, EditIcon, GlobeIcon, PlusIcon, MoreIcon, } from "outline-icons"; import { transparentize, darken } from "polished"; import * as React from "react"; import { withTranslation, Trans, type TFunction } from "react-i18next"; import { Link } from "react-router-dom"; import styled from "styled-components"; import breakpoint from "styled-components-breakpoint"; import AuthStore from "stores/AuthStore"; import PoliciesStore from "stores/PoliciesStore"; import SharesStore from "stores/SharesStore"; import UiStore from "stores/UiStore"; import Document from "models/Document"; import DocumentShare from "scenes/DocumentShare"; import { Action, Separator } from "components/Actions"; import Badge from "components/Badge"; import Breadcrumb, { Slash } from "components/Breadcrumb"; import Button from "components/Button"; import Collaborators from "components/Collaborators"; import Fade from "components/Fade"; import Flex from "components/Flex"; import Modal from "components/Modal"; import Tooltip from "components/Tooltip"; import DocumentMenu from "menus/DocumentMenu"; import NewChildDocumentMenu from "menus/NewChildDocumentMenu"; import TemplatesMenu from "menus/TemplatesMenu"; import { metaDisplay } from "utils/keyboard"; import { newDocumentUrl, editDocumentUrl } from "utils/routeHelpers"; type Props = { auth: AuthStore, ui: UiStore, shares: SharesStore, policies: PoliciesStore, document: Document, isDraft: boolean, isEditing: boolean, isRevision: boolean, isSaving: boolean, isPublishing: boolean, publishingIsDisabled: boolean, savingIsDisabled: boolean, onDiscard: () => void, onSave: ({ done?: boolean, publish?: boolean, autosave?: boolean, }) => void, t: TFunction, }; @observer class Header extends React.Component { @observable isScrolled = false; @observable showShareModal = false; componentDidMount() { window.addEventListener("scroll", this.handleScroll); } componentWillUnmount() { window.removeEventListener("scroll", this.handleScroll); } updateIsScrolled = () => { this.isScrolled = window.scrollY > 75; }; handleScroll = throttle(this.updateIsScrolled, 50); handleSave = () => { this.props.onSave({ done: true }); }; handlePublish = () => { this.props.onSave({ done: true, publish: true }); }; handleShareLink = async (ev: SyntheticEvent<>) => { const { document } = this.props; await document.share(); this.showShareModal = true; }; handleCloseShareModal = () => { this.showShareModal = false; }; handleClickTitle = () => { window.scrollTo({ top: 0, behavior: "smooth", }); }; render() { const { shares, document, policies, isEditing, isDraft, isPublishing, isRevision, isSaving, savingIsDisabled, publishingIsDisabled, ui, auth, t, } = this.props; const share = shares.getByDocumentId(document.id); const isPubliclyShared = share && share.published; const isNew = document.isNew; const isTemplate = document.isTemplate; const can = policies.abilities(document.id); const canShareDocuments = auth.team && auth.team.sharing && can.share; const canToggleEmbeds = auth.team && auth.team.documentEmbeds; const canEdit = can.update && !isEditing; return ( {!isEditing && ( <> )} {isEditing && ( <> )} {canEdit && ( )} {canEdit && can.createChildDocument && ( ( )} /> )} {canEdit && isTemplate && !isDraft && !isRevision && ( )} {can.update && isDraft && !isRevision && ( )} {!isEditing && ( <> (