Skip to content

Commit 2a5d805

Browse files
committed
Show empty content when commands are unavailable in edit mode
1 parent becda3a commit 2a5d805

5 files changed

Lines changed: 53 additions & 28 deletions

File tree

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/attachments/AttachmentCommandPicker.kt

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import androidx.compose.foundation.Image
2020
import androidx.compose.foundation.layout.Arrangement
2121
import androidx.compose.foundation.layout.Column
2222
import androidx.compose.foundation.layout.Row
23+
import androidx.compose.foundation.layout.fillMaxSize
2324
import androidx.compose.foundation.layout.fillMaxWidth
2425
import androidx.compose.foundation.layout.padding
2526
import androidx.compose.foundation.layout.width
@@ -40,6 +41,7 @@ import androidx.compose.ui.unit.dp
4041
import io.getstream.chat.android.compose.R
4142
import io.getstream.chat.android.compose.R.string.stream_compose_message_composer_instant_commands
4243
import io.getstream.chat.android.compose.state.messages.attachments.CommandPickerMode
44+
import io.getstream.chat.android.compose.ui.components.EmptyContent
4345
import io.getstream.chat.android.compose.ui.theme.ChatTheme
4446
import io.getstream.chat.android.compose.ui.theme.StreamTokens
4547
import io.getstream.chat.android.compose.ui.util.clickable
@@ -61,36 +63,44 @@ internal fun AttachmentCommandPicker(
6163
messageAction: MessageAction? = null,
6264
onCommandSelected: (Command) -> Unit = {},
6365
) {
64-
Column(
65-
modifier = Modifier
66-
.fillMaxWidth(),
67-
) {
68-
Text(
66+
if (messageAction is Edit) {
67+
EmptyContent(
68+
modifier = Modifier.fillMaxSize(),
69+
text = stringResource(R.string.stream_compose_message_composer_commands_unavailable_in_edit),
70+
painter = painterResource(id = R.drawable.stream_design_ic_command),
71+
)
72+
} else {
73+
Column(
6974
modifier = Modifier
70-
.padding(
71-
start = StreamTokens.spacingMd,
72-
end = StreamTokens.spacingMd,
73-
top = StreamTokens.spacingXs,
74-
bottom = StreamTokens.spacingMd,
75-
)
7675
.fillMaxWidth(),
77-
text = stringResource(stream_compose_message_composer_instant_commands),
78-
style = ChatTheme.typography.headingSmall,
79-
color = ChatTheme.colors.textPrimary,
80-
)
81-
val sortedCommands = remember(commands, messageAction) {
82-
commands.sortedByAvailability(messageAction)
83-
}
84-
LazyColumn(horizontalAlignment = Alignment.CenterHorizontally) {
85-
items(
86-
items = sortedCommands,
87-
key = Command::name,
88-
) { command ->
89-
CommandItem(
90-
command = command,
91-
enabled = command.isAvailableFor(messageAction),
92-
onCommandSelected = onCommandSelected,
93-
)
76+
) {
77+
Text(
78+
modifier = Modifier
79+
.padding(
80+
start = StreamTokens.spacingMd,
81+
end = StreamTokens.spacingMd,
82+
top = StreamTokens.spacingXs,
83+
bottom = StreamTokens.spacingMd,
84+
)
85+
.fillMaxWidth(),
86+
text = stringResource(stream_compose_message_composer_instant_commands),
87+
style = ChatTheme.typography.headingSmall,
88+
color = ChatTheme.colors.textPrimary,
89+
)
90+
val sortedCommands = remember(commands, messageAction) {
91+
commands.sortedByAvailability(messageAction)
92+
}
93+
LazyColumn(horizontalAlignment = Alignment.CenterHorizontally) {
94+
items(
95+
items = sortedCommands,
96+
key = Command::name,
97+
) { command ->
98+
CommandItem(
99+
command = command,
100+
enabled = command.isAvailableFor(messageAction),
101+
onCommandSelected = onCommandSelected,
102+
)
103+
}
94104
}
95105
}
96106
}

stream-chat-android-compose/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
<string name="stream_compose_message_composer_command_template">/%1$s %2$s</string>
167167
<string name="stream_compose_message_composer_command_unavailable_in_reply">Not available while replying</string>
168168
<string name="stream_compose_message_composer_command_unavailable_in_edit">Not available while editing</string>
169+
<string name="stream_compose_message_composer_commands_unavailable_in_edit">Commands not available while editing</string>
169170
<string name="stream_compose_message_composer_show_in_channel">Also send in Channel</string>
170171
<string name="stream_compose_message_composer_file_not_supported">File type is not supported</string>
171172
<string name="stream_compose_message_composer_unsupported_attachment">Unsupported attachment</string>

stream-chat-android-compose/src/test/kotlin/io/getstream/chat/android/compose/ui/messages/attachments/AttachmentCommandPickerTest.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,18 @@ internal class AttachmentCommandPickerTest : PaparazziComposeTest {
3737
AttachmentCommandPicker()
3838
}
3939
}
40+
41+
@Test
42+
fun `command picker in edit mode`() {
43+
snapshotWithDarkMode {
44+
AttachmentCommandPickerInEditMode()
45+
}
46+
}
47+
48+
@Test
49+
fun `command picker in reply mode`() {
50+
snapshotWithDarkMode {
51+
AttachmentCommandPickerInReplyMode()
52+
}
53+
}
4054
}
Loading
Loading

0 commit comments

Comments
 (0)