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] Prevent "Undo Level" after Setting Featured Image via Image Block #33057

Merged
merged 19 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 15 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
28 changes: 19 additions & 9 deletions packages/block-library/src/image/edit.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
BottomSheet,
BottomSheetTextControl,
BottomSheetSelectControl,
FooterMessageControl,
FooterMessageLink,
Badge,
} from '@wordpress/components';
Expand Down Expand Up @@ -460,6 +461,7 @@ export class ImageEdit extends Component {
setFeaturedButtonStyle,
styles.removeFeaturedButton,
] }
cellContainerStyle={ styles.setFeaturedCellContainer }
onPress={ () =>
this.onSetFeatured( MEDIA_ID_NO_FEATURED_IMAGE_SET )
}
Expand All @@ -470,17 +472,12 @@ export class ImageEdit extends Component {
<BottomSheet.Cell
label={ __( 'Set as Featured Image ' ) }
labelStyle={ setFeaturedButtonStyle }
cellContainerStyle={ styles.setFeaturedCellContainer }
onPress={ () => this.onSetFeatured( attributes.id ) }
/>
);

return (
<PanelBody>
{ isFeaturedImage
? removeFeaturedButton()
: setFeaturedButton() }
</PanelBody>
);
return isFeaturedImage ? removeFeaturedButton() : setFeaturedButton();
}

render() {
Expand Down Expand Up @@ -564,8 +561,21 @@ export class ImageEdit extends Component {
<PanelBody title={ __( 'Link Settings' ) }>
{ this.getLinkSettings( true ) }
</PanelBody>
{ canImageBeFeatured &&
this.getFeaturedButtonPanel( isFeaturedImage ) }
<PanelBody
title={ __( 'Featured Image' ) }
titleStyle={ styles.featuredImagePanelTitle }
>
{ canImageBeFeatured &&
this.getSetFeaturedButton( isFeaturedImage ) }
fluiddot marked this conversation as resolved.
Show resolved Hide resolved
</PanelBody>
<PanelBody>
<FooterMessageControl
label={ __(
'Changes to featured image will not be affected by the undo/redo buttons.'
) }
cellContainerStyle={ styles.setFeaturedCellContainer }
/>
</PanelBody>
</InspectorControls>
);

Expand Down
15 changes: 10 additions & 5 deletions packages/block-library/src/image/styles.native.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,21 @@
padding-bottom: $grid-unit;
}

.featuredImagePanelTitle {
padding-bottom: 0;
}

.setFeaturedCellContainer {
fluiddot marked this conversation as resolved.
Show resolved Hide resolved
align-items: flex-start;
}

.setFeaturedButton {
border-top-width: $border-width;
border-top-color: $light-gray-400;
padding: $grid-unit-20;
text-align: center;
text-align: left;
color: $blue-50;
padding: $grid-unit-15 0;
}

.setFeaturedButtonDark {
border-top-color: $gray-70;
color: $blue-30;
}

Expand Down
6 changes: 4 additions & 2 deletions packages/components/src/panel/body.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import { Text, View } from 'react-native';
import styles from './body.scss';
import BottomSeparatorCover from './bottom-separator-cover';

export function PanelBody( { children, title, style = {} } ) {
export function PanelBody( { children, title, style, titleStyle = {} } ) {
return (
<View style={ [ styles.panelContainer, style ] }>
{ title && (
<Text style={ styles.sectionHeaderText }>{ title }</Text>
<Text style={ [ styles.sectionHeaderText, titleStyle ] }>
{ title }
</Text>
) }
{ children }
<BottomSeparatorCover />
Expand Down
12 changes: 9 additions & 3 deletions packages/edit-post/src/editor.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,15 @@ class Editor extends Component {

this.subscriptionParentFeaturedImageIdNativeUpdated = subscribeFeaturedImageIdNativeUpdated(
( payload ) => {
editEntityRecord( 'postType', postType, postId, {
featured_media: payload.featuredImageId,
} );
editEntityRecord(
'postType',
postType,
postId,
{ featured_media: payload.featuredImageId },
{
undoIgnore: true,
}
);
}
);
}
Expand Down