Skip to content

Commit

Permalink
체크리스트 생성 중 닉네임 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
leesa-l committed Dec 29, 2023
1 parent 05403db commit 3985c16
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ sealed interface DeepLink {
override val deepLink: String = "$SCHEME://profile"
}

object Step : DeepLink {
override val deepLink: String = "$SCHEME://step"
data class Step(val nickname: String) : DeepLink {
override val deepLink: String = "$SCHEME://step/$nickname"
}

data class CheckList(val id: String) : DeepLink {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ class Home : MVIComposeFragment<HomeIntent, HomeState, HomeEffect>() {

override fun processEffect(effect: HomeEffect) {
when (effect) {
HomeEffect.NavigateToAddCheckList ->
deepLink(DeepLink.Step) { popUpTo(R.id.home) }
is HomeEffect.NavigateToAddCheckList -> {
deepLink(DeepLink.Step(effect.nickname)) { popUpTo(R.id.home) }
}

is HomeEffect.NavigateToCheckList -> {
deepLink(DeepLink.CheckList(effect.id)) { popUpTo(R.id.home) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ sealed interface HomeState : ViewState {
}

sealed interface HomeEffect : ViewEffect {
object NavigateToAddCheckList : HomeEffect
data class NavigateToAddCheckList(val nickname: String) : HomeEffect

data class NavigateToCheckList(val id: String) : HomeEffect
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.dkin.chevit.presentation.home

import androidx.lifecycle.viewModelScope
import com.dkin.chevit.core.mvi.MVIViewModel
import com.dkin.chevit.domain.base.getOrNull
import com.dkin.chevit.domain.usecase.auth.GetUserUseCase
import com.dkin.chevit.domain.usecase.plan.GetMyChecklistUseCase
import com.dkin.chevit.presentation.home.model.CheckListItem
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class HomeViewModel @Inject constructor(
private val getMyChecklistUseCase: GetMyChecklistUseCase,
private val getUserUseCase: GetUserUseCase,
) : MVIViewModel<HomeIntent, HomeState, HomeEffect>() {
private var nickname = ""

override fun createInitialState(): HomeState = HomeState.Loading

Expand All @@ -30,7 +29,7 @@ class HomeViewModel @Inject constructor(
}

fun onClickAddChecklist() {
setEffect { HomeEffect.NavigateToAddCheckList }
setEffect { HomeEffect.NavigateToAddCheckList(nickname) }
}

fun onClickChecklist(id: String) {
Expand All @@ -45,6 +44,7 @@ class HomeViewModel @Inject constructor(
val checklist = checklistAsync.await().getOrNull()
setState {
val currentState = state.value
nickname = user?.name ?: ""
if (currentState is HomeState.Stable) {
currentState.copy(
userName = user?.name ?: currentState.userName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.ViewGroup
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.platform.ViewCompositionStrategy
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.dkin.chevit.core.mvi.MVIComposeFragment
import com.dkin.chevit.presentation.deeplink.DeepLink
import com.dkin.chevit.presentation.deeplink.deepLink
Expand Down Expand Up @@ -44,4 +45,12 @@ class Step : MVIComposeFragment<StepIntent, StepState, StepEffect>() {
}
}
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val nickname = arguments?.getString("nickname")
nickname?.let {
viewModel.setNickname(nickname)
} ?: findNavController().popBackStack()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ fun StepScreen(
fun CreateCheckListLoading(
nickname: String
) {
val text = if (nickname.isBlank()) {
"딱맞는 체크리스트를\\n만들고 있어요!"
} else {
"${nickname}님께\n딱맞는 체크리스트를\n만들고 있어요!"
}

Box(
modifier = Modifier
.fillMaxSize()
Expand All @@ -160,7 +166,7 @@ fun CreateCheckListLoading(
Spacer(Modifier.height(32.dp))
Text(
modifier = Modifier,
text = "${nickname}님께\n딱맞는 체크리스트를\n만들고 있어요!",
text = text,
style = ChevitTheme.typhography.headlineLarge.copy(color = ChevitTheme.colors.textPrimary),
textAlign = TextAlign.Center
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.dkin.chevit.presentation.step

import androidx.lifecycle.viewModelScope
import com.dkin.chevit.core.mvi.MVIViewModel
import com.dkin.chevit.domain.base.get
import com.dkin.chevit.domain.base.getOrNull
import com.dkin.chevit.domain.base.onComplete
import com.dkin.chevit.domain.model.Country
import com.dkin.chevit.domain.usecase.plan.GetTravelKindsListUseCase
Expand All @@ -19,8 +17,6 @@ import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import java.time.LocalDate
import javax.inject.Inject

Expand All @@ -29,7 +25,7 @@ class StepViewModel @Inject constructor(
private val getTravelKindsListUseCase: GetTravelKindsListUseCase,
private val getTravelWithListUseCase: GetTravelWithListUseCase,
private val searchCountryListUseCase: SearchCountryListUseCase,
private val postNewScheduleUseCase: PostNewScheduleUseCase
private val postNewScheduleUseCase: PostNewScheduleUseCase,
) : MVIViewModel<StepIntent, StepState, StepEffect>() {
private val _countryList: MutableStateFlow<List<CountryModel>> = MutableStateFlow(listOf())
val countryList = _countryList.asStateFlow()
Expand All @@ -40,11 +36,6 @@ class StepViewModel @Inject constructor(
private val _userNickname: MutableStateFlow<String> = MutableStateFlow("")
val userNickname = _userNickname.asStateFlow()

init {
//TODO 닉네임 datastore에서 가져오기
_userNickname.value = "민지"
}

override fun createInitialState(): StepState = StepState.empty()

override suspend fun processIntent(intent: StepIntent) {
Expand All @@ -54,6 +45,10 @@ class StepViewModel @Inject constructor(
}
}

fun setNickname(name: String) {
_userNickname.value = name
}

fun clearCountry() {
_countryList.value = listOf()
setState {
Expand Down
5 changes: 4 additions & 1 deletion presentation/step/src/main/res/navigation/nav_step.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
android:id="@+id/step"
android:name="com.dkin.chevit.presentation.step.Step"
android:label="Step">
<deepLink app:uri="chevit://step" />
<argument
android:name="nickname"
app:argType="string" />
<deepLink app:uri="chevit://step/{nickname}" />
</fragment>
</navigation>

0 comments on commit 3985c16

Please sign in to comment.