Allow pasting images into comment boxes and post url box. Fixes #472

This commit is contained in:
Dessalines 2020-01-27 21:59:38 -05:00
parent 2e84441e66
commit e4713829df
2 changed files with 32 additions and 4 deletions

View file

@ -96,6 +96,7 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
className={`form-control ${this.state.previewMode && 'd-none'}`}
value={this.state.commentForm.content}
onInput={linkEvent(this, this.handleCommentContentChange)}
onPaste={linkEvent(this, this.handleImageUploadPaste)}
required
disabled={this.props.disabled}
rows={2}
@ -208,9 +209,22 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
i.props.onReplyCancel();
}
handleImageUploadPaste(i: CommentForm, event: any) {
let image = event.clipboardData.files[0];
if (image) {
i.handleImageUpload(i, image);
}
}
handleImageUpload(i: CommentForm, event: any) {
let file: any;
if (event.target) {
event.preventDefault();
let file = event.target.files[0];
file = event.target.files[0];
} else {
file = event;
}
const imageUploadUrl = `/pictshare/api/upload.php`;
const formData = new FormData();
formData.append('file', file);

View file

@ -160,6 +160,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
class="form-control"
value={this.state.postForm.url}
onInput={linkEvent(this, this.handlePostUrlChange)}
onPaste={linkEvent(this, this.handleImageUploadPaste)}
/>
{this.state.suggestedTitle && (
<div
@ -442,9 +443,22 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
i.setState(i.state);
}
handleImageUploadPaste(i: PostForm, event: any) {
let image = event.clipboardData.files[0];
if (image) {
i.handleImageUpload(i, image);
}
}
handleImageUpload(i: PostForm, event: any) {
let file: any;
if (event.target) {
event.preventDefault();
let file = event.target.files[0];
file = event.target.files[0];
} else {
file = event;
}
const imageUploadUrl = `/pictshare/api/upload.php`;
const formData = new FormData();
formData.append('file', file);