Skip to content

Commit

Permalink
내정보 탭 기능 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
kts6056 committed Nov 20, 2023
1 parent 4526047 commit d0fe18a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import com.dkin.chevit.core.mvi.ViewState
sealed interface MyPageIntent : ViewIntent {
object ViewCreated : MyPageIntent
data class AlarmSwitchClicked(val enabled: Boolean) : MyPageIntent
object SignOutClicked : MyPageIntent
object WithDrawClicked : MyPageIntent
object ProfileSettingClicked : MyPageIntent
object TermsClicked : MyPageIntent
object NotificationSettingClicked : MyPageIntent
}

@Stable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ package com.dkin.chevit.presentation.home
import com.dkin.chevit.core.mvi.MVIViewModel
import com.dkin.chevit.domain.base.get
import com.dkin.chevit.domain.base.onComplete
import com.dkin.chevit.domain.usecase.auth.WithDrawUserUseCase
import com.dkin.chevit.domain.usecase.auth.GetUserUseCase
import com.dkin.chevit.domain.usecase.auth.SignOutUseCase
import com.dkin.chevit.domain.usecase.auth.WithDrawUserUseCase
import com.dkin.chevit.domain.usecase.notification.GetNotificationSettingUseCase
import com.dkin.chevit.domain.usecase.notification.UpdateNotificationEnableStateUseCase
import com.dkin.chevit.presentation.home.MyPageIntent.AlarmSwitchClicked
import com.dkin.chevit.presentation.home.MyPageIntent.NotificationSettingClicked
import com.dkin.chevit.presentation.home.MyPageIntent.ProfileSettingClicked
import com.dkin.chevit.presentation.home.MyPageIntent.SignOutClicked
import com.dkin.chevit.presentation.home.MyPageIntent.TermsClicked
import com.dkin.chevit.presentation.home.MyPageIntent.ViewCreated
import com.dkin.chevit.presentation.home.MyPageIntent.WithDrawClicked
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.awaitAll
Expand All @@ -19,7 +24,6 @@ class MyPageViewModel @Inject constructor(
private val getUserUseCase: GetUserUseCase,
private val signOutUseCase: SignOutUseCase,
private val withDrawUserUseCase: WithDrawUserUseCase,
private val getNotificationSettingUseCase: GetNotificationSettingUseCase,
private val updateNotificationEnableStateUseCase: UpdateNotificationEnableStateUseCase
) : MVIViewModel<MyPageIntent, MyPageState, MyPageEffect>() {

Expand All @@ -28,19 +32,20 @@ class MyPageViewModel @Inject constructor(
override suspend fun processIntent(intent: MyPageIntent) = when (intent) {
ViewCreated -> setup()
is AlarmSwitchClicked -> onClickAlarmEnabled(intent.enabled)
SignOutClicked -> onClickSignOut()
WithDrawClicked -> onClickWithdraw()
ProfileSettingClicked -> onClickProfileSetting()
TermsClicked -> onClickTerms()
NotificationSettingClicked -> onClickNotificationSetting()
}

private suspend fun setup() {
val asyncUser = async { getUserUseCase(Unit).get() }
val notificationSettingAsync = async { getNotificationSettingUseCase(Unit).get() }
listOf(asyncUser, notificationSettingAsync).awaitAll()
val user = asyncUser.await()
val notificationSetting = notificationSettingAsync.await()
val user = getUserUseCase(Unit).get()
setState {
copy(
userName = user.name,
profileUrl = user.profileImageUrl,
notificationEnabled = notificationSetting.notificationEnabled
notificationEnabled = user.notificationEnabled
)
}
}
Expand All @@ -63,23 +68,15 @@ class MyPageViewModel @Inject constructor(
}
}

fun onClickProfileSetting() {
private fun onClickProfileSetting() {
setEffect { MyPageEffect.NavigateToProfileSetting }
}

fun onClickTerms() {
private fun onClickTerms() {
setEffect { MyPageEffect.NavigateToTerms }
}

fun onClickNotificationSetting() {
private fun onClickNotificationSetting() {
setEffect { MyPageEffect.NavigateToNotificationSetting }
}

fun signOut() {
//todo
}

fun withdraw() {
//todo
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fun UserContents(
)
Spacer(modifier = Modifier.height(12.dp))
ChevitButtonChip(
onClick = { myViewModel.onClickProfileSetting() },
onClick = { myViewModel.dispatch(MyPageIntent.ProfileSettingClicked) },
text = "프로필 설정",
)
Spacer(modifier = Modifier.height(52.dp))
Expand Down Expand Up @@ -123,11 +123,13 @@ fun UserContents(
AlarmSetting(
checked = myPageState.notificationEnabled,
onClickItem = { myViewModel.dispatch(MyPageIntent.AlarmSwitchClicked(it)) },
onClickNotificationSetting = { myViewModel.onClickNotificationSetting() }
onClickNotificationSetting = {
myViewModel.dispatch(MyPageIntent.NotificationSettingClicked)
}
)
UserItem(
title = "이용약관",
onClickItem = { myViewModel.onClickTerms() }
onClickItem = { myViewModel.dispatch(MyPageIntent.TermsClicked) }
) {
Icon(
imageVector = ChevitIcon.IconArrowRight,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.window.DialogProperties
import com.dkin.chevit.presentation.home.MyPageViewModel
import androidx.navigation.compose.rememberNavController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.dialog
import androidx.navigation.compose.rememberNavController
import com.dkin.chevit.presentation.home.HomeViewModel
import com.dkin.chevit.presentation.home.MyPageIntent
import com.dkin.chevit.presentation.home.MyPageViewModel
import com.dkin.chevit.presentation.resource.ChevitDialog
import com.dkin.chevit.presentation.resource.util.clickableNoRipple

Expand Down Expand Up @@ -63,7 +64,7 @@ fun UserTabContents(
body = "로그아웃시\n소셜 로그인 연동이 해제됩니다.",
cancelBtnText = "로그아웃",
confirmBtnText = "취소",
onClickCancel = { myViewModel.signOut() },
onClickCancel = { myViewModel.dispatch(MyPageIntent.SignOutClicked) },
onClickConfirm = { navController.popBackStack() },
)
}
Expand All @@ -83,7 +84,7 @@ fun UserTabContents(
body = "회원 탈퇴시 계정과 함께\n저장되어 있는 체크리스트가 삭제됩니다.",
cancelBtnText = "회원탈퇴",
confirmBtnText = "취소",
onClickCancel = { myViewModel.withdraw() },
onClickCancel = { myViewModel.dispatch(MyPageIntent.WithDrawClicked) },
onClickConfirm = { navController.popBackStack() },
)
}
Expand Down

0 comments on commit d0fe18a

Please sign in to comment.