refs #2033 Reject adding 5+ images before upload images in new toot

This commit is contained in:
AkiraFukushima 2021-01-24 01:38:19 +09:00
parent c9111778a4
commit c241acfa99
3 changed files with 29 additions and 11 deletions

View File

@ -30,6 +30,7 @@ import Mousetrap from 'mousetrap'
import ReceiveDrop from './TimelineSpace/ReceiveDrop'
import { AccountLoadError } from '@/errors/load'
import { TimelineFetchError } from '@/errors/fetch'
import { NewTootAttachLength } from '@/errors/validations'
import { Event } from '~/src/renderer/components/event'
export default {
@ -126,11 +127,18 @@ export default {
.then(() => {
Event.$emit('image-uploaded')
})
.catch(() => {
this.$message({
message: this.$t('message.attach_error'),
type: 'error'
})
.catch(err => {
if (err instanceof NewTootAttachLength) {
this.$message({
message: this.$t('validation.new_toot.attach_length', { max: 4 }),
type: 'error'
})
} else {
this.$message({
message: this.$t('message.attach_error'),
type: 'error'
})
}
})
return false
},

View File

@ -354,11 +354,18 @@ export default {
.then(() => {
this.statusHeight = this.statusHeight - this.$refs.preview.offsetHeight
})
.catch(() => {
this.$message({
message: this.$t('message.attach_error'),
type: 'error'
})
.catch(err => {
if (err instanceof NewTootAttachLength) {
this.$message({
message: this.$t('validation.new_toot.attach_length', { max: 4 }),
type: 'error'
})
} else {
this.$message({
message: this.$t('message.attach_error'),
type: 'error'
})
}
})
},
removeAttachment(media) {

View File

@ -328,7 +328,10 @@ const actions: ActionTree<NewTootState, RootState> = {
commit(MUTATION_TYPES.CHANGE_SENSITIVE, false)
commit(MUTATION_TYPES.CHANGE_VISIBILITY_VALUE, Visibility.Public.value)
},
uploadImage: async ({ commit, rootState }, image: any) => {
uploadImage: async ({ commit, state, rootState }, image: any) => {
if (state.attachedMedias.length > 3) {
throw new NewTootAttachLength()
}
commit(MUTATION_TYPES.CHANGE_BLOCK_SUBMIT, true)
if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) {
throw new AuthenticationError()