diff --git a/feature/message/src/main/kotlin/com/bff/wespot/message/screen/MessageReportScreen.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/screen/MessageReportScreen.kt index 41d02717..2eb2d7e3 100644 --- a/feature/message/src/main/kotlin/com/bff/wespot/message/screen/MessageReportScreen.kt +++ b/feature/message/src/main/kotlin/com/bff/wespot/message/screen/MessageReportScreen.kt @@ -16,6 +16,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -38,27 +39,17 @@ import com.bff.wespot.ui.component.ListBottomGradient import com.bff.wespot.ui.component.WSSelectionItem import com.bff.wespot.ui.model.ToastState import com.bff.wespot.ui.util.handleSideEffect -import com.ramcosta.composedestinations.annotation.Destination import kotlinx.collections.immutable.persistentListOf import org.orbitmvi.orbit.compose.collectAsState import org.orbitmvi.orbit.compose.collectSideEffect -interface MessageReportNavigator { - fun navigateUp() - fun popUpToMessageScreen() -} - -data class MessageReportScreenArgs( - val messageId: Int, -) - @OptIn(ExperimentalMaterial3Api::class) -@Destination(navArgsDelegate = MessageReportScreenArgs::class) @Composable fun MessageReportScreen( viewModel: ReportViewModel = hiltViewModel(), + messageId: Int, showToast: (ToastState) -> Unit, - navigator: MessageReportNavigator, + onDismiss: () -> Unit, ) { val scrollState = rememberScrollState() @@ -69,9 +60,7 @@ fun MessageReportScreen( viewModel.collectSideEffect { when (it) { - ReportSideEffect.NavigateToMessage -> { - navigator.popUpToMessageScreen() - } + ReportSideEffect.NavigateToMessage -> onDismiss() is ReportSideEffect.ShowToast -> { showToast( @@ -90,7 +79,7 @@ fun MessageReportScreen( WSTopBar( title = stringResource(id = R.string.report_title), canNavigateBack = true, - navigateUp = navigator::navigateUp, + navigateUp = onDismiss, ) }, ) { innerPadding -> @@ -170,7 +159,9 @@ fun MessageReportScreen( } Box( - modifier = Modifier.fillMaxSize().zIndex(1f), + modifier = Modifier + .fillMaxSize() + .zIndex(1f), contentAlignment = Alignment.BottomCenter, ) { ListBottomGradient(height = 120) @@ -186,4 +177,8 @@ fun MessageReportScreen( ) } } + + LaunchedEffect(Unit) { + viewModel.onAction(ReportAction.OnMessageReportScreenEntered(messageId)) + } } diff --git a/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportAction.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportAction.kt index 21f1b4cc..2e2696b9 100644 --- a/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportAction.kt +++ b/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportAction.kt @@ -4,6 +4,7 @@ import com.bff.wespot.message.model.ReportReason sealed class ReportAction { data object OnMessageReportButtonClicked : ReportAction() + data class OnMessageReportScreenEntered(val messageId: Int) : ReportAction() data class OnReportReasonSelected(val reportReason: ReportReason) : ReportAction() data class OnReportReasonChanged(val reason: String) : ReportAction() } diff --git a/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportUiState.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportUiState.kt index 890d2649..96307a45 100644 --- a/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportUiState.kt +++ b/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportUiState.kt @@ -3,7 +3,7 @@ package com.bff.wespot.message.state.report import com.bff.wespot.message.model.ReportReason data class ReportUiState( - val messageId: Int, + val messageId: Int = -1, val reportReason: ReportReason = ReportReason(), val inputReportReason: String = "", ) diff --git a/feature/message/src/main/kotlin/com/bff/wespot/message/viewmodel/ReportViewModel.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/viewmodel/ReportViewModel.kt index 1e8f2e23..39cdaa20 100644 --- a/feature/message/src/main/kotlin/com/bff/wespot/message/viewmodel/ReportViewModel.kt +++ b/feature/message/src/main/kotlin/com/bff/wespot/message/viewmodel/ReportViewModel.kt @@ -1,6 +1,5 @@ package com.bff.wespot.message.viewmodel -import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import com.bff.wespot.common.extension.onNetworkFailure import com.bff.wespot.domain.repository.CommonRepository @@ -24,22 +23,27 @@ import javax.inject.Inject @HiltViewModel class ReportViewModel @Inject constructor( private val commonRepository: CommonRepository, - savedStateHandle: SavedStateHandle, ) : BaseViewModel(), ContainerHost { - override val container = container( - ReportUiState( - messageId = savedStateHandle["messageId"] ?: -1, - ), - ) + override val container = container(ReportUiState()) fun onAction(action: ReportAction) { when (action) { + is ReportAction.OnMessageReportScreenEntered -> { + handleMessageReportScreenEntered(action.messageId) + } is ReportAction.OnReportReasonSelected -> handleReportReasonSelected(action.reportReason) is ReportAction.OnReportReasonChanged -> handleReportReasonChanged(action.reason) ReportAction.OnMessageReportButtonClicked -> reportMessage() } } + private fun handleMessageReportScreenEntered(messageId: Int) = intent { + /** MessageReportScreen이 Dialog로, 보이지 않아도 상태가 유지되므로 진입시에 상태를 초기화 한다.*/ + reduce { + ReportUiState(messageId = messageId) + } + } + private fun handleReportReasonSelected(reportReason: ReportReason) = intent { reduce { /** 이미 선택된 신고 사유를 클릭한 경우 선택 해제됨. */