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

[RNMobile] Add media inserter blocks to toolbar #51827

Merged
merged 18 commits into from
Jul 6, 2023
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 ) {
derekblank marked this conversation as resolved.
Show resolved Hide resolved
insertBlocks( [ createBlock( blockType ) ] );
}

const renderMediaButtons = () => {
derekblank marked this conversation as resolved.
Show resolved Hide resolved
const buttons = [
<ToolbarButton
key="imageButton"
title={ __( 'Image' ) }
icon={ imageIcon }
onClick={ () => onInsertBlock( 'core/image' ) }
derekblank marked this conversation as resolved.
Show resolved Hide resolved
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