Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
George Hotelling committed Oct 24, 2022
1 parent 24ddf67 commit be22d83
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 79 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { PanelBody, Button } from '@wordpress/components';
import { sprintf, _n } from '@wordpress/i18n';
import { backup } from '@wordpress/icons';
import { addQueryArgs } from '@wordpress/url';
import { PostTypeSupportCheck } from '@wordpress/editor';

/**
* Internal dependencies
*/
import { store as editSiteStore } from '../../../store';

const useRevisionData = () =>
useSelect( ( select ) => {
const {
getCurrentTemplateLastRevisionId,
getCurrentTemplateRevisionsCount,
} = select( editSiteStore );
return {
lastRevisionId: getCurrentTemplateLastRevisionId(),
revisionsCount: getCurrentTemplateRevisionsCount(),
};
} );

function PostLastRevisionCheck( { children } ) {
const { lastRevisionId, revisionsCount } = useRevisionData();

if ( ! lastRevisionId || revisionsCount < 2 ) {
return null;
}

return (
<PostTypeSupportCheck supportKeys="revisions">
{ children }
</PostTypeSupportCheck>
);
}

const PostLastRevision = () => {
const { lastRevisionId, revisionsCount } = useRevisionData();

return (
<PostLastRevisionCheck>
<Button
href={ addQueryArgs( 'revision.php', {
revision: lastRevisionId,
gutenberg: true,
} ) }
className="editor-post-last-revision__title"
icon={ backup }
>
{ sprintf(
/* translators: %d: number of revisions */
_n( '%d Revision', '%d Revisions', revisionsCount ),
revisionsCount
) }
</Button>
</PostLastRevisionCheck>
);
};

export default function LastRevision() {
return (
<PostLastRevisionCheck>
<PanelBody className="edit-post-last-revision__panel">
<PostLastRevision />
</PanelBody>
</PostLastRevisionCheck>
);
}
Original file line number Diff line number Diff line change
@@ -1,94 +1,18 @@
/**
* WordPress dependencies
*/
import { useSelect, withSelect } from '@wordpress/data';
import { Icon, PanelBody, Button } from '@wordpress/components';
import { useSelect } from '@wordpress/data';
import { Icon } from '@wordpress/components';
import { store as editorStore } from '@wordpress/editor';
import { store as coreStore } from '@wordpress/core-data';
import { sprintf, _n } from '@wordpress/i18n';
import { backup } from '@wordpress/icons';
import { addQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
*/
import { store as editSiteStore } from '../../../store';
import TemplateActions from './template-actions';
import TemplateAreas from './template-areas';
import PostTypeSupportCheck from '../../../../../editor/src/components/post-type-support-check';

/*
* TODO Refactor all of these components copied from the editor.
*/

export function _PostLastRevisionCheck( {
lastRevisionId,
revisionsCount,
children,
} ) {
if ( ! lastRevisionId || revisionsCount < 2 ) {
return null;
}

return (
<PostTypeSupportCheck supportKeys="revisions">
{ children }
</PostTypeSupportCheck>
);
}

const PostLastRevisionCheck = withSelect( ( select ) => {
const {
getCurrentTemplateLastRevisionId,
getCurrentTemplateRevisionsCount,
} = select( editSiteStore );
return {
lastRevisionId: getCurrentTemplateLastRevisionId(),
revisionsCount: getCurrentTemplateRevisionsCount(),
};
} )( _PostLastRevisionCheck );

const _PostLastRevision = ( { lastRevisionId, revisionsCount } ) => {
return (
<PostLastRevisionCheck>
<Button
href={ addQueryArgs( 'revision.php', {
revision: lastRevisionId,
gutenberg: true,
} ) }
className="editor-post-last-revision__title"
icon={ backup }
>
{ sprintf(
/* translators: %d: number of revisions */
_n( '%d Revision', '%d Revisions', revisionsCount ),
revisionsCount
) }
</Button>
</PostLastRevisionCheck>
);
};

const PostLastRevision = withSelect( ( select ) => {
const {
getCurrentTemplateLastRevisionId,
getCurrentTemplateRevisionsCount,
} = select( editSiteStore );
return {
lastRevisionId: getCurrentTemplateLastRevisionId(),
revisionsCount: getCurrentTemplateRevisionsCount(),
};
} )( _PostLastRevision );

function LastRevision() {
return (
<PostLastRevisionCheck>
<PanelBody className="edit-post-last-revision__panel">
<PostLastRevision />
</PanelBody>
</PostLastRevisionCheck>
);
}
import LastRevision from '../last-revision';

export default function TemplateCard() {
const {
Expand Down

0 comments on commit be22d83

Please sign in to comment.