Skip to content

Commit

Permalink
Update #247: DeleteSuccessRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
0se0 committed Nov 7, 2024
1 parent 2074440 commit 47060d4
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package com.hankki.feature.storedetail.editbottomsheet.edit.delete

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.hankki.core.common.extension.noRippleClickable
import com.hankki.core.designsystem.component.button.HankkiMediumButton
import com.hankki.core.designsystem.component.topappbar.HankkiTopBar
import com.hankki.core.designsystem.theme.Gray700
import com.hankki.core.designsystem.theme.Gray850
import com.hankki.core.designsystem.theme.HankkiTheme
import com.hankki.core.designsystem.theme.Red500
import com.hankki.core.designsystem.theme.White
import com.hankki.feature.storedetail.R

@Composable
fun DeleteSuccessRoute(
viewModel: DeleteSuccessViewModel = hiltViewModel(),
onNavigateToEditMenu: () -> Unit,
onNavigateToStoreDetailRoute: () -> Unit,
onNavigateUp: () -> Unit
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val sideEffectFlow = viewModel.sideEffect

LaunchedEffect(Unit) {
sideEffectFlow.collect { sideEffect ->
when (sideEffect) {
DeleteSuccessSideEffect.NavigateToEditMenu -> onNavigateToEditMenu()
DeleteSuccessSideEffect.NavigateToStoreDetail -> onNavigateToStoreDetailRoute()
DeleteSuccessSideEffect.NavigateUp -> onNavigateUp()
}
}
}

DeleteSuccessScreen(
nickname = uiState.nickname,
onNavigateToEditMenu = { viewModel.navigateToEditMenu() },
onNavigateToStoreDetailRoute = { viewModel.navigateToStoreDetail() },
onNavigateUp = { viewModel.navigateUp() },
)
}

@Composable
fun DeleteSuccessScreen(
nickname: String,
onNavigateToEditMenu: () -> Unit,
onNavigateToStoreDetailRoute: () -> Unit,
onNavigateUp: () -> Unit
) {
Column(
modifier = Modifier
.fillMaxSize()
) {
Spacer(modifier = Modifier.statusBarsPadding())
HankkiTopBar(
leadingIcon = {
Icon(
painter = painterResource(com.hankki.core.designsystem.R.drawable.ic_arrow_left),
contentDescription = "뒤로가기",
modifier = Modifier
.offset(x = 6.dp, y = 2.dp)
.noRippleClickable(onClick = onNavigateUp),
tint = Gray700
)
}
)

Spacer(modifier = Modifier.height(18.dp))
Text(
text = "${nickname}님이 말씀해주신대로\n메뉴를 삭제했어요!",
style = HankkiTheme.typography.suitH2,
color = Gray850,
modifier = Modifier.padding(start = 22.dp)
)

Box {
Image(
painter = painterResource(id = R.drawable.img_deleted_complete),
contentDescription = "delete_complete",
modifier = Modifier.fillMaxSize()
)

Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
) {
Spacer(modifier = Modifier.weight(1f))

HankkiMediumButton(
modifier = Modifier.fillMaxWidth(),
text = "다른 메뉴도 삭제하기",
onClick = onNavigateToEditMenu,
enabled = true,
backgroundColor = White,
textStyle = HankkiTheme.typography.sub3,
textColor = Red500,
borderColor = Red500
)
Spacer(modifier = Modifier.height(16.dp))
HankkiMediumButton(
modifier = Modifier.fillMaxWidth(),
text = "완료",
onClick = onNavigateToStoreDetailRoute,
enabled = true,
textStyle = HankkiTheme.typography.sub3
)
Spacer(
modifier = Modifier
.navigationBarsPadding()
.padding(bottom = 15.dp)
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.hankki.feature.storedetail.editbottomsheet.edit.delete

sealed interface DeleteSuccessSideEffect {
data object NavigateToEditMenu : DeleteSuccessSideEffect
data object NavigateToStoreDetail : DeleteSuccessSideEffect
data object NavigateUp : DeleteSuccessSideEffect
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.hankki.feature.storedetail.editbottomsheet.edit.delete

data class DeleteSuccessState(
val nickname: String = ""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.hankki.feature.storedetail.editbottomsheet.edit.delete

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.hankki.domain.storedetail.repository.StoreDetailRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class DeleteSuccessViewModel @Inject constructor(
private val storeDetailRepository: StoreDetailRepository
) : ViewModel() {

private val _uiState = MutableStateFlow(DeleteSuccessState())
val uiState: StateFlow<DeleteSuccessState> = _uiState

private val _sideEffect = Channel<DeleteSuccessSideEffect>()
val sideEffect = _sideEffect.receiveAsFlow()

init {
fetchNickname()
}


private fun fetchNickname() {
viewModelScope.launch {
storeDetailRepository.getStoreDetailNickname()
.onSuccess { nickname ->
_uiState.value = DeleteSuccessState(nickname = nickname.nickname)
}
.onFailure {
// 처리
}
}
}

fun navigateToEditMenu() {
viewModelScope.launch {
_sideEffect.send(DeleteSuccessSideEffect.NavigateToEditMenu)
}
}

fun navigateToStoreDetail() {
viewModelScope.launch {
_sideEffect.send(DeleteSuccessSideEffect.NavigateToStoreDetail)
}
}

fun navigateUp() {
viewModelScope.launch {
_sideEffect.send(DeleteSuccessSideEffect.NavigateUp)
}
}
}

0 comments on commit 47060d4

Please sign in to comment.