import * as React from "react"; const { withSelect } = window.wp.data; import { SelectType } from "../../../typings/gutenberg"; import { ErrorText, ErrorHeading, Heading, MainHeading, BodySection } from "../styles"; import { RevisionLinks } from "./RevisionLinks"; export interface PostStatusProps { requirePublish?: boolean; actionString?: string; lastPublishedRevision?: any; lastArchivedRevision?: any; saved: boolean; published: boolean; updated: boolean; url: string; isSavingPost: boolean; pluginDataMissing: boolean; contentId?: number; } const NoMarginHeading = MainHeading.extend` margin-bottom: 0; `; class PostStatusComponent extends React.Component { public render(): JSX.Element { let content; let heading = WordPress Post Status; if (this.props.saved && this.props.pluginDataMissing) { heading = WordPress Post Status; content = ( This post was {this.props.published ? "published" : "last saved"} before the Civil plugin was activated, and so isn't fully processed. Please{" "} {this.props.published ? 're-publish by hitting the "Update" button' : "save again"} before continuing. ); } else if (this.props.published) { if (this.props.requirePublish) { content =

Your post is published to your site and is ready to be published on the Civil network.

; } else { content =

Post published.

; } } else { if (this.props.requirePublish) { heading = WordPress Post Status; content = ( Waiting for this post to be published on your WordPress site before you can publish to the Civil network. ); } else if (this.props.saved) { content =

Post saved.

; } } if (!this.props.saved && !(this.props.requirePublish && !this.props.published)) { content = ( <> {content} {this.props.isSavingPost ? ( "Saving post..." ) : ( <> Please save {this.props.published && "updates to"} this post before{" "} {this.props.actionString || "continuing"}. )} ); } if (this.props.contentId && this.props.lastPublishedRevision) { heading = Civil publish status; content = ( ); } return ( {heading} {content} ); } } export const PostStatus = withSelect( (selectStore: SelectType, ownProps: Partial): Partial => { const { getEditedPostAttribute, isEditedPostDirty, isCleanNewPost, isCurrentPostPublished, isSavingPost, hasAutosave, } = selectStore("core/editor"); const { isSavingMetaBoxes } = selectStore("core/edit-post"); const { isPluginDataMissing } = selectStore("civil/blockchain"); const pluginDataMissing = isPluginDataMissing(); const onlyAutosaved = pluginDataMissing && hasAutosave(); const savingPost = isSavingPost() || isSavingMetaBoxes(); const saved = !isEditedPostDirty() && !isCleanNewPost() && !onlyAutosaved && !savingPost; return { requirePublish: ownProps.requirePublish, saved, published: isCurrentPostPublished(), url: getEditedPostAttribute("link"), isSavingPost: savingPost, pluginDataMissing, }; }, )(PostStatusComponent);