Skip to content

Commit

Permalink
refactor: 보낸 봉투 추가 argument로 Friend 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
yangsooplus committed Feb 16, 2024
1 parent ef8816b commit db1af7d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.navigation.navOptions
import com.susu.core.designsystem.theme.SusuTheme
import com.susu.core.model.Envelope
import com.susu.core.model.EnvelopeDetail
import com.susu.core.model.Friend
import com.susu.core.model.Ledger
import com.susu.core.model.Vote
import com.susu.feature.community.navigation.CommunityRoute
Expand Down Expand Up @@ -123,8 +124,8 @@ internal class MainNavigator(
navController.navigateSentEnvelopeEdit(envelopeDetail)
}

fun navigateSentEnvelopeAdd() {
navController.navigateSentEnvelopeAdd()
fun navigateSentEnvelopeAdd(friend: Friend? = null) {
navController.navigateSentEnvelopeAdd(friend)
}

fun navigateSentEnvelopeSearch() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.susu.feature.envelopeadd

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import com.susu.core.model.Category
import com.susu.core.model.Relationship
import com.susu.core.ui.MONEY_MAX_VALUE
import com.susu.core.ui.base.BaseViewModel
import com.susu.domain.usecase.envelope.CreateSentEnvelopeUseCase
import com.susu.feature.sent.navigation.SentRoute
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import kotlinx.datetime.toKotlinLocalDateTime
Expand All @@ -15,7 +17,9 @@ import javax.inject.Inject
@HiltViewModel
class EnvelopeAddViewModel @Inject constructor(
private val createSentEnvelopeUseCase: CreateSentEnvelopeUseCase,
savedStateHandle: SavedStateHandle,
) : BaseViewModel<EnvelopeAddState, EnvelopeAddEffect>(EnvelopeAddState()) {
private val friendArgument = savedStateHandle.get<String>(SentRoute.FRIEND_ARGUMENT_NAME)

private var money: Long = 0
private var name: String = ""
Expand All @@ -29,6 +33,10 @@ class EnvelopeAddViewModel @Inject constructor(
private var phoneNumber: String? = null
private var memo: String? = null

fun initData() {
println(friendArgument)
}

private fun createEnvelope() {
viewModelScope.launch {
createSentEnvelopeUseCase(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.imePadding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -67,6 +68,10 @@ fun SentEnvelopeAddRoute(
mutableStateOf("")
}

LaunchedEffect(key1 = Unit) {
viewModel.initData()
}

BackHandler {
viewModel.goPrevStep()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import com.susu.core.model.EnvelopeDetail
import com.susu.core.model.Friend
import com.susu.core.ui.DialogToken
import com.susu.core.ui.SnackbarToken
import com.susu.core.ui.extension.encodeToUri
Expand Down Expand Up @@ -36,8 +37,8 @@ fun NavController.navigateSentEnvelopeEdit(envelopeDetail: EnvelopeDetail) {
navigate(SentRoute.sentEnvelopeEditRoute(Json.encodeToUri(envelopeDetail)))
}

fun NavController.navigateSentEnvelopeAdd() {
navigate(SentRoute.sentEnvelopeAddRoute)
fun NavController.navigateSentEnvelopeAdd(friend: Friend?) {
navigate(SentRoute.sentEnvelopeAddRoute(Json.encodeToUri(friend)))
}

fun NavController.navigateSentEnvelopeSearch() {
Expand Down Expand Up @@ -134,7 +135,7 @@ fun NavGraphBuilder.sentNavGraph(
)
}

composable(route = SentRoute.sentEnvelopeAddRoute) {
composable(route = SentRoute.sentEnvelopeAddRoute("{${SentRoute.FRIEND_ARGUMENT_NAME}}")) {
SentEnvelopeAddRoute(
popBackStack = popBackStack,
popBackStackWithRefresh = popBackStackWithRefresh,
Expand Down Expand Up @@ -163,8 +164,10 @@ fun NavGraphBuilder.sentNavGraph(

object SentRoute {
const val route = "sent"
const val sentEnvelopeAddRoute = "sent-envelope-add"
const val SENT_REFRESH_ARGUMENT_NAME = "sent-refresh"
fun sentEnvelopeAddRoute(friend: String) = "sent-envelope-add/$friend"
const val FRIEND_ARGUMENT_NAME = "sent-friend"

fun sentEnvelopeRoute(id: String) = "sent-envelope/$id"
const val FRIEND_ID_ARGUMENT_NAME = "sent-envelope-id"
const val EDITED_FRIEND_ID_ARGUMENT_NAME = "edited-friend-id"
Expand Down

0 comments on commit db1af7d

Please sign in to comment.