Skip to content

Commit

Permalink
chore: Add Delete state for TransferDetailsScreen
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Nov 26, 2024
1 parent f8acfd2 commit b4b33cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ import com.infomaniak.swisstransfer.ui.images.icons.QrCode
import com.infomaniak.swisstransfer.ui.images.icons.Share
import com.infomaniak.swisstransfer.ui.previewparameter.TransferUiListPreviewParameter
import com.infomaniak.swisstransfer.ui.screen.main.components.SmallWindowTopAppBarScaffold
import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.TransferDetailsViewModel.TransferDetailsUiState.Loading
import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.TransferDetailsViewModel.TransferDetailsUiState.Success
import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.TransferDetailsViewModel.TransferDetailsUiState.*
import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.components.PasswordBottomSheet
import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.components.QrCodeBottomSheet
import com.infomaniak.swisstransfer.ui.screen.main.transferdetails.components.TransferInfo
Expand All @@ -67,13 +66,18 @@ fun TransferDetailsScreen(
) {
val uiState by transferDetailsViewModel.uiState.collectAsStateWithLifecycle()
val isLoading by remember { derivedStateOf { uiState is Loading } }
val isDelete by remember { derivedStateOf { uiState is Delete } }

LaunchedEffect(transferUuid) {
transferDetailsViewModel.loadTransfer(transferUuid)
}

if (!isLoading) {
if (isDelete) {
navigateBack?.invoke()
} else if (!isLoading) {
TransferDetailsScreen(
transferDetailsViewModel,
transferUuid,
transferUrl = transferDetailsViewModel.getTransferUrl(transferUuid),
direction = direction,
navigateBack = navigateBack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import androidx.lifecycle.viewModelScope
import com.infomaniak.multiplatform_swisstransfer.SharedApiUrlCreator
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi
import com.infomaniak.multiplatform_swisstransfer.managers.TransferManager

import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.*
Expand All @@ -45,7 +44,7 @@ class TransferDetailsViewModel @Inject constructor(
.flatMapLatest { transferManager.getTransferFlow(it) }
.map { transfer ->
when (transfer) {
null -> TransferDetailsUiState.Error
null -> TransferDetailsUiState.Delete
else -> TransferDetailsUiState.Success(transfer)
}
}
Expand All @@ -61,6 +60,12 @@ class TransferDetailsViewModel @Inject constructor(

fun getTransferUrl(transferUuid: String): String = sharedApiUrlCreator.shareTransferUrl(transferUuid)

fun removeTransfer(transferUuid: String) {
viewModelScope.launch {
transferManager.removeTransfer(transferUuid)
}
}

sealed class TransferDetailsUiState {

@Immutable
Expand All @@ -70,6 +75,6 @@ class TransferDetailsViewModel @Inject constructor(
data object Loading : TransferDetailsUiState()

@Immutable
data object Error : TransferDetailsUiState() //TODO Handle error case
data object Delete : TransferDetailsUiState()
}
}

0 comments on commit b4b33cf

Please sign in to comment.