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 9eb92b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 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 },
isTransferStarted = { sendActionResult != SendActionResult.NotStarted },
)
}

Expand Down Expand Up @@ -158,7 +158,7 @@ private fun ImportFilesScreen(
closeActivity: () -> Unit,
shouldStartByPromptingUserForFiles: Boolean,
sendTransfer: () -> Unit,
isTransferPending: () -> Boolean,
isTransferStarted: () -> Boolean,
) {

val shouldShowEmailAddressesFields by remember { derivedStateOf { selectedTransferType.get() == TransferTypeUi.MAIL } }
Expand All @@ -179,7 +179,7 @@ private fun ImportFilesScreen(
importedFiles = files,
shouldShowEmailAddressesFields = { shouldShowEmailAddressesFields },
transferAuthorEmail = transferAuthorEmail,
isTransferPending = isTransferPending,
isTransferStarted = isTransferStarted,
navigateToUploadProgress = sendTransfer,
)
},
Expand Down Expand Up @@ -357,7 +357,7 @@ private fun SendButton(
importedFiles: () -> List<FileUi>,
shouldShowEmailAddressesFields: () -> Boolean,
transferAuthorEmail: GetSetCallbacks<String>,
isTransferPending: () -> Boolean,
isTransferStarted: () -> Boolean,
navigateToUploadProgress: () -> Unit,
) {
val remainingFilesCount = filesToImportCount()
Expand All @@ -379,7 +379,8 @@ private fun SendButton(
modifier = modifier,
title = stringResource(R.string.transferSendButton),
style = ButtonType.PRIMARY,
enabled = { importedFiles().isNotEmpty() && !isImporting && isSenderEmailCorrect && !isTransferPending() },
enabled = { importedFiles().isNotEmpty() && !isImporting && isSenderEmailCorrect && !isTransferStarted() },
showIndeterminateProgress = { isTransferStarted() },
progress = progress,
onClick = navigateToUploadProgress,
)
Expand Down Expand Up @@ -447,7 +448,7 @@ private fun Preview(@PreviewParameter(FileUiListPreviewParameter::class) files:
addFiles = {},
closeActivity = {},
shouldStartByPromptingUserForFiles = false,
isTransferPending = { false },
isTransferStarted = { false },
sendTransfer = {},
)
}
Expand Down

0 comments on commit 9eb92b6

Please sign in to comment.