Skip to content

Commit

Permalink
[Feat]: Destination id 받기 적용, detail 로드
Browse files Browse the repository at this point in the history
  • Loading branch information
jinuemong committed Feb 8, 2024
1 parent bc7b443 commit 4dc8422
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ import ac.dnd.bookkeeping.android.presentation.ui.main.home.history.HistoryConst

object HistoryDetailConstant {
const val ROUTE: String = "${HistoryConstant.ROUTE}/detail"

const val ROUTE_ARGUMENT_ID = "id"
const val CONTAIN_ID_MODEL = "${ROUTE}/${ROUTE_ARGUMENT_ID}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,45 @@ package ac.dnd.bookkeeping.android.presentation.ui.main.home.history.detail

import ac.dnd.bookkeeping.android.presentation.common.util.ErrorObserver
import ac.dnd.bookkeeping.android.presentation.ui.main.ApplicationState
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavType
import androidx.navigation.compose.composable
import androidx.navigation.navArgument

fun NavGraphBuilder.historyDetailDestination(
appState: ApplicationState
) {
composable(
route = HistoryDetailConstant.ROUTE
) {
route = HistoryDetailConstant.CONTAIN_ID_MODEL,
arguments = listOf(
navArgument(HistoryDetailConstant.ROUTE_ARGUMENT_ID) {
type = NavType.LongType
}
)
) { entry ->

val id = entry.arguments?.getLong(HistoryDetailConstant.ROUTE_ARGUMENT_ID) ?: -1

val viewModel: HistoryDetailViewModel = hiltViewModel()

if (id < 0L) {
appState.navController.popBackStack()
} else {
LaunchedEffect(Unit) {
viewModel.loadRelationDetail(id)
}
}

val model: HistoryDetailModel = let {
val state by viewModel.state.collectAsStateWithLifecycle()

val relationDetail by viewModel.relationDetail.collectAsStateWithLifecycle()
HistoryDetailModel(
state = state
state = state,
relationDetail = relationDetail
)
}

Expand Down

0 comments on commit 4dc8422

Please sign in to comment.