Skip to content

Commit

Permalink
DataViews: add new page button in Pages page (#57685)
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Jan 10, 2024
1 parent 5dcd9d1 commit 66879a5
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {
__experimentalView as View,
__experimentalVStack as VStack,
Button,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useEntityRecords, store as coreStore } from '@wordpress/core-data';
Expand Down Expand Up @@ -42,6 +43,7 @@ import {
useEditPostAction,
} from '../actions';
import PostPreview from '../post-preview';
import AddNewPageModal from '../add-new-page';
import Media from '../media';
import { unlock } from '../../lock-unlock';
const { useLocation, useHistory } = unlock( routerPrivateApis );
Expand Down Expand Up @@ -323,6 +325,29 @@ export default function PagePages() {
[ view.type, setView ]
);

const [ showAddPageModal, setShowAddPageModal ] = useState( false );
const openModal = useCallback( () => {
if ( ! showAddPageModal ) {
setShowAddPageModal( true );
}
}, [ showAddPageModal ] );
const closeModal = useCallback( () => {
if ( showAddPageModal ) {
setShowAddPageModal( false );
}
}, [ showAddPageModal ] );
const handleNewPage = useCallback(
( { type, id } ) => {
history.push( {
postId: id,
postType: type,
canvas: 'edit',
} );
closeModal();
},
[ history ]
);

// TODO: we need to handle properly `data={ data || EMPTY_ARRAY }` for when `isLoading`.
return (
<>
Expand All @@ -333,6 +358,19 @@ export default function PagePages() {
: null
}
title={ __( 'Pages' ) }
actions={
<>
<Button variant="primary" onClick={ openModal }>
{ __( 'Add new page' ) }
</Button>
{ showAddPageModal && (
<AddNewPageModal
onSave={ handleNewPage }
onClose={ closeModal }
/>
) }
</>
}
>
<DataViews
paginationInfo={ paginationInfo }
Expand Down

0 comments on commit 66879a5

Please sign in to comment.