Skip to content

Commit

Permalink
Added Image Removal Functionality and Styling
Browse files Browse the repository at this point in the history
  • Loading branch information
zamanq committed Feb 27, 2024
1 parent 7259d12 commit 5f579fd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
9 changes: 9 additions & 0 deletions assets/css/podcasting-editor-screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@
.components-base-control {
width: 100%;
}
.cover-art-container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.cover-art-container button {
margin: 10px 0;
}
24 changes: 19 additions & 5 deletions assets/js/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ function useFeaturedImage() {
editPost({ featured_media: imageId });
};

return { featuredImageUrl, setFeaturedImage };
const removeFeaturedImage = () => {
editPost({ featured_media: 0 });
};

return { featuredImageUrl, setFeaturedImage, removeFeaturedImage };
}

class Edit extends Component {
Expand All @@ -74,7 +78,8 @@ class Edit extends Component {
isSelected,
attributes,
featuredImageUrl,
setFeaturedImage
setFeaturedImage,
removeFeaturedImage
} = this.props;
const { caption, explicit } = attributes;
const duration = attributes.duration || '';
Expand Down Expand Up @@ -304,20 +309,29 @@ class Edit extends Component {
</PanelRow>
<h3 style={{marginTop: '20px'}}>{__('Cover Image', 'simple-podcasting')}</h3>
<p>{__('The featured image of the current post is used as the episode cover art. Please select a featured image to set it.', 'simple-podcasting')}</p>
<PanelRow>
<PanelRow className="cover-art-container">
{featuredImageUrl && (
<img src={featuredImageUrl} alt="Cover Image" />
)}

<MediaUploadCheck>
<MediaUpload
onSelect={onUpdateImage}
allowedTypes={['image/gif']}
allowedTypes={['image']}
render={({ open }) => (
<Button onClick={open}>{__('Select Cover Art', 'simple-podcasting')}</Button>
<Button isSecondary onClick={open}>
{featuredImageUrl ?
__('Replace Cover Art', 'simple-podcasting')
:
__('Select Cover Art', 'simple-podcasting')
}
</Button>
)}
/>
</MediaUploadCheck>
{featuredImageUrl && (
<Button isLink isDestructive onClick={removeFeaturedImage}>{__('Delete Cover Art', 'simple-podcasting')}</Button>
)}
</PanelRow>
</PanelBody>
</InspectorControls>
Expand Down

0 comments on commit 5f579fd

Please sign in to comment.