diff --git a/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/home/history/detail/HistoryDetailConstant.kt b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/home/history/detail/HistoryDetailConstant.kt index 0b61d6a0..a9819ffa 100644 --- a/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/home/history/detail/HistoryDetailConstant.kt +++ b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/home/history/detail/HistoryDetailConstant.kt @@ -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}" } diff --git a/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/home/history/detail/HistoryDetailDestination.kt b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/home/history/detail/HistoryDetailDestination.kt index 19a56c95..cd9f3463 100644 --- a/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/home/history/detail/HistoryDetailDestination.kt +++ b/presentation/src/main/kotlin/ac/dnd/bookkeeping/android/presentation/ui/main/home/history/detail/HistoryDetailDestination.kt @@ -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 ) }