TSK-412 Do not allow to post empty comments

Signed-off-by: Alexander Onnikov <alexander.onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2022-11-14 22:37:13 +07:00
parent 2df58960d2
commit 7e829e3724
No known key found for this signature in database
GPG Key ID: 3320C3B3324E934C
2 changed files with 20 additions and 3 deletions

View File

@ -51,6 +51,7 @@
let isFormatting = false let isFormatting = false
let activeModes = new Set<FormatMode>() let activeModes = new Set<FormatMode>()
let isSelectionEmpty = true let isSelectionEmpty = true
let isEmpty = true
interface RefAction { interface RefAction {
label: IntlString label: IntlString
@ -275,6 +276,7 @@
<div class="inputMsg"> <div class="inputMsg">
<TextEditor <TextEditor
bind:content bind:content
bind:isEmpty
bind:this={textEditor} bind:this={textEditor}
on:content={(ev) => { on:content={(ev) => {
dispatch('message', ev.detail) dispatch('message', ev.detail)
@ -286,7 +288,9 @@
/> />
</div> </div>
{#if showSend} {#if showSend}
<button class="sendButton" on:click={submit}><div class="icon"><Send size={'medium'} /></div></button> <button class="sendButton" on:click={submit} disabled={isEmpty}>
<div class="icon"><Send size={'medium'} /></div>
</button>
{/if} {/if}
</div> </div>
<div class="buttons-group large-gap ml-4 mt-2"> <div class="buttons-group large-gap ml-4 mt-2">
@ -418,6 +422,15 @@
color: var(--theme-caption-color); color: var(--theme-caption-color);
} }
} }
&:disabled {
pointer-events: none;
.icon {
opacity: 0.5;
cursor: not-allowed;
}
}
} }
} }
} }

View File

@ -28,6 +28,7 @@
export let placeholder: IntlString = textEditorPlugin.string.EditorPlaceholder export let placeholder: IntlString = textEditorPlugin.string.EditorPlaceholder
export let extensions: AnyExtension[] = [] export let extensions: AnyExtension[] = []
export let supportSubmit = true export let supportSubmit = true
export let isEmpty = true
let element: HTMLElement let element: HTMLElement
let editor: Editor let editor: Editor
@ -41,9 +42,11 @@
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
export function submit (): void { export function submit (): void {
if (!editor.isEmpty) {
content = editor.getHTML() content = editor.getHTML()
dispatch('content', content) dispatch('content', content)
} }
}
export function clear (): void { export function clear (): void {
content = '' content = ''
@ -159,6 +162,7 @@
}, },
onUpdate: () => { onUpdate: () => {
content = editor.getHTML() content = editor.getHTML()
isEmpty = editor.isEmpty
dispatch('value', content) dispatch('value', content)
}, },
onSelectionUpdate: () => dispatch('selection-update') onSelectionUpdate: () => dispatch('selection-update')