mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
Prevent sending empty messages (#2527)
* Prevent sending empty messages * Fix screenshot issue * Use `aRichTextEditorState` helper function
This commit is contained in:
committed by
GitHub
parent
f865f301d5
commit
3453738344
@@ -0,0 +1 @@
|
|||||||
|
Prevent sending empty messages.
|
||||||
+2
-2
@@ -43,8 +43,8 @@ import io.element.android.libraries.architecture.AsyncData
|
|||||||
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
import io.element.android.libraries.designsystem.components.avatar.AvatarData
|
||||||
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
import io.element.android.libraries.designsystem.components.avatar.AvatarSize
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
|
import io.element.android.libraries.textcomposer.aRichTextEditorState
|
||||||
import io.element.android.libraries.textcomposer.model.MessageComposerMode
|
import io.element.android.libraries.textcomposer.model.MessageComposerMode
|
||||||
import io.element.android.wysiwyg.compose.RichTextEditorState
|
|
||||||
import kotlinx.collections.immutable.persistentListOf
|
import kotlinx.collections.immutable.persistentListOf
|
||||||
import kotlinx.collections.immutable.persistentSetOf
|
import kotlinx.collections.immutable.persistentSetOf
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ fun aMessagesState(
|
|||||||
userHasPermissionToRedactOther: Boolean = false,
|
userHasPermissionToRedactOther: Boolean = false,
|
||||||
userHasPermissionToSendReaction: Boolean = true,
|
userHasPermissionToSendReaction: Boolean = true,
|
||||||
composerState: MessageComposerState = aMessageComposerState(
|
composerState: MessageComposerState = aMessageComposerState(
|
||||||
richTextEditorState = RichTextEditorState("Hello", initialFocus = true),
|
richTextEditorState = aRichTextEditorState(initialText = "Hello", initialFocus = true),
|
||||||
isFullScreen = false,
|
isFullScreen = false,
|
||||||
mode = MessageComposerMode.Normal,
|
mode = MessageComposerMode.Normal,
|
||||||
),
|
),
|
||||||
|
|||||||
+29
-15
@@ -172,7 +172,7 @@ fun TextComposer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val canSendMessage by remember { derivedStateOf { state.messageHtml.isNotEmpty() } }
|
val canSendMessage by remember { derivedStateOf { state.messageMarkdown.isNotBlank() } }
|
||||||
val sendButton = @Composable {
|
val sendButton = @Composable {
|
||||||
SendButton(
|
SendButton(
|
||||||
canSendMessage = canSendMessage,
|
canSendMessage = canSendMessage,
|
||||||
@@ -598,7 +598,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
|
|||||||
items = persistentListOf(
|
items = persistentListOf(
|
||||||
{
|
{
|
||||||
ATextComposer(
|
ATextComposer(
|
||||||
RichTextEditorState("", initialFocus = true),
|
aRichTextEditorState(initialText = "", initialFocus = true),
|
||||||
voiceMessageState = VoiceMessageState.Idle,
|
voiceMessageState = VoiceMessageState.Idle,
|
||||||
composerMode = MessageComposerMode.Normal,
|
composerMode = MessageComposerMode.Normal,
|
||||||
enableTextFormatting = true,
|
enableTextFormatting = true,
|
||||||
@@ -608,7 +608,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ATextComposer(
|
ATextComposer(
|
||||||
RichTextEditorState("A message", initialFocus = true),
|
aRichTextEditorState(initialText = "A message", initialFocus = true),
|
||||||
voiceMessageState = VoiceMessageState.Idle,
|
voiceMessageState = VoiceMessageState.Idle,
|
||||||
composerMode = MessageComposerMode.Normal,
|
composerMode = MessageComposerMode.Normal,
|
||||||
enableTextFormatting = true,
|
enableTextFormatting = true,
|
||||||
@@ -618,8 +618,8 @@ internal fun TextComposerSimplePreview() = ElementPreview {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ATextComposer(
|
ATextComposer(
|
||||||
RichTextEditorState(
|
aRichTextEditorState(
|
||||||
"A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
|
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
|
||||||
initialFocus = true
|
initialFocus = true
|
||||||
),
|
),
|
||||||
voiceMessageState = VoiceMessageState.Idle,
|
voiceMessageState = VoiceMessageState.Idle,
|
||||||
@@ -631,7 +631,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ATextComposer(
|
ATextComposer(
|
||||||
RichTextEditorState("A message without focus", initialFocus = false),
|
aRichTextEditorState(initialText = "A message without focus", initialFocus = false),
|
||||||
voiceMessageState = VoiceMessageState.Idle,
|
voiceMessageState = VoiceMessageState.Idle,
|
||||||
composerMode = MessageComposerMode.Normal,
|
composerMode = MessageComposerMode.Normal,
|
||||||
enableTextFormatting = true,
|
enableTextFormatting = true,
|
||||||
@@ -648,7 +648,7 @@ internal fun TextComposerSimplePreview() = ElementPreview {
|
|||||||
internal fun TextComposerFormattingPreview() = ElementPreview {
|
internal fun TextComposerFormattingPreview() = ElementPreview {
|
||||||
PreviewColumn(items = persistentListOf({
|
PreviewColumn(items = persistentListOf({
|
||||||
ATextComposer(
|
ATextComposer(
|
||||||
RichTextEditorState("", initialFocus = false),
|
aRichTextEditorState(initialText = "", initialFocus = false),
|
||||||
voiceMessageState = VoiceMessageState.Idle,
|
voiceMessageState = VoiceMessageState.Idle,
|
||||||
showTextFormatting = true,
|
showTextFormatting = true,
|
||||||
composerMode = MessageComposerMode.Normal,
|
composerMode = MessageComposerMode.Normal,
|
||||||
@@ -658,7 +658,7 @@ internal fun TextComposerFormattingPreview() = ElementPreview {
|
|||||||
)
|
)
|
||||||
}, {
|
}, {
|
||||||
ATextComposer(
|
ATextComposer(
|
||||||
RichTextEditorState("A message", initialFocus = false),
|
aRichTextEditorState(initialText = "A message", initialFocus = false),
|
||||||
voiceMessageState = VoiceMessageState.Idle,
|
voiceMessageState = VoiceMessageState.Idle,
|
||||||
showTextFormatting = true,
|
showTextFormatting = true,
|
||||||
composerMode = MessageComposerMode.Normal,
|
composerMode = MessageComposerMode.Normal,
|
||||||
@@ -668,7 +668,10 @@ internal fun TextComposerFormattingPreview() = ElementPreview {
|
|||||||
)
|
)
|
||||||
}, {
|
}, {
|
||||||
ATextComposer(
|
ATextComposer(
|
||||||
RichTextEditorState("A message\nWith several lines\nTo preview larger textfields and long lines with overflow", initialFocus = false),
|
aRichTextEditorState(
|
||||||
|
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
|
||||||
|
initialFocus = false
|
||||||
|
),
|
||||||
voiceMessageState = VoiceMessageState.Idle,
|
voiceMessageState = VoiceMessageState.Idle,
|
||||||
showTextFormatting = true,
|
showTextFormatting = true,
|
||||||
composerMode = MessageComposerMode.Normal,
|
composerMode = MessageComposerMode.Normal,
|
||||||
@@ -684,7 +687,7 @@ internal fun TextComposerFormattingPreview() = ElementPreview {
|
|||||||
internal fun TextComposerEditPreview() = ElementPreview {
|
internal fun TextComposerEditPreview() = ElementPreview {
|
||||||
PreviewColumn(items = persistentListOf({
|
PreviewColumn(items = persistentListOf({
|
||||||
ATextComposer(
|
ATextComposer(
|
||||||
RichTextEditorState("A message", initialFocus = true),
|
aRichTextEditorState(initialText = "A message", initialFocus = true),
|
||||||
voiceMessageState = VoiceMessageState.Idle,
|
voiceMessageState = VoiceMessageState.Idle,
|
||||||
composerMode = MessageComposerMode.Edit(EventId("$1234"), "Some text", TransactionId("1234")),
|
composerMode = MessageComposerMode.Edit(EventId("$1234"), "Some text", TransactionId("1234")),
|
||||||
enableTextFormatting = true,
|
enableTextFormatting = true,
|
||||||
@@ -701,7 +704,7 @@ internal fun TextComposerReplyPreview() = ElementPreview {
|
|||||||
items = persistentListOf(
|
items = persistentListOf(
|
||||||
{
|
{
|
||||||
ATextComposer(
|
ATextComposer(
|
||||||
RichTextEditorState(""),
|
aRichTextEditorState(""),
|
||||||
voiceMessageState = VoiceMessageState.Idle,
|
voiceMessageState = VoiceMessageState.Idle,
|
||||||
composerMode = MessageComposerMode.Reply(
|
composerMode = MessageComposerMode.Reply(
|
||||||
isThreaded = false,
|
isThreaded = false,
|
||||||
@@ -737,7 +740,7 @@ internal fun TextComposerReplyPreview() = ElementPreview {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ATextComposer(
|
ATextComposer(
|
||||||
RichTextEditorState("A message"),
|
aRichTextEditorState(initialText = "A message"),
|
||||||
voiceMessageState = VoiceMessageState.Idle,
|
voiceMessageState = VoiceMessageState.Idle,
|
||||||
composerMode = MessageComposerMode.Reply(
|
composerMode = MessageComposerMode.Reply(
|
||||||
isThreaded = true,
|
isThreaded = true,
|
||||||
@@ -758,7 +761,7 @@ internal fun TextComposerReplyPreview() = ElementPreview {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ATextComposer(
|
ATextComposer(
|
||||||
RichTextEditorState("A message"),
|
aRichTextEditorState(initialText = "A message"),
|
||||||
voiceMessageState = VoiceMessageState.Idle,
|
voiceMessageState = VoiceMessageState.Idle,
|
||||||
composerMode = MessageComposerMode.Reply(
|
composerMode = MessageComposerMode.Reply(
|
||||||
isThreaded = false,
|
isThreaded = false,
|
||||||
@@ -779,7 +782,7 @@ internal fun TextComposerReplyPreview() = ElementPreview {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ATextComposer(
|
ATextComposer(
|
||||||
RichTextEditorState("A message"),
|
aRichTextEditorState(initialText = "A message"),
|
||||||
voiceMessageState = VoiceMessageState.Idle,
|
voiceMessageState = VoiceMessageState.Idle,
|
||||||
composerMode = MessageComposerMode.Reply(
|
composerMode = MessageComposerMode.Reply(
|
||||||
isThreaded = false,
|
isThreaded = false,
|
||||||
@@ -800,7 +803,7 @@ internal fun TextComposerReplyPreview() = ElementPreview {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
ATextComposer(
|
ATextComposer(
|
||||||
RichTextEditorState("A message", initialFocus = true),
|
aRichTextEditorState(initialText = "A message", initialFocus = true),
|
||||||
voiceMessageState = VoiceMessageState.Idle,
|
voiceMessageState = VoiceMessageState.Idle,
|
||||||
composerMode = MessageComposerMode.Reply(
|
composerMode = MessageComposerMode.Reply(
|
||||||
isThreaded = false,
|
isThreaded = false,
|
||||||
@@ -923,3 +926,14 @@ private fun ATextComposer(
|
|||||||
onRichContentSelected = null,
|
onRichContentSelected = null,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun aRichTextEditorState(
|
||||||
|
initialText: String = "",
|
||||||
|
initialHtml: String = initialText,
|
||||||
|
initialMarkdown: String = initialText,
|
||||||
|
initialFocus: Boolean = false,
|
||||||
|
) = RichTextEditorState(
|
||||||
|
initialHtml = initialHtml,
|
||||||
|
initialMarkdown = initialMarkdown,
|
||||||
|
initialFocus = initialFocus,
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user