Skip to content

Commit

Permalink
fix(register): show message on uploading invalid image
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexZakablukov committed Mar 17, 2022
1 parent f026544 commit 7e68620
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
1 change: 0 additions & 1 deletion components/views/files/upload/Upload.less
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
display: flex;
justify-content: space-between;
align-items: center;
cursor: pointer;
margin: @large-spacing 0;
}

Expand Down
2 changes: 1 addition & 1 deletion components/views/user/create/Create.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</div>
<div class="column align">
<TypographyText class="set-photo-title" :text="$t('user.registration.photo_text')" />
<input ref="file" class="input-file" type="file" @change="selectImage" accept="image/*"></input>
<input ref="file" class="input-file" type="file" @change="selectImage" accept="image/*" />
<InteractablesButton :action="() => $refs.file.click()" type="primary" size="small"
:text="$t('servers.create.photo_button')" outlined />
</div>
Expand Down
25 changes: 20 additions & 5 deletions components/views/user/create/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ export default Vue.extend({
*/
async selectImage(e: Event) {
const target = e.target as HTMLInputElement
if (target.value === null) return
const files = target.files
if (!files?.length) return
// stop upload if picture is too large for nsfw scan
Expand All @@ -59,7 +61,11 @@ export default Vue.extend({
}
} catch (err: any) {
this.$Logger.log('error', 'file upload error')
this.error = this.$t('errors.sign_in.invalid_file') as string
this.resetFileInput()
return
}
this.error = ''
const reader = new FileReader()
Expand All @@ -74,21 +80,30 @@ export default Vue.extend({
reader.readAsDataURL(files[0])
},
/**
* @method setCroppedImage
* @method resetFileInput
* @description
* @param image
* @returns
* @example
*/
setCroppedImage(image: string) {
this.croppedImage = image
resetFileInput() {
const fileInputRef = this.$refs.file as HTMLInputElement
if (fileInputRef) {
fileInputRef.value = ''
}
},
/**
* @method setCroppedImage
* @description
* @param image
* @returns
* @example
*/
setCroppedImage(image: string) {
this.croppedImage = image
this.resetFileInput()
},
/**
* @method confirm DocsTODO
* @description
Expand Down
3 changes: 3 additions & 0 deletions locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,9 @@ export default {
file_too_large:
'File is too large, please upload a file smaller than 8MB.',
},
sign_in: {
invalid_file: 'Unable to upload, invalid file.',
},
friends: {
request_already_sent: 'You have already sent a request to this user',
request_already_accepted: 'This user is already in your friends',
Expand Down

0 comments on commit 7e68620

Please sign in to comment.