// @flow import { inject, observer } from "mobx-react"; import * as React from "react"; import { Link } from "react-router-dom"; import styled from "styled-components"; import AuthStore from "stores/AuthStore"; import CollectionsStore from "stores/CollectionsStore"; import Document from "models/Document"; import Breadcrumb from "components/Breadcrumb"; import Flex from "components/Flex"; import Time from "components/Time"; const Container = styled(Flex)` color: ${(props) => props.theme.textTertiary}; font-size: 13px; white-space: nowrap; overflow: hidden; `; const Modified = styled.span` color: ${(props) => props.theme.textTertiary}; font-weight: ${(props) => (props.highlight ? "600" : "400")}; `; type Props = { collections: CollectionsStore, auth: AuthStore, showCollection?: boolean, showPublished?: boolean, showLastViewed?: boolean, document: Document, children: React.Node, to?: string, }; function DocumentMeta({ auth, collections, showPublished, showCollection, showLastViewed, document, children, to, ...rest }: Props) { const { modifiedSinceViewed, updatedAt, updatedBy, createdAt, publishedAt, archivedAt, deletedAt, isDraft, lastViewedAt, } = document; // Prevent meta information from displaying if updatedBy is not available. // Currently the situation where this is true is rendering share links. if (!updatedBy) { return null; } let content; if (deletedAt) { content = ( deleted ); } else if (archivedAt) { content = ( archived ); } else if (createdAt === updatedAt) { content = ( created ); } else if (publishedAt && (publishedAt === updatedAt || showPublished)) { content = ( published ); } else if (isDraft) { content = ( saved ); } else { content = ( updated ); } const collection = collections.get(document.collectionId); const updatedByMe = auth.user && auth.user.id === updatedBy.id; const timeSinceNow = () => { if (isDraft || !showLastViewed) { return null; } if (!lastViewedAt) { return ( <> • Never viewed ); } return ( • Viewed ); }; return ( {updatedByMe ? "You" : updatedBy.name}  {to ? {content} : content} {showCollection && collection && (  in  )}  {timeSinceNow()} {children} ); } export default inject("collections", "auth")(observer(DocumentMeta));