Skip to content

Commit

Permalink
Try to use it here and there
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Mar 31, 2022
1 parent 180f8eb commit 52d0104
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
4 changes: 2 additions & 2 deletions packages/block-library/src/post-template/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import classnames from 'classnames';
* WordPress dependencies
*/
import { memo, useMemo, useState } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { useSuspenseSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import {
BlockContextProvider,
Expand Down Expand Up @@ -87,7 +87,7 @@ export default function PostTemplateEdit( {
const [ { page } ] = queryContext;
const [ activeBlockContextId, setActiveBlockContextId ] = useState();

const { posts, blocks } = useSelect(
const { posts, blocks } = useSuspenseSelect(
( select ) => {
const { getEntityRecords, getTaxonomies } = select( coreStore );
const { getBlocks } = select( blockEditorStore );
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/site-logo/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
__experimentalImageEditor as ImageEditor,
__experimentalImageEditingProvider as ImageEditingProvider,
} from '@wordpress/block-editor';
import { useSelect, useDispatch } from '@wordpress/data';
import { useSuspenseSelect, useDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { crop, upload } from '@wordpress/icons';
import { SVG, Path } from '@wordpress/primitives';
Expand Down Expand Up @@ -80,7 +80,7 @@ const SiteLogo = ( {
const classes = classnames( 'custom-logo-link', {
'is-transient': isBlobURL( logoUrl ),
} );
const { imageEditing, maxWidth, title } = useSelect( ( select ) => {
const { imageEditing, maxWidth, title } = useSuspenseSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
const siteEntities = select( coreStore ).getEditedEntityRecord(
'root',
Expand Down Expand Up @@ -369,7 +369,7 @@ export default function LogoEdit( {
siteIconId,
mediaItemData,
isRequestingMediaItem,
} = useSelect( ( select ) => {
} = useSuspenseSelect( ( select ) => {
const { canUser, getEntityRecord, getEditedEntityRecord } = select(
coreStore
);
Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/template-part/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { isEmpty } from 'lodash';
/**
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { useSuspenseSelect } from '@wordpress/data';
import {
BlockControls,
useBlockProps,
Expand Down Expand Up @@ -56,7 +56,7 @@ export default function TemplatePartEdit( {
// Set the postId block attribute if it did not exist,
// but wait until the inner blocks have loaded to allow
// new edits to trigger this.
const { isResolved, innerBlocks, isMissing, area } = useSelect(
const { isResolved, innerBlocks, isMissing, area } = useSuspenseSelect(
( select ) => {
const { getEditedEntityRecord, hasFinishedResolution } = select(
coreStore
Expand Down
4 changes: 2 additions & 2 deletions packages/edit-site/src/components/block-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
import { useSelect, useSuspenseSelect, useDispatch } from '@wordpress/data';
import { useCallback, useRef } from '@wordpress/element';
import { useEntityBlockEditor, store as coreStore } from '@wordpress/core-data';
import {
Expand Down Expand Up @@ -48,7 +48,7 @@ const LAYOUT = {
};

export default function BlockEditor( { setIsInserterOpen } ) {
const { settings } = useSelect(
const { settings } = useSuspenseSelect(
( select ) => {
let storedSettings = select( editSiteStore ).getSettings(
setIsInserterOpen
Expand Down
43 changes: 30 additions & 13 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/**
* WordPress dependencies
*/
import { useEffect, useState, useMemo, useCallback } from '@wordpress/element';
import {
useEffect,
useState,
useMemo,
useCallback,
Suspense,
} from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { Popover, Button, Notice } from '@wordpress/components';
import { EntityProvider, store as coreStore } from '@wordpress/core-data';
Expand Down Expand Up @@ -236,18 +242,29 @@ function Editor( { onError } ) {
content={
<>
<EditorNotices />
{ editorMode === 'visual' &&
template && (
<BlockEditor
setIsInserterOpen={
setIsInserterOpened
}
/>
) }
{ editorMode === 'text' &&
template && (
<CodeEditor />
) }
<Suspense
fallback={
<h1>
Very Ugly
Loading State
</h1>
}
>
{ editorMode ===
'visual' &&
template && (
<BlockEditor
setIsInserterOpen={
setIsInserterOpened
}
/>
) }
{ editorMode ===
'text' &&
template && (
<CodeEditor />
) }
</Suspense>
{ templateResolved &&
! template &&
settings?.siteUrl &&
Expand Down

0 comments on commit 52d0104

Please sign in to comment.