Merge pull request #2069 from h3poteto/iss-2033

closes #2033 Reject adding 5+ images before upload images in new toot
This commit is contained in:
AkiraFukushima 2021-01-24 12:36:40 +09:00 committed by GitHub
commit 9a8b32cd80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 ReceiveDrop from './TimelineSpace/ReceiveDrop'
import { AccountLoadError } from '@/errors/load' import { AccountLoadError } from '@/errors/load'
import { TimelineFetchError } from '@/errors/fetch' import { TimelineFetchError } from '@/errors/fetch'
import { NewTootAttachLength } from '@/errors/validations'
import { Event } from '~/src/renderer/components/event' import { Event } from '~/src/renderer/components/event'
export default { export default {
@ -126,11 +127,18 @@ export default {
.then(() => { .then(() => {
Event.$emit('image-uploaded') Event.$emit('image-uploaded')
}) })
.catch(() => { .catch(err => {
this.$message({ if (err instanceof NewTootAttachLength) {
message: this.$t('message.attach_error'), this.$message({
type: 'error' 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 return false
}, },

View File

@ -354,11 +354,18 @@ export default {
.then(() => { .then(() => {
this.statusHeight = this.statusHeight - this.$refs.preview.offsetHeight this.statusHeight = this.statusHeight - this.$refs.preview.offsetHeight
}) })
.catch(() => { .catch(err => {
this.$message({ if (err instanceof NewTootAttachLength) {
message: this.$t('message.attach_error'), this.$message({
type: 'error' 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) { removeAttachment(media) {

View File

@ -328,7 +328,10 @@ const actions: ActionTree<NewTootState, RootState> = {
commit(MUTATION_TYPES.CHANGE_SENSITIVE, false) commit(MUTATION_TYPES.CHANGE_SENSITIVE, false)
commit(MUTATION_TYPES.CHANGE_VISIBILITY_VALUE, Visibility.Public.value) 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) commit(MUTATION_TYPES.CHANGE_BLOCK_SUBMIT, true)
if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) { if (rootState.TimelineSpace.account.accessToken === undefined || rootState.TimelineSpace.account.accessToken === null) {
throw new AuthenticationError() throw new AuthenticationError()