forked from nutomic/lemmy
Allow pasting images into comment boxes and post url box. Fixes #472
This commit is contained in:
parent
e7c90bee01
commit
beb55a471f
2 changed files with 32 additions and 4 deletions
18
ui/src/components/comment-form.tsx
vendored
18
ui/src/components/comment-form.tsx
vendored
|
@ -96,6 +96,7 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
|
||||||
className={`form-control ${this.state.previewMode && 'd-none'}`}
|
className={`form-control ${this.state.previewMode && 'd-none'}`}
|
||||||
value={this.state.commentForm.content}
|
value={this.state.commentForm.content}
|
||||||
onInput={linkEvent(this, this.handleCommentContentChange)}
|
onInput={linkEvent(this, this.handleCommentContentChange)}
|
||||||
|
onPaste={linkEvent(this, this.handleImageUploadPaste)}
|
||||||
required
|
required
|
||||||
disabled={this.props.disabled}
|
disabled={this.props.disabled}
|
||||||
rows={2}
|
rows={2}
|
||||||
|
@ -208,9 +209,22 @@ export class CommentForm extends Component<CommentFormProps, CommentFormState> {
|
||||||
i.props.onReplyCancel();
|
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) {
|
handleImageUpload(i: CommentForm, event: any) {
|
||||||
event.preventDefault();
|
let file: any;
|
||||||
let file = event.target.files[0];
|
if (event.target) {
|
||||||
|
event.preventDefault();
|
||||||
|
file = event.target.files[0];
|
||||||
|
} else {
|
||||||
|
file = event;
|
||||||
|
}
|
||||||
|
|
||||||
const imageUploadUrl = `/pictshare/api/upload.php`;
|
const imageUploadUrl = `/pictshare/api/upload.php`;
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
|
|
18
ui/src/components/post-form.tsx
vendored
18
ui/src/components/post-form.tsx
vendored
|
@ -160,6 +160,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
class="form-control"
|
class="form-control"
|
||||||
value={this.state.postForm.url}
|
value={this.state.postForm.url}
|
||||||
onInput={linkEvent(this, this.handlePostUrlChange)}
|
onInput={linkEvent(this, this.handlePostUrlChange)}
|
||||||
|
onPaste={linkEvent(this, this.handleImageUploadPaste)}
|
||||||
/>
|
/>
|
||||||
{this.state.suggestedTitle && (
|
{this.state.suggestedTitle && (
|
||||||
<div
|
<div
|
||||||
|
@ -442,9 +443,22 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
|
||||||
i.setState(i.state);
|
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) {
|
handleImageUpload(i: PostForm, event: any) {
|
||||||
event.preventDefault();
|
let file: any;
|
||||||
let file = event.target.files[0];
|
if (event.target) {
|
||||||
|
event.preventDefault();
|
||||||
|
file = event.target.files[0];
|
||||||
|
} else {
|
||||||
|
file = event;
|
||||||
|
}
|
||||||
|
|
||||||
const imageUploadUrl = `/pictshare/api/upload.php`;
|
const imageUploadUrl = `/pictshare/api/upload.php`;
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
formData.append('file', file);
|
formData.append('file', file);
|
||||||
|
|
Loading…
Reference in a new issue