Update avatar uploading

This commit is contained in:
taehoon 2019-03-22 13:00:58 -04:00
parent e14720419f
commit ac0b45fa14
3 changed files with 9 additions and 20 deletions

View file

@ -70,22 +70,10 @@ const ImageCropper = {
this.dataUrl = undefined this.dataUrl = undefined
this.$emit('close') this.$emit('close')
}, },
submit () { submit (cropping = true) {
this.submitting = true this.submitting = true
this.avatarUploadError = null this.avatarUploadError = null
this.submitHandler(this.cropper, this.file) this.submitHandler(cropping && this.cropper, this.file)
.then(() => this.destroy())
.catch((err) => {
this.submitError = err
})
.finally(() => {
this.submitting = false
})
},
submitWithoutCropping () {
this.submitting = true
this.avatarUploadError = null
this.submitHandler(false, this.dataUrl)
.then(() => this.destroy()) .then(() => this.destroy())
.catch((err) => { .catch((err) => {
this.submitError = err this.submitError = err

View file

@ -5,9 +5,9 @@
<img ref="img" :src="dataUrl" alt="" @load.stop="createCropper" /> <img ref="img" :src="dataUrl" alt="" @load.stop="createCropper" />
</div> </div>
<div class="image-cropper-buttons-wrapper"> <div class="image-cropper-buttons-wrapper">
<button class="btn" type="button" :disabled="submitting" @click="submit" v-text="saveText"></button> <button class="btn" type="button" :disabled="submitting" @click="submit()" v-text="saveText"></button>
<button class="btn" type="button" :disabled="submitting" @click="destroy" v-text="cancelText"></button> <button class="btn" type="button" :disabled="submitting" @click="destroy" v-text="cancelText"></button>
<button class="btn" type="button" :disabled="submitting" @click="submitWithoutCropping" v-text="saveWithoutCroppingText"></button> <button class="btn" type="button" :disabled="submitting" @click="submit(false)" v-text="saveWithoutCroppingText"></button>
<i class="icon-spin4 animate-spin" v-if="submitting"></i> <i class="icon-spin4 animate-spin" v-if="submitting"></i>
</div> </div>
<div class="alert error" v-if="submitError"> <div class="alert error" v-if="submitError">

View file

@ -163,16 +163,17 @@ const UserSettings = {
reader.readAsDataURL(file) reader.readAsDataURL(file)
}, },
submitAvatar (cropper, file) { submitAvatar (cropper, file) {
const that = this
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
function updateAvatar (avatar) { function updateAvatar (avatar) {
this.$store.state.api.backendInteractor.updateAvatar({ avatar }) that.$store.state.api.backendInteractor.updateAvatar({ avatar })
.then((user) => { .then((user) => {
this.$store.commit('addNewUsers', [user]) that.$store.commit('addNewUsers', [user])
this.$store.commit('setCurrentUser', user) that.$store.commit('setCurrentUser', user)
resolve() resolve()
}) })
.catch((err) => { .catch((err) => {
reject(new Error(this.$t('upload.error.base') + ' ' + err.message)) reject(new Error(that.$t('upload.error.base') + ' ' + err.message))
}) })
} }