Moved upload errors in user_settings to an array. Moved upload error strings to its separate section in i18n

This commit is contained in:
Rinpatch 2018-12-12 16:38:01 +03:00
parent 25a04f2294
commit bf8bb9ce13
5 changed files with 29 additions and 52 deletions

View file

@ -25,7 +25,7 @@ const mediaUpload = {
if (file.size > store.state.instance.uploadlimit) { if (file.size > store.state.instance.uploadlimit) {
const filesize = fileSizeFormatService.fileSizeFormat(file.size) const filesize = fileSizeFormatService.fileSizeFormat(file.size)
const allowedsize = fileSizeFormatService.fileSizeFormat(store.state.instance.uploadlimit) const allowedsize = fileSizeFormatService.fileSizeFormat(store.state.instance.uploadlimit)
self.$emit('upload-failed', 'upload_error_file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit}) self.$emit('upload-failed', 'file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit})
return return
} }
const formData = new FormData() const formData = new FormData()
@ -39,7 +39,7 @@ const mediaUpload = {
self.$emit('uploaded', fileData) self.$emit('uploaded', fileData)
self.uploading = false self.uploading = false
}, (error) => { // eslint-disable-line handle-callback-err }, (error) => { // eslint-disable-line handle-callback-err
self.$emit('upload-failed', 'upload_error_generic') self.$emit('upload-failed', 'default')
self.uploading = false self.uploading = false
}) })
}, },

View file

