Add error message in post status form when failing to post and don't get rid of post/attachments when failing.

This commit is contained in:
Shpuld Shpuldson 2017-08-20 13:16:41 +03:00
parent fb3408d64f
commit 42fb65e274
3 changed files with 33 additions and 13 deletions

View File

@ -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)

View File

@ -19,6 +19,9 @@
<media-upload @uploading="disableSubmit" @uploaded="addMediaFile" @upload-failed="enableSubmit" :drop-files="dropFiles"></media-upload>
<button :disabled="submitDisabled" type="submit" class="btn btn-default base05 base01-background">Submit</button>
</div>
<div class='error' v-if="error">
Error: {{ error }}
</div>
<div class="attachments">
<div class="attachment" v-for="file in newStatus.files">
<i class="fa icon-cancel" @click="removeMediaFile(file)"></i>
@ -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;

View File

@ -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
})
}