diff --git a/unit/createpost/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/createpost/CreatePostScreen.kt b/unit/createpost/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/createpost/CreatePostScreen.kt index 13d9440e0..af9da640b 100644 --- a/unit/createpost/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/createpost/CreatePostScreen.kt +++ b/unit/createpost/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/createpost/CreatePostScreen.kt @@ -53,6 +53,7 @@ import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.KeyboardCapitalization import androidx.compose.ui.text.input.KeyboardType import androidx.compose.ui.text.input.TextFieldValue +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.unit.dp import cafe.adriel.voyager.core.screen.Screen @@ -161,7 +162,7 @@ class CreatePostScreen( LaunchedEffect(model, communityId) { communityId?.also { communityId -> - CreatePostMviModel.Intent.SetCommunity(CommunityModel(id = communityId)) + model.reduce(CreatePostMviModel.Intent.SetCommunity(CommunityModel(id = communityId))) } } LaunchedEffect(model) { @@ -500,22 +501,6 @@ class CreatePostScreen( color = MaterialTheme.colorScheme.error, ) } - if (uiState.currentUser.isNotEmpty()) { - Text( - text = buildString { - append(stringResource(MR.strings.post_reply_source_account)) - append(" ") - append(uiState.currentUser) - if (uiState.currentInstance.isNotEmpty()) { - append("@") - append(uiState.currentInstance) - } - }, - color = MaterialTheme.colorScheme.onBackground, - style = MaterialTheme.typography.labelSmall, - textDecoration = TextDecoration.Underline, - ) - } } }, ) @@ -538,6 +523,27 @@ class CreatePostScreen( showScores = uiState.showScores, ) } + + if (uiState.currentUser.isNotEmpty()) { + Text( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = Spacing.m), + text = buildString { + append(stringResource(MR.strings.post_reply_source_account)) + append(" ") + append(uiState.currentUser) + if (uiState.currentInstance.isNotEmpty()) { + append("@") + append(uiState.currentInstance) + } + }, + color = MaterialTheme.colorScheme.onBackground, + style = MaterialTheme.typography.labelSmall, + textDecoration = TextDecoration.Underline, + textAlign = TextAlign.End, + ) + } } } } diff --git a/unit/createpost/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/createpost/CreatePostViewModel.kt b/unit/createpost/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/createpost/CreatePostViewModel.kt index 55fb63620..5bf62677a 100644 --- a/unit/createpost/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/createpost/CreatePostViewModel.kt +++ b/unit/createpost/src/commonMain/kotlin/com/github/diegoberaldin/raccoonforlemmy/unit/createpost/CreatePostViewModel.kt @@ -164,7 +164,8 @@ class CreatePostViewModel( } private fun submit(body: String) { - if (uiState.value.loading) { + val currentState = uiState.value + if (currentState.loading) { return } @@ -176,41 +177,33 @@ class CreatePostViewModel( ) } - val communityId = uiState.value.communityId - val title = uiState.value.title - val url = uiState.value.url.takeIf { it.isNotEmpty() }?.trim() - val nsfw = uiState.value.nsfw - val languageId = uiState.value.currentLanguageId + val communityId = currentState.communityId + val title = currentState.title + val url = currentState.url.takeIf { it.isNotEmpty() }?.trim() + val nsfw = currentState.nsfw + val languageId = currentState.currentLanguageId var valid = true if (title.isEmpty()) { updateState { - it.copy( - titleError = message_missing_field.desc(), - ) + it.copy(titleError = message_missing_field.desc()) } valid = false } if (body.isEmpty()) { updateState { - it.copy( - bodyError = message_missing_field.desc(), - ) + it.copy(bodyError = message_missing_field.desc()) } valid = false } if (!url.isNullOrEmpty() && !url.isValidUrl()) { updateState { - it.copy( - urlError = message_invalid_field.desc(), - ) + it.copy(urlError = message_invalid_field.desc()) } valid = false } if (communityId == null) { updateState { - it.copy( - communityError = message_missing_field.desc(), - ) + it.copy(communityError = message_missing_field.desc()) } valid = false }