summaryrefslogtreecommitdiffstats
path: root/ui/src/components/post-form.tsx
diff options
context:
space:
mode:
authorDessalines <tyhou13@gmx.com>2020-06-23 21:11:38 -0400
committerDessalines <tyhou13@gmx.com>2020-06-23 21:11:38 -0400
commitdc94e58cbf7e7de10d97331a3056380a3416e0b0 (patch)
tree85ed25783b0470ead3012a9718aea50b39c940dd /ui/src/components/post-form.tsx
parentfd6a040568239d2e6949394fdc0ce0f7ac70275c (diff)
parent790b944031f9433be765936763d848ffa6e1b496 (diff)
Merge branch 'master' into federation_merge_from_master_2
Diffstat (limited to 'ui/src/components/post-form.tsx')
-rw-r--r--ui/src/components/post-form.tsx42
1 files changed, 32 insertions, 10 deletions
diff --git a/ui/src/components/post-form.tsx b/ui/src/components/post-form.tsx
index 22224c34..9f5aa363 100644
--- a/ui/src/components/post-form.tsx
+++ b/ui/src/components/post-form.tsx
@@ -36,6 +36,7 @@ import {
setupTippy,
emojiPicker,
hostname,
+ pictrsDeleteToast,
} from '../utils';
import autosize from 'autosize';
import Tribute from 'tributejs/src/Tribute.js';
@@ -284,7 +285,7 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
/>
{this.state.previewMode && (
<div
- className="md-div"
+ className="card card-body md-div"
dangerouslySetInnerHTML={mdToHtml(this.state.postForm.body)}
/>
)}
@@ -364,7 +365,9 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
<div class="form-group row">
<div class="col-sm-10">
<button
- disabled={!this.state.postForm.community_id}
+ disabled={
+ !this.state.postForm.community_id || this.state.loading
+ }
type="submit"
class="btn btn-secondary mr-2"
>
@@ -410,6 +413,12 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
handlePostSubmit(i: PostForm, event: any) {
event.preventDefault();
+
+ // Coerce empty url string to undefined
+ if (i.state.postForm.url && i.state.postForm.url === '') {
+ i.state.postForm.url = undefined;
+ }
+
if (i.props.post) {
WebSocketService.Instance.editPost(i.state.postForm);
} else {
@@ -523,9 +532,9 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
file = event;
}
- const imageUploadUrl = `/pictshare/api/upload.php`;
+ const imageUploadUrl = `/pictrs/image`;
const formData = new FormData();
- formData.append('file', file);
+ formData.append('images[]', file);
i.state.imageLoading = true;
i.setState(i.state);
@@ -536,13 +545,26 @@ export class PostForm extends Component<PostFormProps, PostFormState> {
})
.then(res => res.json())
.then(res => {
- let url = `${window.location.origin}/pictshare/${encodeURI(res.url)}`;
- if (res.filetype == 'mp4') {
- url += '/raw';
+ console.log('pictrs upload:');
+ console.log(res);
+ if (res.msg == 'ok') {
+ let hash = res.files[0].file;
+ let url = `${window.location.origin}/pictrs/image/${hash}`;
+ let deleteToken = res.files[0].delete_token;
+ let deleteUrl = `${window.location.origin}/pictrs/image/delete/${deleteToken}/${hash}`;
+ i.state.postForm.url = url;
+ i.state.imageLoading = false;
+ i.setState(i.state);
+ pictrsDeleteToast(
+ i18n.t('click_to_delete_picture'),
+ i18n.t('picture_deleted'),
+ deleteUrl
+ );
+ } else {
+ i.state.imageLoading = false;
+ i.setState(i.state);
+ toast(JSON.stringify(res), 'danger');
}
- i.state.postForm.url = url;
- i.state.imageLoading = false;
- i.setState(i.state);
})
.catch(error => {
i.state.imageLoading = false;