From 42fb65e274f4890263e4cb3d88ba3b9c0b728516 Mon Sep 17 00:00:00 2001 From: Shpuld Shpuldson Date: Sun, 20 Aug 2017 13:16:41 +0300 Subject: [PATCH] Add error message in post status form when failing to post and don't get rid of post/attachments when failing. --- .../post_status_form/post_status_form.js | 21 ++++++++++++------- .../post_status_form/post_status_form.vue | 10 +++++++++ .../status_poster/status_poster.service.js | 15 +++++++------ 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/components/post_status_form/post_status_form.js b/src/components/post_status_form/post_status_form.js index c097026362..6b78b7dda2 100644 --- a/src/components/post_status_form/post_status_form.js +++ b/src/components/post_status_form/post_status_form.js @@ -39,6 +39,7 @@ const PostStatusForm = { return { dropFiles: [], submitDisabled: false, + error: null, newStatus: { status: statusText, files: [] @@ -90,14 +91,20 @@ const PostStatusForm = { media: newStatus.files, store: this.$store, inReplyToStatusId: this.replyTo + }).then((data) => { + if (!data.error) { + this.newStatus = { + status: '', + files: [] + } + this.$emit('posted') + let el = this.$el.querySelector('textarea') + el.style.height = '16px' + this.error = null + } else { + this.error = data.error + } }) - this.newStatus = { - status: '', - files: [] - } - this.$emit('posted') - let el = this.$el.querySelector('textarea') - el.style.height = '16px' }, addMediaFile (fileInfo) { this.newStatus.files.push(fileInfo) diff --git a/src/components/post_status_form/post_status_form.vue b/src/components/post_status_form/post_status_form.vue index a17d6479f8..e1e3e4be3f 100644 --- a/src/components/post_status_form/post_status_form.vue +++ b/src/components/post_status_form/post_status_form.vue @@ -19,6 +19,9 @@ +
+ Error: {{ error }} +
@@ -61,6 +64,13 @@ width: 10em; } } + .error { + border-radius: 5px; + text-align: center; + background-color: rgba(255, 48, 16, 0.65); + padding: 0.25em; + margin: 0.35em; + } .attachments { padding: 0 0.5em; diff --git a/src/services/status_poster/status_poster.service.js b/src/services/status_poster/status_poster.service.js index bc1fd37d26..ee8d160a48 100644 --- a/src/services/status_poster/status_poster.service.js +++ b/src/services/status_poster/status_poster.service.js @@ -7,12 +7,15 @@ const postStatus = ({ store, status, media = [], inReplyToStatusId = undefined } return apiService.postStatus({credentials: store.state.users.currentUser.credentials, status, mediaIds, inReplyToStatusId}) .then((data) => data.json()) .then((data) => { - store.dispatch('addNewStatuses', { - statuses: [data], - timeline: 'friends', - showImmediately: true, - noIdUpdate: true // To prevent missing notices on next pull. - }) + if (!data.error) { + store.dispatch('addNewStatuses', { + statuses: [data], + timeline: 'friends', + showImmediately: true, + noIdUpdate: true // To prevent missing notices on next pull. + }) + } + return data }) }