@ -264,7 +264,7 @@ const PostStatusForm = {
}, },
uploadFailed (errString, templateArgs) { uploadFailed (errString, templateArgs) {
templateArgs = templateArgs || {} templateArgs = templateArgs || {}
this.error = this.$t('post_status.upload_error') + ' ' + this.$t('post_status.' + errString, templateArgs) this.error = this.$t('upload.error.base') + ' ' + this.$t('upload.error.' + errString, templateArgs)
this.enableSubmit() this.enableSubmit()
}, },
disableSubmit () { disableSubmit () {

View file

@ -5,9 +5,7 @@ import fileSizeFormatService from '../../services/file_size_format/file_size_for
const UserSettings = { const UserSettings = {
data () { data () {
return { return {
avataruploaderror: null, uploaderror: [null, null, null],
backgrounduploaderror: null,
banneruploaderror: null,
newname: this.$store.state.users.currentUser.name, newname: this.$store.state.users.currentUser.name,
newbio: this.$store.state.users.currentUser.description, newbio: this.$store.state.users.currentUser.description,
newlocked: this.$store.state.users.currentUser.locked, newlocked: this.$store.state.users.currentUser.locked,
@ -73,27 +71,12 @@ const UserSettings = {
uploadFile (slot, e) { uploadFile (slot, e) {
const file = e.target.files[0] const file = e.target.files[0]
if (!file) { return } if (!file) { return }
var limit = 0 var limit = [this.$store.state.instance.avatarlimit, this.$store.state.instance.bannerlimit, this.$store.state.instance.backgroundlimit]
var error = () => {} console.log(file.size, limit)
switch (slot) { if (file.size > limit[slot]) {
case 0:
limit = this.$store.state.instance.avatarlimit
error = (error) => { this.avataruploaderror = error }
break
case 1:
limit = this.$store.state.instance.bannerlimit
error = (error) => { this.banneruploaderror = error }
break
case 2:
limit = this.$store.state.instance.backgroundlimit
error = (error) => { this.backgrounduploaderror = error }
}
console.log(this.$store)
console.log(file.size + ' ' + slot + ' ' + limit)
if (file.size > limit) {
const filesize = fileSizeFormatService.fileSizeFormat(file.size) const filesize = fileSizeFormatService.fileSizeFormat(file.size)
const allowedsize = fileSizeFormatService.fileSizeFormat(limit) const allowedsize = fileSizeFormatService.fileSizeFormat(limit[slot])
error(this.$t('post_status.upload_error_file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit})) this.$set(this.uploaderror, slot, this.$t('upload.error.base') + ' ' + this.$t('upload.error.file_too_big', {filesize: filesize.num, filesizeunit: filesize.unit, allowedsize: allowedsize.num, allowedsizeunit: allowedsize.unit}))
return return
} }
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
@ -135,17 +118,7 @@ const UserSettings = {
}) })
}, },
clearUploadError (slot) { clearUploadError (slot) {
switch (slot) { this.$set(this.uploaderror, slot, null)
case 0:
this.avataruploaderror = null
break
case 1:
this.banneruploaderror = null
break
case 2:
this.backgrounduploaderror = null
break
}
}, },
submitBanner () { submitBanner () {
if (!this.previews[1]) { return } if (!this.previews[1]) { return }

View file

@ -43,8 +43,8 @@
</div> </div>
<i class="icon-spin4 animate-spin" v-if="uploading[0]"></i> <i class="icon-spin4 animate-spin" v-if="uploading[0]"></i>
<button class="btn btn-default" v-else-if="previews[0]" @click="submitAvatar">{{$t('general.submit')}}</button> <button class="btn btn-default" v-else-if="previews[0]" @click="submitAvatar">{{$t('general.submit')}}</button>
<div class='alert error' v-if="avataruploaderror"> <div class='alert error' v-if="uploaderror[0]">
Error: {{ avataruploaderror }} Error: {{ uploaderror[0] }}
<i class="icon-cancel" @click="clearUploadError(0)"></i> <i class="icon-cancel" @click="clearUploadError(0)"></i>
</div> </div>
</div> </div>
@ -60,8 +60,8 @@
</div> </div>
<i class=" icon-spin4 animate-spin uploading" v-if="uploading[1]"></i> <i class=" icon-spin4 animate-spin uploading" v-if="uploading[1]"></i>
<button class="btn btn-default" v-else-if="previews[1]" @click="submitBanner">{{$t('general.submit')}}</button> <button class="btn btn-default" v-else-if="previews[1]" @click="submitBanner">{{$t('general.submit')}}</button>
<div class='alert error' v-if="banneruploaderror"> <div class='alert error' v-if="uploaderror[1]">
Error: {{ banneruploaderror }} Error: {{ uploaderror[1] }}
<i class="icon-cancel" @click="clearUploadError(1)"></i> <i class="icon-cancel" @click="clearUploadError(1)"></i>
</div> </div>
</div> </div>
@ -75,8 +75,8 @@
</div> </div>
<i class=" icon-spin4 animate-spin uploading" v-if="uploading[2]"></i> <i class=" icon-spin4 animate-spin uploading" v-if="uploading[2]"></i>
<button class="btn btn-default" v-else-if="previews[2]" @click="submitBg">{{$t('general.submit')}}</button> <button class="btn btn-default" v-else-if="previews[2]" @click="submitBg">{{$t('general.submit')}}</button>
<div class='alert error' v-if="backgrounduploaderror"> <div class='alert error' v-if="uploaderror[2]">
Error: {{ backgrounduploaderror }} Error: {{ uploaderror[2] }}
<i class="icon-cancel" @click="clearUploadError(2)"></i> <i class="icon-cancel" @click="clearUploadError(2)"></i>
</div> </div>
</div> </div>

View file

@ -52,9 +52,6 @@
"account_not_locked_warning": "Your account is not {0}. Anyone can follow you to view your follower-only posts.", "account_not_locked_warning": "Your account is not {0}. Anyone can follow you to view your follower-only posts.",
"account_not_locked_warning_link": "locked", "account_not_locked_warning_link": "locked",
"attachments_sensitive": "Mark attachments as sensitive", "attachments_sensitive": "Mark attachments as sensitive",
"upload_error": "Upload failed.",
"upload_error_file_too_big": "File too big [{filesize}{filesizeunit} / {allowedsize}{allowedsizeunit}]",
"upload_error_generic": "Try again later",
"content_type": { "content_type": {
"plain_text": "Plain text" "plain_text": "Plain text"
}, },
@ -230,6 +227,12 @@
"favorite": "Favorite", "favorite": "Favorite",
"user_settings": "User Settings" "user_settings": "User Settings"
}, },
"upload":{
"error": {
"base": "Upload failed.",
"file_too_big": "File too big [{filesize}{filesizeunit} / {allowedsize}{allowedsizeunit}]",
"default": "Try again later"
},
"file_size_units": { "file_size_units": {
"B": "B", "B": "B",
"KiB": "KiB", "KiB": "KiB",
@ -238,3 +241,4 @@
"TiB": "TiB" "TiB": "TiB"
} }
} }
}