Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MessagesAction Update to also handle non-actionable messages without failing #168

Merged
merged 17 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MessageActionMapper @Inject constructor() {
fun map(action: String?): Result<MessagesAction> {
return runCatching {
pauljohanneskraft marked this conversation as resolved.
Show resolved Hide resolved
when {
action.isNullOrBlank() -> error("Invalid action type")
action.isNullOrBlank() -> MessagesAction.NoAction
videoSectionRegex.matches(action) -> {
mapVideoSectionAction(action).getOrThrow()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ data class Message(
val description: String? = null,
val action: String?,
val isDismissible: Boolean = true,
val isLoading: Boolean = false,
pauljohanneskraft marked this conversation as resolved.
Show resolved Hide resolved
val isExpanded: Boolean = false,
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
Expand Down Expand Up @@ -125,17 +124,14 @@ fun MessageItem(
)
}
Spacer(modifier = Modifier.weight(1f))
Button(
modifier = Modifier.testIdentifier(MessageItemTestIdentifiers.ACTION_BUTTON),
colors = ButtonDefaults.buttonColors(containerColor = primary),
enabled = !message.isLoading,
onClick = {
onAction(Action.MessageItemClicked(message))
},
) {
if (message.isLoading) {
CircularProgressIndicator(modifier = Modifier.size(Sizes.Content.small))
} else {
if (message.action != null || message.isDismissible) {
Button(
modifier = Modifier.testIdentifier(MessageItemTestIdentifiers.ACTION_BUTTON),
colors = ButtonDefaults.buttonColors(containerColor = primary),
onClick = {
onAction(Action.MessageItemClicked(message))
},
) {
Text(
text = stringResource(R.string.message_item_button_action_text),
color = Colors.onPrimary,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.stanford.bdh.engagehf.messages

sealed class MessagesAction {
data object NoAction : MessagesAction()
data class VideoSectionAction(val videoSectionVideo: VideoSectionVideo) : MessagesAction()
data object MedicationsAction : MessagesAction()
data object MeasurementsAction : MessagesAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MessagesHandler @Inject constructor(
val actionResult = messagesActionMapper.map(action = message.action)
var failure = actionResult.exceptionOrNull()
when (val messagesAction = actionResult.getOrNull()) {
is MessagesAction.NoAction -> Unit
pauljohanneskraft marked this conversation as resolved.
Show resolved Hide resolved
is MessagesAction.HealthSummaryAction -> {
failure = healthSummaryService.generateHealthSummaryPdf().exceptionOrNull()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import edu.stanford.spezi.core.design.component.AsyncTextButton
import edu.stanford.spezi.core.design.component.VerticalSpacer
import edu.stanford.spezi.core.design.component.validated.outlinedtextfield.ValidatedOutlinedTextField
import edu.stanford.spezi.core.design.theme.Colors
import edu.stanford.spezi.core.design.theme.Spacings
Expand All @@ -56,8 +55,6 @@ import edu.stanford.spezi.core.design.theme.TextStyles.bodyLarge
import edu.stanford.spezi.core.design.theme.TextStyles.titleLarge
import edu.stanford.spezi.core.utils.extensions.testIdentifier
import edu.stanford.spezi.module.account.R
import edu.stanford.spezi.module.account.login.components.SignInWithGoogleButton
import edu.stanford.spezi.module.account.login.components.TextDivider
import edu.stanford.spezi.module.account.register.FieldState
import edu.stanford.spezi.module.account.register.IconLeadingContent
import edu.stanford.spezi.core.design.R as DesignR
Expand Down
Loading