Skip to content

Commit

Permalink
[REFACTOR]#220 : MessageReportScreen -> Dialog로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
jeongjaino committed Jan 15, 2025
1 parent 277d189 commit 27730e7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand All @@ -69,9 +60,7 @@ fun MessageReportScreen(

viewModel.collectSideEffect {
when (it) {
ReportSideEffect.NavigateToMessage -> {
navigator.popUpToMessageScreen()
}
ReportSideEffect.NavigateToMessage -> onDismiss()

is ReportSideEffect.ShowToast -> {
showToast(
Expand All @@ -90,7 +79,7 @@ fun MessageReportScreen(
WSTopBar(
title = stringResource(id = R.string.report_title),
canNavigateBack = true,
navigateUp = navigator::navigateUp,
navigateUp = onDismiss,
)
},
) { innerPadding ->
Expand Down Expand Up @@ -170,7 +159,9 @@ fun MessageReportScreen(
}

Box(
modifier = Modifier.fillMaxSize().zIndex(1f),
modifier = Modifier
.fillMaxSize()
.zIndex(1f),
contentAlignment = Alignment.BottomCenter,
) {
ListBottomGradient(height = 120)
Expand All @@ -186,4 +177,8 @@ fun MessageReportScreen(
)
}
}

LaunchedEffect(Unit) {
viewModel.onAction(ReportAction.OnMessageReportScreenEntered(messageId))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "",
)
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,22 +23,27 @@ import javax.inject.Inject
@HiltViewModel
class ReportViewModel @Inject constructor(
private val commonRepository: CommonRepository,
savedStateHandle: SavedStateHandle,
) : BaseViewModel(), ContainerHost<ReportUiState, ReportSideEffect> {
override val container = container<ReportUiState, ReportSideEffect>(
ReportUiState(
messageId = savedStateHandle["messageId"] ?: -1,
),
)
override val container = container<ReportUiState, ReportSideEffect>(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 {
/** 이미 선택된 신고 사유를 클릭한 경우 선택 해제됨. */
Expand Down

0 comments on commit 27730e7

Please sign in to comment.