Skip to content

Commit

Permalink
Update: Move template actions to the editor store.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Apr 4, 2024
1 parent 01545b4 commit 826b965
Show file tree
Hide file tree
Showing 12 changed files with 620 additions and 563 deletions.
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ function FeaturedImage( { item, viewType } ) {
);
}

const PAGE_ACTIONS = [
'edit-post',
'view-post',
'restore',
'permanently-delete',
'view-post-revisions',
'rename-post',
'move-to-trash',
];

export default function PagePages() {
const postType = 'page';
const [ view, setView ] = useView( postType );
Expand Down Expand Up @@ -353,7 +363,7 @@ export default function PagePages() {
},
[ history ]
);
const actions = usePostActions( onActionPerformed );
const actions = usePostActions( onActionPerformed, PAGE_ACTIONS );
const onChangeView = useCallback(
( newView ) => {
if ( newView.type !== view.type ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useState } from '@wordpress/element';
import { store as noticesStore } from '@wordpress/notices';
import { decodeEntities } from '@wordpress/html-entities';
import { store as reusableBlocksStore } from '@wordpress/reusable-blocks';
import { store as editorStore } from '@wordpress/editor';
import { privateApis as routerPrivateApis } from '@wordpress/router';
import { privateApis as patternsPrivateApis } from '@wordpress/patterns';

Expand Down Expand Up @@ -198,7 +199,7 @@ export const deleteAction = {
useDispatch( reusableBlocksStore );
const { createErrorNotice, createSuccessNotice } =
useDispatch( noticesStore );
const { removeTemplates } = unlock( useDispatch( editSiteStore ) );
const { removeTemplates } = unlock( useDispatch( editorStore ) );

const deletePattern = async () => {
const promiseResult = await Promise.allSettled(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ import {
LAYOUT_TABLE,
LAYOUT_LIST,
} from '../../utils/constants';
import {
resetTemplateAction,
deleteTemplateAction,
renameTemplateAction,
} from './actions';

import usePatternSettings from '../page-patterns/use-pattern-settings';
import { unlock } from '../../lock-unlock';
import AddNewTemplatePart from './add-new-template-part';
Expand Down Expand Up @@ -194,6 +190,14 @@ function Preview( { item, viewType } ) {
);
}

const TEMPLATE_ACTIONS = [
'edit-post',
'reset-template',
'rename-template',
'view-post-revisions',
'delete-template',
];

export default function PageTemplatesTemplateParts( { postType } ) {
const { params } = useLocation();
const { activeView = 'all', layout } = params;
Expand Down Expand Up @@ -354,20 +358,8 @@ export default function PageTemplatesTemplateParts( { postType } ) {
},
[ history ]
);
const [ editAction, viewRevisionsAction ] = usePostActions(
onActionPerformed,
[ 'edit-post', 'view-post-revisions' ]
);
const actions = useMemo(
() => [
editAction,
resetTemplateAction,
renameTemplateAction,
viewRevisionsAction,
deleteTemplateAction,
],
[ editAction, viewRevisionsAction ]
);

const actions = usePostActions( onActionPerformed, TEMPLATE_ACTIONS );

const onChangeView = useCallback(
( newView ) => {
Expand Down
Loading

0 comments on commit 826b965

Please sign in to comment.