Skip to content

Commit

Permalink
fix(message): disable save on empty message (#3317)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonwoodland committed May 31, 2022
1 parent 685f7e0 commit e709bc9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
12 changes: 8 additions & 4 deletions components/views/chat/message/edit/Edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
</div>
<div class="edit-message-bottom">
<div>
{{$t('messaging.edit.escape_to')}}
<a @click="cancelMessage">{{$t('messaging.edit.cancel')}}</a>
{{$t('messaging.edit.enter_to')}}
<a @click="saveMessage">{{$t('messaging.edit.save')}}</a>
<div>
{{$t('messaging.edit.escape_to')}}
<a @click="cancelMessage">{{$t('messaging.edit.cancel')}}</a>
</div>
<div>
{{$t('messaging.edit.enter_to')}}
<a @click="saveMessage">{{$t('messaging.edit.save')}}</a>
</div>
</div>
<div>{{lengthCount}}/{{maxChars}}</div>
</div>
Expand Down
10 changes: 7 additions & 3 deletions components/views/chat/message/edit/Edit.less
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@
margin: 0 -@light-spacing 0 0;
justify-content: space-between;
& > div {
padding: 0 @light-spacing;
a {
margin-right: @light-spacing;
display: flex;
margin: 0 @light-spacing;
> div {
&:not(:last-child)::after {
content: '';
margin: 0 @light-spacing;
}
}
}
}
Expand Down
24 changes: 10 additions & 14 deletions components/views/chat/message/edit/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@ import { Config } from '~/config'
import { KeybindingEnum } from '~/libraries/Enums/enums'
import Editable from '~/components/views/chat/chatbar/Editable.vue'
declare module 'vue/types/vue' {
interface Vue {
saveMessage: Function
cancelMessage: Function
lengthCount: number
charlimit: boolean
}
}
export default Vue.extend({
components: {
SmileIcon,
Expand All @@ -40,19 +31,23 @@ export default Vue.extend({
}
},
computed: {
lengthCount() {
return this.$data.content.length
lengthCount(): number {
return this.content.length
},
charlimit() {
charlimit(): boolean {
return this.lengthCount > this.maxChars
},
},
mounted() {
this.$data.content = this.$props.message
this.content = this.message
},
methods: {
saveMessage() {
this.$emit('commitMessage', this.$data.content.slice(0, this.maxChars))
if (this.content.trim().length === 0) {
this.$toast.error(this.$t('errors.chat.empty_message_error') as string)
return
}
this.$emit('commitMessage', this.content.slice(0, this.maxChars))
},
cancelMessage() {
this.$emit('cancelMessage')
Expand All @@ -64,6 +59,7 @@ export default Vue.extend({
switch (event.key) {
case KeybindingEnum.ENTER:
if (!event.shiftKey) {
event.preventDefault()
this.saveMessage()
}
break
Expand Down
4 changes: 2 additions & 2 deletions locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ export default {
files: 'Files',
},
edit: {
escape_to: 'escape to ',
escape_to: 'escape to',
cancel: 'cancel',
enter_to: 'enter to ',
enter_to: 'enter to',
save: 'save',
},
},
Expand Down

0 comments on commit e709bc9

Please sign in to comment.