Last active
August 22, 2025 13:05
-
-
Save ifucolo/0bb66ce1c4f666ccbd2dd6fdb4194c10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Composable | |
| fun PlanRouteComponent( | |
| viewModel: PlanFlowViewModel = koinViewModel(), | |
| planName: String, | |
| subPlanName: String? = null, | |
| onClose: () -> Unit | |
| ) { | |
| val backStack = viewModel.backStack | |
| val planUiState by viewModel.planDataUiState.collectAsStateWithLifecycle() | |
| LaunchedEffect(planName, subPlanName) { | |
| viewModel.init(planName = planName, subPlanName = subPlanName) | |
| viewModel.shouldCloseFlow.collect { shouldClose -> | |
| if (shouldClose) { | |
| onClose() | |
| } | |
| } | |
| } | |
| BackHandler(enabled = backStack.size > 1) { | |
| viewModel.popBackStack() | |
| } | |
| val onRetry = { | |
| viewModel.init(planName = planName, subPlanName = subPlanName) | |
| } | |
| NavDisplay( | |
| backStack = backStack, | |
| onBack = { | |
| if (!viewModel.popBackStack()) { | |
| onClose() | |
| } | |
| }, | |
| entryDecorators = listOf( | |
| rememberSceneSetupNavEntryDecorator(), | |
| rememberSavedStateNavEntryDecorator(), | |
| rememberViewModelStoreNavEntryDecorator() | |
| ), | |
| entryProvider = entryProvider { | |
| entry<PlanRoutes.Loading> { | |
| LoadingStateScreen() | |
| } | |
| entry<PlanRoutes.Error> { | |
| ErrorStateScreen( | |
| onRetry = { | |
| viewModel.init(planName = planName, subPlanName = subPlanName) | |
| } | |
| ) | |
| } | |
| entry<PlanRoutes.DaysDashBoard> { | |
| HandleMainRouteContent( | |
| planUiState = planUiState, | |
| onRetry = onRetry | |
| ) { successState -> | |
| PlanDaysDashBoardScreen( | |
| planDomain = successState.planDomain, | |
| onReset = { | |
| viewModel.init(planName = planName, subPlanName = subPlanName) | |
| }, | |
| onDaySelected = { daySelected -> | |
| viewModel.setDaySelected(daySelected) | |
| }, | |
| onBackClick = { | |
| viewModel.onPrayFinish() | |
| }, | |
| ) | |
| } | |
| } | |
| entry<PlanRoutes.StartStep> { route -> | |
| HandleMainRouteContent( | |
| planUiState = planUiState, | |
| onRetry = onRetry | |
| ) { successState -> | |
| val planDomain = successState.planDomain | |
| PlanStartStepScreen( | |
| startStepList = planDomain.startStepPhrases, | |
| colorPrimary = planDomain.colorPrimary, | |
| colorSecondary = planDomain.colorSecondary, | |
| onStartClick = { | |
| viewModel.startReading(PlanRoutes.Pray) | |
| } | |
| ) | |
| } | |
| } | |
| entry<PlanRoutes.Pray> { route -> | |
| HandleMainRouteContent( | |
| planUiState = planUiState, | |
| onRetry = onRetry | |
| ) { successState -> | |
| PlanDetailScreen( | |
| planDomain = successState.planDomain, | |
| onOpenFeedBack = { isLastDay -> | |
| viewModel.navigateTo(PlanRoutes.Feedback(isLastDay)) | |
| }, | |
| onBackClick = { | |
| viewModel.popBackStack() | |
| } | |
| ) | |
| } | |
| } | |
| entry<PlanRoutes.Feedback> { route -> | |
| HandleMainRouteContent( | |
| planUiState = planUiState, | |
| onRetry = onRetry | |
| ) { successState -> | |
| PlanFeedbackScreen( | |
| planDomain = successState.planDomain, | |
| isLastDay = route.isLastDay, | |
| onShare = { | |
| // buildShare(saveAndShare, it) | |
| }, | |
| onDone = { | |
| viewModel.onDone(isLastDay = route.isLastDay) | |
| } | |
| ) | |
| } | |
| } | |
| }, | |
| ...... | |
| transitionSpec, | |
| popTransitionSpec, | |
| predictivePopTransitionSpec | |
| ) | |
| } | |
| @Composable | |
| private fun HandleMainRouteContent( | |
| planUiState: PlanDataUiState, | |
| onRetry: () -> Unit, | |
| content: @Composable (successState: PlanDataUiState.Success) -> Unit | |
| ) { | |
| when (planUiState) { | |
| is PlanDataUiState.Success -> { | |
| content(planUiState) | |
| } | |
| PlanDataUiState.Initializing, PlanDataUiState.Loading -> { | |
| LoadingStateScreen() | |
| } | |
| is PlanDataUiState.Error -> { | |
| ErrorStateScreen( | |
| onRetry = onRetry | |
| ) | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment