Skip to content

Commit

Permalink
chore: Add a NotStarted SendActionResult
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Dec 16, 2024
1 parent dcfab58 commit a07acf2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ImportFilesViewModel @Inject constructor(
@IoDispatcher private val ioDispatcher: CoroutineDispatcher,
) : ViewModel() {

private val _sendActionResult = MutableStateFlow<SendActionResult?>(null)
private val _sendActionResult = MutableStateFlow<SendActionResult?>(SendActionResult.NotStarted)
val sendActionResult = _sendActionResult.asStateFlow()

@OptIn(FlowPreview::class)
Expand Down Expand Up @@ -129,11 +129,11 @@ class ImportFilesViewModel @Inject constructor(
}

fun sendTransfer() {
_sendActionResult.update{ SendActionResult.Pending }
_sendActionResult.update { SendActionResult.Pending }
viewModelScope.launch(ioDispatcher) {
runCatching {
val uuid = uploadManager.createAndGetUpload(generateNewUploadSession()).uuid
uploadManager.initUploadSession(recaptcha = "Recaptcha")!! // TODO Handle ContainerErrorsException here
uploadManager.initUploadSession(recaptcha = "Recaptcha")!! // TODO: Handle ContainerErrorsException here
uploadWorkerScheduler.scheduleWork(uuid)
_sendActionResult.update {
val totalSize = importationFilesManager.importedFiles.value.sumOf { it.fileSize }
Expand Down Expand Up @@ -258,8 +258,9 @@ class ImportFilesViewModel @Inject constructor(
//endregion

sealed class SendActionResult {
data class Success(val totalSize: Long) : SendActionResult()
data object NotStarted : SendActionResult()
data object Pending : SendActionResult()
data class Success(val totalSize: Long) : SendActionResult()
data object Failure : SendActionResult()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fun ImportFilesScreen(
closeActivity = closeActivity,
shouldStartByPromptingUserForFiles = true,
sendTransfer = importFilesViewModel::sendTransfer,
isTransferPending = { sendActionResult == SendActionResult.Pending },
isTransferPending = { sendActionResult != SendActionResult.NotStarted },
)
}

Expand Down Expand Up @@ -380,6 +380,7 @@ private fun SendButton(
title = stringResource(R.string.transferSendButton),
style = ButtonType.PRIMARY,
enabled = { importedFiles().isNotEmpty() && !isImporting && isSenderEmailCorrect && !isTransferPending() },
showIndeterminateProgress = { isTransferPending() },
progress = progress,
onClick = navigateToUploadProgress,
)
Expand Down

0 comments on commit a07acf2

Please sign in to comment.