From c39ae06bd4bb553649a015f3d104440f1584402d Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 7 Sep 2019 20:42:01 -0700 Subject: Allow Image uploads through docker pictshare. - Fixes #210 --- ui/src/components/comment-form.tsx | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'ui/src/components/comment-form.tsx') diff --git a/ui/src/components/comment-form.tsx b/ui/src/components/comment-form.tsx index e18a6e3f..837cefb5 100644 --- a/ui/src/components/comment-form.tsx +++ b/ui/src/components/comment-form.tsx @@ -136,7 +136,10 @@ export class CommentForm extends Component { } {this.props.node && } # - # +
+ + +
@@ -154,8 +157,8 @@ export class CommentForm extends Component { i.state.previewMode = false; i.state.commentForm.content = undefined; - i.setState(i.state); event.target.reset(); + i.setState(i.state); if (i.props.node) { i.props.onReplyCancel(); } @@ -177,6 +180,28 @@ export class CommentForm extends Component { handleReplyCancel(i: CommentForm) { i.props.onReplyCancel(); } + + handleImageUpload(i: CommentForm, event: any) { + event.preventDefault(); + let file = event.target.files[0]; + const imageUploadUrl = `/pictshare/api/upload.php`; + const formData = new FormData(); + formData.append('file', file); + fetch(imageUploadUrl, { + method: 'POST', + body: formData, + }) + .then(res => res.json()) + .then(res => { + let url = `${window.location.origin}/pictshare/${res.url}`; + let markdown = (res.filetype == 'mp4') ? `[vid](${url}/raw)` : `![](${url})`; + let content = i.state.commentForm.content; + content = (content) ? `${content} ${markdown}` : markdown; + i.state.commentForm.content = content; + i.setState(i.state); + }) + .catch((error) => alert(error)); + } userSearch(text: string, cb: any) { if (text) { -- cgit v1.2.3