Skip to content

Commit

Permalink
Merge pull request #161 from Infomaniak/display-upload-error
Browse files Browse the repository at this point in the history
Navigate to upload error screen when an error is detected
  • Loading branch information
LunarX authored Nov 12, 2024
2 parents bf1df42 + 8185c1b commit 531b2aa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fun NewTransferNavHost(navController: NavHostController, closeActivity: () -> Un
navigateToUploadSuccess = { transferLink ->
navController.navigate(UploadSuccessDestination(args.transferType, transferLink))
},
navigateToUploadError = { navController.navigate(UploadErrorDestination) },
closeActivity = closeActivity
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fun UploadProgressScreen(
uploadProgressViewModel: UploadProgressViewModel = hiltViewModel<UploadProgressViewModel>(),
totalSizeInBytes: Long,
navigateToUploadSuccess: (String) -> Unit,
navigateToUploadError: () -> Unit,
closeActivity: () -> Unit,
) {
val uiState by uploadProgressViewModel.transferProgressUiState.collectAsStateWithLifecycle()
Expand All @@ -63,7 +64,7 @@ fun UploadProgressScreen(
uploadProgressViewModel.trackUploadProgress()
}

HandleProgressState({ uiState }, navigateToUploadSuccess)
HandleProgressState({ uiState }, navigateToUploadSuccess, navigateToUploadError)

UploadProgressScreen(
progressState = { uiState },
Expand All @@ -80,17 +81,14 @@ fun UploadProgressScreen(
@Composable
private fun HandleProgressState(
uiState: () -> UploadProgressUiState,
navigateToUploadSuccess: (String) -> Unit
navigateToUploadSuccess: (String) -> Unit,
navigateToUploadError: () -> Unit,
) {
val currentUiState = uiState()
LaunchedEffect(uiState()) {
when (currentUiState) {
is UploadProgressUiState.Success -> {
navigateToUploadSuccess(currentUiState.transferLink)
}
is UploadProgressUiState.Cancelled -> {
// TODO: navigate to failure screen
}
is UploadProgressUiState.Success -> navigateToUploadSuccess(currentUiState.transferLink)
is UploadProgressUiState.Cancelled -> navigateToUploadError()
else -> Unit
}
}
Expand Down

0 comments on commit 531b2aa

Please sign in to comment.