Skip to content
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: 3 additions & 2 deletions packages/block-library/src/gallery/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,11 @@ function GalleryEdit( props ) {
}, [ linkTo ] );

const hasImages = !! images.length;
const hasImageIds = hasImages && images.some( ( image ) => !! image.id );

const mediaPlaceholder = (
<MediaPlaceholder
addToGallery={ hasImages }
addToGallery={ hasImageIds }
isAppender={ hasImages }
disableMediaButtons={ hasImages && ! isSelected }
icon={ ! hasImages && sharedIcon }
Expand All @@ -337,7 +338,7 @@ function GalleryEdit( props ) {
accept="image/*"
allowedTypes={ ALLOWED_MEDIA_TYPES }
multiple
value={ images }
value={ hasImageIds ? images : {} }
onError={ onUploadError }
notices={ hasImages ? undefined : noticeUI }
onFocus={ onFocus }
Expand Down
7 changes: 3 additions & 4 deletions packages/editor/src/components/post-author/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* WordPress dependencies
*/
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand All @@ -13,10 +14,8 @@ const minimumUsersForCombobox = 25;

function PostAuthor() {
const showCombobox = useSelect( ( select ) => {
const authors = select( 'core' ).getUsers( {
who: 'authors',
per_page: minimumUsersForCombobox + 1,
} );
// Not using `getUsers()` because it requires `list_users` capability.
const authors = select( coreStore ).getAuthors();
return authors?.length >= minimumUsersForCombobox;
}, [] );

Expand Down
18 changes: 3 additions & 15 deletions packages/editor/src/components/post-text-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ import Textarea from 'react-autosize-textarea';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useState, useEffect } from '@wordpress/element';
import { useState } from '@wordpress/element';
import { parse } from '@wordpress/blocks';
import { useDispatch, useSelect } from '@wordpress/data';
import { useInstanceId } from '@wordpress/compose';
import { VisuallyHidden } from '@wordpress/components';

export const DEBOUNCE_TIME = 300;
export default function PostTextEditor() {
const postContent = useSelect(
( select ) => select( 'core/editor' ).getEditedPostContent(),
Expand All @@ -30,18 +29,6 @@ export default function PostTextEditor() {
setValue( postContent );
}

const saveText = () => {
const blocks = parse( value );
resetEditorBlocks( blocks );
};

useEffect( () => {
const timeoutId = setTimeout( saveText, DEBOUNCE_TIME );
return () => {
clearTimeout( timeoutId );
};
}, [ value ] );

/**
* Handles a textarea change event to notify the onChange prop callback and
* reflect the new value in the component's own state. This marks the start
Expand All @@ -67,7 +54,8 @@ export default function PostTextEditor() {
*/
const stopEditing = () => {
if ( isDirty ) {
saveText();
const blocks = parse( value );
resetEditorBlocks( blocks );
setIsDirty( false );
}
};
Expand Down
24 changes: 2 additions & 22 deletions packages/editor/src/components/post-text-editor/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import Textarea from 'react-autosize-textarea';
/**
* WordPress dependencies
*/
import * as wp from '@wordpress/data';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import PostTextEditor, { DEBOUNCE_TIME } from '../';
import PostTextEditor from '../';

const useSelect = wp.useSelect;
// "Downgrade" ReactAutosizeTextarea to a regular textarea. Assumes aligned
// props interface.
jest.mock( 'react-autosize-textarea', () => ( props ) => (
Expand Down Expand Up @@ -176,23 +175,4 @@ describe( 'PostTextEditor', () => {

expect( textarea.props.value ).toBe( 'Goodbye World' );
} );
it( 'debounce value update after given time', () => {
let wrapper;
act( () => {
wrapper = create( <PostTextEditor /> );
} );
const mockDispatchFn = jest.fn();
jest.mock( '@wordpress/data/src/components/use-dispatch', () => ( {
useDispatch: () => ( {
editPost: jest.fn(),
resetEditorBlocks: mockDispatchFn,
} ),
} ) );

const textarea = wrapper.root.findByType( Textarea );
act( () => textarea.props.onChange( { target: { value: 'text' } } ) );
setTimeout( () => {
expect( mockDispatchFn ).toHaveBeenCalled();
}, DEBOUNCE_TIME );
} );
} );