summaryrefslogtreecommitdiffstats
path: root/ui/src/components/comment-form.tsx
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-01-27 21:59:38 -0500
committerDessalines <tyhou13@gmx.com>2020-01-27 21:59:38 -0500
commite4713829dfd7f3a3470abc35209e1975fb9b8a70 (patch)
tree8921ee823b56e04d94847037cb573c5f09ca142e /ui/src/components/comment-form.tsx
parent2e84441e6635b42065ef646238a6c95aea207548 (diff)
Allow pasting images into comment boxes and post url box. Fixes #472
Diffstat (limited to 'ui/src/components/comment-form.tsx')
-rw-r--r--ui/src/components/comment-form.tsx18
1 files changed, 16 insertions, 2 deletions
diff --git a/ui/src/components/comment-form.tsx b/ui/src/components/comment-form.tsx
index e4543d66..7eb30f50 100644
--- a/ui/src/components/comment-form.tsx
+++ b/ui/src/components/comment-form.tsx
@@ -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) {
- event.preventDefault();
- let file = event.target.files[0];
+ let file: any;
+ if (event.target) {
+ event.preventDefault();
+ file = event.target.files[0];
+ } else {
+ file = event;
+ }
+
const imageUploadUrl = `/pictshare/api/upload.php`;
const formData = new FormData();
formData.append('file', file);