Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FSE: Move initial template fetch to client #23186

Merged
merged 2 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions lib/edit-site-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,8 @@ function gutenberg_edit_site_init( $hook ) {
}
}

$current_template_id = $template_ids['front-page'];

$settings['editSiteInitialState'] = array();

$settings['editSiteInitialState']['homeTemplateId'] = $current_template_id;
$settings['editSiteInitialState']['templateId'] = $current_template_id;
$settings['editSiteInitialState']['templateType'] = 'wp_template';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can also get rid of all of these except for showOnFront unless that is already in the site entity.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool. I'll look into removing these in a follow-up :)

$settings['editSiteInitialState']['templateIds'] = array_values( $template_ids );
$settings['editSiteInitialState']['templatePartIds'] = array_values( $template_part_ids );
Expand All @@ -192,7 +188,6 @@ function gutenberg_edit_site_init( $hook ) {
'/wp/v2/taxonomies?per_page=100&context=edit',
'/wp/v2/pages?per_page=100&context=edit',
'/wp/v2/themes?status=active',
sprintf( '/wp/v2/templates/%s?context=edit', $current_template_id ),
array( '/wp/v2/media', 'OPTIONS' ),
);
$preload_data = array_reduce(
Expand Down
6 changes: 3 additions & 3 deletions lib/template-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function gutenberg_add_template_loader_filters() {
* @param string $template_type A template type.
* @return string[] A list of template candidates, in descending order of priority.
*/
function get_template_hierachy( $template_type ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😅

function get_template_hierarchy( $template_type ) {
if ( ! in_array( $template_type, get_template_types(), true ) ) {
return array();
}
Expand Down Expand Up @@ -220,9 +220,9 @@ function gutenberg_find_template_post_and_parts( $template_type, $template_hiera

if ( empty( $template_hierarchy ) ) {
if ( 'index' === $template_type ) {
$template_hierarchy = get_template_hierachy( 'index' );
$template_hierarchy = get_template_hierarchy( 'index' );
} else {
$template_hierarchy = array_merge( get_template_hierachy( $template_type ), get_template_hierachy( 'index' ) );
$template_hierarchy = array_merge( get_template_hierarchy( $template_type ), get_template_hierarchy( 'index' ) );
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function Editor() {
} ),
[ page.context ]
);
return template ? (
return (
<>
<EditorStyles styles={ settings.styles } />
<FullscreenMode isActive={ isFullscreenActive } />
Expand Down Expand Up @@ -223,7 +223,7 @@ function Editor() {
>
<Notices />
<Popover.Slot name="block-toolbar" />
<BlockEditor />
{ template && <BlockEditor /> }
<KeyboardShortcuts />
</BlockSelectionClearer>
}
Expand Down Expand Up @@ -268,6 +268,6 @@ function Editor() {
</DropZoneProvider>
</SlotFillProvider>
</>
) : null;
);
}
export default Editor;
7 changes: 6 additions & 1 deletion packages/edit-site/src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ import controls from './controls';
import { STORE_KEY } from './constants';

export default function registerEditSiteStore( initialState ) {
return registerStore( STORE_KEY, {
const store = registerStore( STORE_KEY, {
reducer,
actions,
selectors,
controls: { ...dataControls, ...controls },
persist: [ 'preferences' ],
initialState,
} );

// We set the initial page here to include the template fetch which will
// resolve the correct homepage template.
store.dispatch( actions.setPage( initialState.page ) );
return store;
}