From c241acfa9902e44a7efe52bb493e20c1f4e4ec9b Mon Sep 17 00:00:00 2001 From: AkiraFukushima Date: Sun, 24 Jan 2021 01:38:19 +0900 Subject: [PATCH] refs #2033 Reject adding 5+ images before upload images in new toot --- src/renderer/components/TimelineSpace.vue | 18 +++++++++++++----- .../TimelineSpace/Modals/NewToot.vue | 17 ++++++++++++----- .../store/TimelineSpace/Modals/NewToot.ts | 5 ++++- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/renderer/components/TimelineSpace.vue b/src/renderer/components/TimelineSpace.vue index 9c809676..7b42699f 100644 --- a/src/renderer/components/TimelineSpace.vue +++ b/src/renderer/components/TimelineSpace.vue @@ -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 }, diff --git a/src/renderer/components/TimelineSpace/Modals/NewToot.vue b/src/renderer/components/TimelineSpace/Modals/NewToot.vue index b6e4c8e8..15d6d9b7 100644 --- a/src/renderer/components/TimelineSpace/Modals/NewToot.vue +++ b/src/renderer/components/TimelineSpace/Modals/NewToot.vue @@ -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) { diff --git a/src/renderer/store/TimelineSpace/Modals/NewToot.ts b/src/renderer/store/TimelineSpace/Modals/NewToot.ts index a7356a09..78c5f642 100644 --- a/src/renderer/store/TimelineSpace/Modals/NewToot.ts +++ b/src/renderer/store/TimelineSpace/Modals/NewToot.ts @@ -328,7 +328,10 @@ const actions: ActionTree = { 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()