+export const ImageCard = ({
+ image,
+ siteName,
+ onClick,
+ isSelected,
+}) => (
+
@@ -27,13 +34,27 @@ export const ImageCard = ({ image, siteName, onClick }) => (
export default class ImagesModal extends PureComponent {
render() {
- const { siteName, images, onClose, onImageSelect, readImageToUpload } = this.props;
+ const {
+ siteName,
+ images,
+ onClose,
+ onImageSelect,
+ readImageToUpload,
+ selectedImage,
+ setSelectedImage,
+ } = this.props;
return (!!images.length
&& (
)
);
- };
+ }
}
ImageCard.propTypes = {
@@ -74,10 +100,18 @@ ImageCard.propTypes = {
}).isRequired,
siteName: PropTypes.string.isRequired,
onClick: PropTypes.func.isRequired,
+ isSelected: PropTypes.bool.isRequired,
};
ImagesModal.propTypes = {
+ images: PropTypes.arrayOf(PropTypes.shape({
+ fileName: PropTypes.string,
+ path: PropTypes.string,
+ })).isRequired,
onClose: PropTypes.func.isRequired,
siteName: PropTypes.string.isRequired,
onImageSelect: PropTypes.func.isRequired,
+ readImageToUpload: PropTypes.func.isRequired,
+ selectedImage: PropTypes.string.isRequired,
+ setSelectedImage: PropTypes.func.isRequired,
};
diff --git a/src/layouts/EditPage.jsx b/src/layouts/EditPage.jsx
index 2bb2355cb..7ae93eb3d 100644
--- a/src/layouts/EditPage.jsx
+++ b/src/layouts/EditPage.jsx
@@ -43,6 +43,7 @@ export default class EditPage extends Component {
images: [],
isSelectingImage: false,
pendingImageUpload: null,
+ selectedImage: '',
};
this.mdeRef = React.createRef();
}
@@ -129,8 +130,9 @@ export default class EditPage extends Component {
}));
}
- onImageClick = (filePath) => {
- const path = `/${filePath}`;
+ onImageClick = () => {
+ const { selectedImage } = this.state;
+ const path = `/${selectedImage}`;
const cm = this.mdeRef.current.simpleMde.codemirror;
cm.replaceSelection(`![](${path})`);
// set state so that rerender is triggered and image is shown
@@ -170,10 +172,21 @@ export default class EditPage extends Component {
imgReader.readAsDataURL(event.target.files[0]);
}
+ setSelectedImage = async (filePath) => {
+ this.setState({ selectedImage: filePath });
+ }
+
render() {
const { match } = this.props;
const { siteName, fileName } = match.params;
- const { editorValue, canShowDeleteWarningModal, images, isSelectingImage, pendingImageUpload } = this.state;
+ const {
+ editorValue,
+ canShowDeleteWarningModal,
+ images,
+ isSelectingImage,
+ pendingImageUpload,
+ selectedImage,
+ } = this.state;
return (
<>
this.setState({ isSelectingImage: false })}
+ onClose={() => this.setState({ isSelectingImage: false, selectedImage: '' })}
images={images}
- onImageSelect={this.onImageClick}
+ onImageSelect={() => {
+ this.onImageClick();
+ this.setState({ selectedImage: '' });
+ }}
readImageToUpload={this.readImageToUpload}
+ selectedImage={selectedImage}
+ setSelectedImage={this.setSelectedImage}
/>
)}
@@ -213,7 +231,7 @@ export default class EditPage extends Component {
name: 'image',
action: async () => {
await this.getImages(siteName);
- this.setState({ isSelectingImage: true })
+ this.setState({ isSelectingImage: true });
},
className: 'fa fa-picture-o',
title: 'Insert Image',
@@ -227,7 +245,10 @@ export default class EditPage extends Component {
/>
-
+
diff --git a/src/layouts/Images.jsx b/src/layouts/Images.jsx
index 451628443..a49b0f6f5 100644
--- a/src/layouts/Images.jsx
+++ b/src/layouts/Images.jsx
@@ -122,6 +122,10 @@ export default class Images extends Component {
/>
{
+ // eslint-disable-next-line no-param-reassign
+ event.target.value = '';
+ }}
type="file"
id="file-upload"
accept="image/png, image/jpeg, image/gif"
diff --git a/src/styles/isomer-cms/pages/Media.module.scss b/src/styles/isomer-cms/pages/Media.module.scss
index f524cbac9..39680748d 100644
--- a/src/styles/isomer-cms/pages/Media.module.scss
+++ b/src/styles/isomer-cms/pages/Media.module.scss
@@ -35,6 +35,10 @@
overflow-y: scroll;
padding-bottom: 50px;
+ .selectedMediaCard{
+ outline: 2px solid $isomer-blue;
+ @extend .mediaCard;
+ }
.mediaCard{
@include single-site;