Skip to content

Commit

Permalink
FSE: Move initial template fetch to client (#23186)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahtallen authored Jun 16, 2020
1 parent 8258f40 commit bd46c6f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
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';
$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 ) {
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;
}

0 comments on commit bd46c6f

Please sign in to comment.