// @flow import * as React from 'react'; import { throttle } from 'lodash'; import { observable } from 'mobx'; import { observer, inject } from 'mobx-react'; import { Redirect } from 'react-router-dom'; import styled from 'styled-components'; import breakpoint from 'styled-components-breakpoint'; import { NewDocumentIcon } from 'outline-icons'; import { transparentize } from 'polished'; import Document from 'models/Document'; import AuthStore from 'stores/AuthStore'; import { documentEditUrl } from 'utils/routeHelpers'; import { meta } from 'utils/keyboard'; import Flex from 'shared/components/Flex'; import Breadcrumb from './Breadcrumb'; import DocumentMenu from 'menus/DocumentMenu'; import NewChildDocumentMenu from 'menus/NewChildDocumentMenu'; import DocumentShare from 'scenes/DocumentShare'; import Button from 'components/Button'; import Modal from 'components/Modal'; import Collaborators from 'components/Collaborators'; import { Action, Separator } from 'components/Actions'; type Props = { document: Document, isDraft: boolean, isEditing: boolean, isSaving: boolean, isPublishing: boolean, savingIsDisabled: boolean, onDiscard: () => *, onSave: ({ done?: boolean, publish?: boolean, autosave?: boolean, }) => *, auth: AuthStore, }; @observer class Header extends React.Component { @observable isScrolled = false; @observable showShareModal = false; @observable redirectTo: ?string; componentDidMount() { window.addEventListener('scroll', this.handleScroll); } componentWillUnmount() { window.removeEventListener('scroll', this.handleScroll); } updateIsScrolled = () => { this.isScrolled = window.scrollY > 75; }; handleScroll = throttle(this.updateIsScrolled, 50); handleEdit = () => { this.redirectTo = documentEditUrl(this.props.document); }; handleSave = () => { this.props.onSave({ done: true }); }; handlePublish = () => { this.props.onSave({ done: true, publish: true }); }; handleShareLink = async (ev: SyntheticEvent<*>) => { const { document } = this.props; if (!document.shareUrl) await document.share(); this.showShareModal = true; }; handleCloseShareModal = () => { this.showShareModal = false; }; handleClickTitle = () => { window.scrollTo({ top: 0, behavior: 'smooth', }); }; render() { if (this.redirectTo) return ; const { document, isEditing, isDraft, isPublishing, isSaving, savingIsDisabled, auth, } = this.props; const canShareDocuments = auth.team && auth.team.sharing; const canToggleEmbeds = auth.team && auth.team.documentEmbeds; return ( {document.title} {!isDraft && !isEditing && } {isSaving && !isPublishing && ( Saving… )} {!isDraft && !isEditing && canShareDocuments && ( )} {isEditing && ( )} {isDraft && ( )} {!isEditing && ( )} {!isEditing && ( )} {!isEditing && !isDraft && ( } /> )} ); } } const Status = styled.div` color: ${props => props.theme.slate}; `; const Wrapper = styled(Flex)` width: 100%; align-self: flex-end; ${breakpoint('tablet')` width: 33.3%; `}; `; const Actions = styled(Flex)` position: sticky; top: 0; right: 0; left: 0; z-index: 1; background: ${props => transparentize(0.1, props.theme.background)}; border-bottom: 1px solid ${props => (props.isCompact ? props.theme.background : 'transparent')}; padding: 12px; transition: all 100ms ease-out; transform: translate3d(0, 0, 0); -webkit-backdrop-filter: blur(20px); @media print { display: none; } ${breakpoint('tablet')` padding: ${props => (props.isCompact ? '12px' : `24px 24px 0`)}; `}; `; const Title = styled.div` font-size: 16px; font-weight: 600; text-align: center; justify-content: center; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; transition: opacity 100ms ease-in-out; opacity: ${props => (props.isHidden ? '0' : '1')}; cursor: ${props => (props.isHidden ? 'default' : 'pointer')}; display: none; width: 0; ${breakpoint('tablet')` display: block; flex-grow: 1; `}; `; export default inject('auth')(Header);