docbrown/app/javascript/article-form/elements/imageManagement.jsx
Mac Siri 0f3342bcec [WIP] Implement non front-matter editor (#415)
* Create alternate editor

* Install linkstate (?)

Not sure how it disappear in the first place

* Run yarn install

* Modulize ArticleForm component

* Refactor

* Isolating css WIP

* Implement simplified frontmatter-less editor

* Modulize individual form element

* Ajust props names

* Transform json params to snakecase

* Remove codes

* Update /new, almost there for release

* Fix editor resize issues

* Change defaultvalue to value in article form tag element

* Modify html buttons in article form
2018-07-27 20:12:33 -07:00

84 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { h, Component } from 'preact';
import PropTypes from 'prop-types';
import { generateMainImage } from '../actions'
// const ImageManagement = ({ onExit }) => (
export default class ImageManagement extends Component {
constructor(props) {
super(props);
this.state = {insertionImageUrl: null}
}
handleMainImageUpload = e => {
e.preventDefault();
const payload = {image: e.target.files, wrap_cloudinary: true,}
generateMainImage(payload, this.props.onMainImageUrlChange, null)
// this.props.onMainImageUrlChange(e.target.value)
}
handleInsertionImageUpload = e => {
const payload = {image: e.target.files,}
generateMainImage(payload, this.handleInertImageUploadSuccess, null)
}
handleInertImageUploadSuccess = response => {
this.setState({
insertionImageUrl: response.link,
})
}
triggerMainImageRemoval = e => {
e.preventDefault();
this.props.onMainImageUrlChange({link: null})
}
render() {
const { onExit, mainImageUrl } = this.props;
const { insertionImageUrl } = this.state;
// mainImageUrl
let mainImageArea;
if (mainImageUrl) {
mainImageArea = <div>
<img src={mainImageUrl} />
<button onClick={this.triggerMainImageRemoval}>Remove Cover Image</button>
</div>
} else {
mainImageArea = <div>
<input type="file" onChange={this.handleMainImageUpload}/>
</div>
}
let inertionImageArea;
if (insertionImageUrl) {
inertionImageArea = <div>
<h3>Markdown Image:</h3>
<input type="text" value={`![](${insertionImageUrl})`} />
<h3>Direct URL:</h3>
<input type="text" value={insertionImageUrl} />
</div>
} else {
inertionImageArea = <div>
<input type="file" onChange={this.handleInsertionImageUpload} />
</div>
}
return <div
className="articleform__imagemanagement"
>
<button
class="articleform__exitbutton"
data-content="exit"
onClick={onExit}
>×</button>
<h2>Cover Image</h2>
{mainImageArea}
<h2>Body Images</h2>
{inertionImageArea}
</div>
}
};
ImageManagement.propTypes = {
onExit: PropTypes.func.isRequired,
};
// export default ImageManagement;