Skip to content
Merged
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ import {
import { ToolbarGroup, ToolbarButton } from '@wordpress/components';
import {
keyboardClose,
audio as audioIcon,
media as imageIcon,
video as videoIcon,
gallery as galleryIcon,
undo as undoIcon,
redo as redoIcon,
} from '@wordpress/icons';
import { store as editorStore } from '@wordpress/editor';
import { createBlock } from '@wordpress/blocks';

/**
* Internal dependencies
Expand All @@ -38,6 +43,7 @@ function HeaderToolbar( {
showInserter,
showKeyboardHideButton,
getStylesFromColorScheme,
insertBlocks,
onHideKeyboard,
isRTL,
noContentSelected,
Expand All @@ -55,6 +61,7 @@ function HeaderToolbar( {
scrollViewRef.current.scrollTo( { x: 0 } );
}
};

const renderHistoryButtons = () => {
const buttons = [
/* TODO: replace with EditorHistoryRedo and EditorHistoryUndo. */
Expand Down Expand Up @@ -83,6 +90,53 @@ function HeaderToolbar( {
return isRTL ? buttons.reverse() : buttons;
};

function onInsertBlock( blockType ) {
insertBlocks( [ createBlock( blockType ) ] );
}

const renderMediaButtons = () => {
const buttons = [
<ToolbarButton
key="imageButton"
title={ __( 'Image' ) }
icon={ imageIcon }
onClick={ () => onInsertBlock( 'core/image' ) }
extraProps={ {
hint: __( 'Insert Image Block' ),
} }
/>,
<ToolbarButton
key="videoButton"
title={ __( 'Video' ) }
icon={ videoIcon }
onClick={ () => onInsertBlock( 'core/video' ) }
extraProps={ {
hint: __( 'Insert Video Block' ),
} }
/>,
<ToolbarButton
key="galleryButton"
title={ __( 'Gallery' ) }
icon={ galleryIcon }
onClick={ () => onInsertBlock( 'core/gallery' ) }
extraProps={ {
hint: __( 'Insert Gallery Block' ),
} }
/>,
<ToolbarButton
key="audioButton"
title={ __( 'Audio' ) }
icon={ audioIcon }
onClick={ () => onInsertBlock( 'core/audio' ) }
extraProps={ {
hint: __( 'Insert Audio Block' ),
} }
/>,
];

return buttons;
};

const onToggleInserter = useCallback(
( isOpen ) => {
if ( isOpen ) {
Expand Down Expand Up @@ -131,6 +185,7 @@ function HeaderToolbar( {
useExpandedMode={ useExpandedMode }
onToggle={ onToggleInserter }
/>
{ noContentSelected && renderMediaButtons() }
{ renderHistoryButtons() }
<BlockToolbar />
</ScrollView>
Expand Down Expand Up @@ -181,7 +236,8 @@ export default compose( [
};
} ),
withDispatch( ( dispatch ) => {
const { clearSelectedBlock } = dispatch( blockEditorStore );
const { clearSelectedBlock, insertBlocks } =
dispatch( blockEditorStore );
const { togglePostTitleSelection } = dispatch( editorStore );

return {
Expand All @@ -191,6 +247,7 @@ export default compose( [
clearSelectedBlock();
togglePostTitleSelection( false );
},
insertBlocks,
};
} ),
withViewportMatch( { isLargeViewport: 'medium' } ),
Expand Down