Skip to content

Commit 7abe896

Browse files
committed
fix send button activeness
Signed-off-by: alperozturk96 <alper_ozturk@proton.me>
1 parent bf198b3 commit 7abe896

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

app/src/main/java/com/nextcloud/client/assistant/AssistantScreen.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ private fun InputBar(
330330
) {
331331
val scope = rememberCoroutineScope()
332332
val text by viewModel.inputBarText.collectAsState()
333+
val chatUIState by chatViewModel.uiState.collectAsState()
333334

334335
Surface(
335336
tonalElevation = 3.dp,
@@ -387,7 +388,8 @@ private fun InputBar(
387388
delay(CHAT_INPUT_DELAY)
388389
viewModel.updateInputBarText("")
389390
}
390-
}
391+
},
392+
enabled = chatUIState.canSend()
391393
) {
392394
Icon(
393395
painter = painterResource(id = R.drawable.ic_send),

app/src/main/java/com/nextcloud/client/assistant/chat/ChatContent.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import androidx.compose.foundation.layout.height
2929
import androidx.compose.foundation.layout.padding
3030
import androidx.compose.foundation.layout.size
3131
import androidx.compose.foundation.lazy.LazyColumn
32+
import androidx.compose.foundation.lazy.LazyListState
3233
import androidx.compose.foundation.lazy.items
3334
import androidx.compose.foundation.lazy.rememberLazyListState
3435
import androidx.compose.foundation.shape.CircleShape
@@ -138,7 +139,7 @@ private fun ChatMessageList(
138139
messages: List<ChatMessage>,
139140
showTypingIndicator: Boolean,
140141
modifier: Modifier = Modifier,
141-
listState: androidx.compose.foundation.lazy.LazyListState,
142+
listState: LazyListState,
142143
bottomSlot: (@Composable () -> Unit)? = null
143144
) {
144145
LazyColumn(

app/src/main/java/com/nextcloud/client/assistant/chat/ChatUIState.kt

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ sealed class ChatUIState {
1717
data class Thinking(val messages: List<ChatMessage>) : ChatUIState()
1818
data class RetryAvailable(val messages: List<ChatMessage>) : ChatUIState()
1919
data class Error(val messages: List<ChatMessage>, val errorType: ChatErrorType) : ChatUIState()
20-
}
2120

22-
fun ChatUIState.messages(): List<ChatMessage> = when (this) {
23-
is ChatUIState.Content -> messages
24-
is ChatUIState.Sending -> messages
25-
is ChatUIState.Thinking -> messages
26-
is ChatUIState.RetryAvailable -> messages
27-
is ChatUIState.Error -> messages
28-
is ChatUIState.Loading, is ChatUIState.Empty -> emptyList()
21+
fun messages(): List<ChatMessage> = when (this) {
22+
is Content -> messages
23+
is Sending -> messages
24+
is Thinking -> messages
25+
is RetryAvailable -> messages
26+
is Error -> messages
27+
is Loading, is Empty -> emptyList()
28+
}
29+
30+
fun canSend(): Boolean = (this == Empty || this is Content)
2931
}

0 commit comments

Comments
 (0)