Skip to content

Commit

Permalink
refactor: Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
sirambd committed Nov 7, 2024
1 parent 6ad51c6 commit c439491
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ fun NewTransferNavHost(navController: NavHostController, closeActivity: () -> Un
composable<UploadProgressDestination> {
val args = it.toRoute<UploadProgressDestination>()
UploadProgressScreen(
transferType = args.transferType,
totalSizeInBytes = args.totalSize,
navigateToUploadSuccess = { transferType, transferLink ->
navController.navigate(UploadSuccessDestination(transferType, transferLink))
navigateToUploadSuccess = { transferLink ->
navController.navigate(UploadSuccessDestination(args.transferType, transferLink))
},
closeActivity = closeActivity
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fun ImportFilesScreen(
val selectedTransferType by newTransferViewModel.selectedTransferType.collectAsStateWithLifecycle()
val sendActionResult by newTransferViewModel.sendActionResult.collectAsStateWithLifecycle()

HandleSendActionResult({ sendActionResult }, selectedTransferType, navigateToUploadProgress)
HandleSendActionResult({ sendActionResult }, { selectedTransferType }, navigateToUploadProgress)

ImportFilesScreen(
files = { files },
Expand All @@ -88,12 +88,12 @@ fun ImportFilesScreen(
@Composable
private fun HandleSendActionResult(
getSendActionResult: () -> SendActionResult?,
transferType: TransferType,
transferType: () -> TransferType,
navigateToUploadProgress: (transferType: TransferType, totalSize: Long) -> Unit,
) {
LaunchedEffect(getSendActionResult()) {
when (val actionResult = getSendActionResult()) {
is SendActionResult.Success -> navigateToUploadProgress(transferType, actionResult.totalSize)
is SendActionResult.Success -> navigateToUploadProgress(transferType(), actionResult.totalSize)
is SendActionResult.Failure -> Unit //TODO: Show error
else -> Unit
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import com.infomaniak.swisstransfer.R
import com.infomaniak.swisstransfer.ui.components.*
import com.infomaniak.swisstransfer.ui.images.AppImages.AppIllus
import com.infomaniak.swisstransfer.ui.images.illus.uploadCancelBottomSheet.RedCrossPaperPlanes
import com.infomaniak.swisstransfer.ui.screen.newtransfer.importfiles.components.TransferType
import com.infomaniak.swisstransfer.ui.screen.newtransfer.upload.components.AdHeader
import com.infomaniak.swisstransfer.ui.screen.newtransfer.upload.components.Progress
import com.infomaniak.swisstransfer.ui.theme.Margin
Expand All @@ -46,9 +45,8 @@ import com.infomaniak.swisstransfer.workers.UploadWorker.UploadProgressUiState
@Composable
fun UploadProgressScreen(
uploadProgressViewModel: UploadProgressViewModel = hiltViewModel<UploadProgressViewModel>(),
transferType: TransferType,
totalSizeInBytes: Long,
navigateToUploadSuccess: (TransferType, String) -> Unit,
navigateToUploadSuccess: (String) -> Unit,
closeActivity: () -> Unit,
) {
val uiState by uploadProgressViewModel.transferProgressUiState.collectAsStateWithLifecycle()
Expand All @@ -64,7 +62,7 @@ fun UploadProgressScreen(
uploadProgressViewModel.trackUploadProgress()
}

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

UploadProgressScreen(
progressState = { uiState },
Expand All @@ -81,14 +79,13 @@ fun UploadProgressScreen(
@Composable
private fun HandleProgressState(
uiState: () -> UploadProgressUiState,
transferType: TransferType,
navigateToUploadSuccess: (TransferType, String) -> Unit
navigateToUploadSuccess: (String) -> Unit
) {
val currentUiState = uiState()
LaunchedEffect(uiState()) {
when (currentUiState) {
is UploadProgressUiState.Success -> {
navigateToUploadSuccess(transferType, currentUiState.transferLink)
navigateToUploadSuccess(currentUiState.transferLink)
}
is UploadProgressUiState.Cancelled -> {
// TODO: navigate to failure screen
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class UploadFileTask(
data = data,
onUpload = { bytesSentTotal, _ ->
mutex.withLock {
ensureActive()
ensureActive() // Cancel when this chunk is resumed while parent scope is cancelled
onUploadBytes(bytesSentTotal - oldBytesSentTotal)
oldBytesSentTotal = bytesSentTotal
}
Expand Down

0 comments on commit c439491

Please sign in to comment.